I have a server running on Java using the library Pi4j to control the RaspberryPi's GPIOs and a file on which I write the current GPIOs' statuses. When I run the code from IntelliJ IDE everything works just fine.
But when I create the .jar file and run it like
sudo java -jar server.jar
It works fine updating the file, but the GPIOs do not change their status.
When I do
java -jar server.jar
The GPIOs correctly change their status but I get the error java.io.FileNotFoundException: relStat.txt (Permission denied)
My file permission are all set to anyone, so anyone should be able to read, modify and run it.
Why does this happen?
This is a permission issue,
The file owner is the "pi" user.
Which user you are running under?
Related
So I've been writing this little code, and it works -- but I have to type in the whole Computer;~ User$ java MyProject and change the path every time, so I decided to stick it in a .jar file (so I could just run it on a double click). I am an Intellij user on running macos. I created the file, File/Project Structure/artifacts/+/myMain etc and now have a .jar file sitting on my desktop. When I run the jar inside of Intellij, or run the jar using
java -jar /Users/Me/Desktop/MyProject/out/artifacts/MyProject_jar/MyProject.jar, it works fine.
However, when I:
Run it from the terminal with java -jar MyProject.jar I get Error: Unable to access jarfile MyProject.jar
^^Resolved - using the chmod 755 MyProject.jar command, see comment for further details
Or run it on right click with Jar launcher I get The Java JAR file "MyProject.jar" could not be launched. Check the Console for possible error messages. There are no error messages in the console.
And before anyone says it, I have Java 13 and the project is running on Java 13 -- it's the default that my computer has, and has been updated automatically ever since installation.
How would I be able to launch this file, and what could be stopping it from doing so?
in terminal, do an
ls -l MyProject.jar
You'll see something like:
-rw-r--r-- 1 youruser yourgroup 1024 Apr 24 15:41 MyProject.jar
The -rw-r--r-- part is the file permissions where an "r" means readable, "w" means writable, and an "x" would mean executable, but as you can see there isn't one there. Without going into the long explanation, use the chmod command to make the file executable by doing
chmod 755 MyProject.jar
Afterwards, use the same ls command and you should see -rwxr-xr-x in the permissions field. The file is now executable (by anyone) and should launch if you click in in Finder.
If your program has no GUI but requires console input, you should run it from the terminal instead of double clicking it. When you double click the MyProject.jar file, you actually launch it through jar launcher. The jar launcher will pass the files to the JVM. However, since you are not launching it from the terminal, the JVM does not know which terminal to use, so the program might not be properly executed.
I'm trying to build an webapp as wrapper for youtube-dl. I'm calling the youtube-dl command using Runtime.getRuntime().exec() but all I'm getting is permission denied saying File system is read-only
And I'm passing the working directory while executing command like Runtime.getRuntime().exec("youtube-dl ...",null,workingDirectory)
Permission for the workingDirectory is changed like below
drwxr-xr-x 1 tomcat tomcat 0 May 13 08:21 Folder
Even tried ProcessBuilder instead of RunTime results same issue and tried other commands such as touch to create file, but the result is same. got touch: cannot touch 'a.txt': Read-only file system error
I'm using tomcat9 - 9.0.16-3ubuntu0.18.04.1, Java8 - 1.8.0_242, Ubuntu - 18.04.1 and tomcat is installed via apt-get
Could anyone tell me what I'm doing wrong?
Seems like your file system went to read only mode.. Please get that server reboot..
I'm having a strange issue trying to run classes from an executable .jar file on Linux that none of the existing question threads I've sorted through seem to be able to resolve. I'll preface this in that I've never had to use Linux before and am only using it in this situation out of necessity, so it's possible I have overlooked something simple that I just didn't know could be causing the problem.
I can launch the classes from my .jar file without any issues on Windows via a .bat file with the following settings:
start "MyServer1" java -classpath ./*;Server.jar infoServer/StartInfoServer
start "MyServer2" java -classpath ./*;Server.jar loginServer/StartLoginServer
start "MyServer3" java -classpath ./*;Server.jar chatServer/start
start "MyServer4" java -classpath ./*;Server.jar gameServer/start
However, when I move to trying to launch these classes from the .jar on Linux, I get a "could not find or load main class" error. My .sh file is set up like this, and is placed in the same directory as my .jar file:
echo Starting Servers
java -cp Server.jar infoServer.StartInfoServer
java -cp Server.jar loginServer.StartLoginServer
java -cp Server.jar chatServer.start
java -cp Server.jar gameServer.start
echo All Done Starting Server
I've used ls from the Terminal to verify the .jar and .sh were being recognized as existing where they should be. (For future note, I'm using the Terminal from inside the directory containing my files.) I've made sure to make use of chmod to be sure both the .jar and the .sh have read/write/execute permissions and used ls -l to verify those permissions were indeed present. I've tried various forms of explicitly defining the classpath, such as using "/home/machine/Desktop/Folder/MyJar.jar", using pwd from the Terminal to ensure I'm getting the filepath correct. I've checked over my Java compatibility. (1.7.0_65 on Linux, 1.8.0_45 on Windows, with the .jar being created in Eclipse using 1.7 Compliance settings.) I can use unzip MyJar.jar from the Terminal and it will properly extract all my class files, allowing me to verify that my .jar isn't corrupted on my Linux machine and that the paths to the classes I'm trying to run are still the same on Linux as they are on Windows.
I do apologize if this is just a problem of inexperience overlooking something, but I can't think of or find any indication of what the problem could possibly be.
EDIT:
I've updated the question with some screenshots related to the problem:
https://gyazo.com/0ae2a2701aae734db21ef7c29200283b - General File Setup.
https://gyazo.com/d735d9cee57b4a92078c4b624d012b8c - Running the Shell via Terminal.
Other notes: jar -tf Server.jar works from the Terminal but not from inside the Shell script, which leads me to believe this may be some kind of visibility or pathing error, but I can't find any reason why that would be the case.
I'm trying to run a java application on a server computer by using VNC (tightVNC).
I have the java application in eclipse and it runs perfectly. Then I export it to a runnable jar file and upload the runnable jar file to the server. Now I'm trying to run the application (called ABUN_0.0.0.jar) using VNC.
I use /u01/gatc/java/jdk1.6.0_10/bin/java -jar ABUN_0.0.0.jar& (I've used this for previous versions of the app and its worked perfectly). However now I get Unable to access jarfile ABUN_0.0.0.jar
instead of
/u01/gatc/java/jdk1.6.0_10/bin/java -jar ABUN_0.0.0.jar&
use this,
/u01/gatc/java/jdk1.6.0_10/bin/java -jar /**path to jar**/ABUN_0.0.0.jar &
or
if Linux System,
check ABUN_0.0.0.jar's permission level.
To give Permission,
chmod 755 /**path to jar**/ABUN_0.0.0.jar
I am getting this exception when i open jar file using cmd:
java.io.FileNotFoundException: C:\Windows\System32\drivers\etc\hosts.File (Access is denied)
How can i open jar file with administrator privilege?
Simply double clicking the jar file does not open the jar file.I am using win7 as OS.
If I understand correctly, you're trying to run java from a command prompt but want admin privileges. In that case, right-click on the "command prompt" and choose "run as administrator", then you can
java -jar myprogram.jar
from the command prompt as before.
However do you really want to allow this program to edit your hosts file? I'd recommend you find out what it's trying to do and make the change manually if you're happy with it.
If you want to run jar file with admin privileges from console or by double clicking, without explicitly executing it with admin rights Which is most obvious from user's point of view as he might just know how to click and not internal working. Then this is my post answering your quest in simple steps.
Run Java file as Administrator with full privileges