Linux error unable to access jarfile

What causes «Unable to access jarfile» error?

I want to execute my program without using an IDE. I’ve created a jar file and an exectuable jar file. When I double click the exe jar file, nothing happens, and when I try to use the command in cmd it gives me this:

Error: Unable to access jarfile
  1. Right click on project folder (Calculator)
  2. Select
  3. Click on Java Folder and select «Exectuable Jar File», then select next
  4. Launch Configuration: Main — Calculator
  5. Create Export Destination
  6. Hit «Finish» and profit! Well, not really.

You should show how you created the JARs, what’s in them and how you try to run the program. The Java code is irrelevant here.

Have you tried relaunching elcipse and recompiling? Sometimes Eclipse has does some strange things that can be avoided by relaunching.

I have no answers to my problem, i answered it myself, and there is no way to show my appreciation in the comments, other than thanking them via reply. Please Reread your comment.

I was able to solve it by passing absolute path for the jar file after the command «java -jar /home/aboslute_path_to_the_jar_file.jar». Hope it helps.

39 Answers 39

I had encountered this issue when I had run my Jar file as

java -jar TestJar

java -jar TestJar.jar

Missing the extension .jar also causes this issue.

In my case I thought it was a file while it was a folder on the console. The jar file was in a folder that has the same name.

This is always the incorrect Answer for this Question — the Question mentioned using the .jar extension; it wasn’t missing. Although this Answer may help in some similar situations, it wasn’t the answer to this Question’s particular situation.

I just placed it in a different folder and it worked.

I had a similar issue on WIndows, using cygwin. So cygwin uses different paths than windows /cygdrive/c/ vs C:\ I fixed this by using realpath —relative-to=$(pwd) path/to/jarfile So it will always enforce a relative path iso using /cygdrive/c/. /path/to/jarfile

Beware of spaces in the path, even when your jar is in the current working directory. For example, for me this was failing:

I was able to fix this by givng the full, quoted path to the jar:

Credit goes to this answer for setting me on the right path.

Thanks for this. Need to give the full path in Linux as well, if trying to run it from a different directory.

This answer is partly a duplicate of an already given answer on this question. This is the earlier answer with the same method: full quoted path. Sep 6 ’15 by @benez

I had this issue under CygWin in Windows. I have read elsewhere that Java does not understand the CygWin paths ( /cygdrive/c/some/dir instead of C:\some\dir ) — so I used a relative path instead: ../../some/dir/sbt-launch.jar .

In cases where you need cygwin to use windows formatted paths instead of cygwin paths you can use the cygpath -w /path/here command to convert the path to the windows equivalent.

Читайте также:  What is aptitude linux

I had the same issue when trying to launch the jar file. The path contained a space, so I had to place quotes around. Instead of:

java -jar C:\Path to File\myJar.jar 
java -jar "C:\Path to File\myJar.jar" 

The quotations did the trick for me since I also had spaces inbetween. I then tried it without spaces in the path and without quotation marks and then it worked also

Anno 2019: This solution helped for me, with quotation marks! Without quotation marks and without spaces it doesn’t work in my case.

Just came across the same problem trying to make a bad USB.

I tried to run this command in admin cmd

java -jar c:\fw\ducky\duckencode.jar -I c:\fw\ducky\HelloWorld.txt -o c:\fw\ducky\inject.bin 
Error: unable to access jarfile c:\fw\ducky\duckencode.jar 

Right click the jarfile in question. Click properties. Click the unblock tab in bottom right corner. The file was blocked, because it was downloaded and not created on my PC.

In the cmd I changed the directory to where the jar file is located.

Then I typed dir and saw the file was named duckencode.jar.jar

So in cmd I changed the original command to reference the file with .jar.jar

java -jar c:\fw\ducky\duckencode.jar.jar -I c:\fw\ducky\HelloWorld.txt -o c:\fw\ducky\inject.bin 

That command executed without error messages and the inject.bin I was trying to create was now located in the directory.

None of the provided answers worked for me on macOS 11 Big Sur. The problem turned out to be that programs require special permission to access the Desktop, Documents, and Downloads folders, and Java breaks both the exception for directly opened files and the permission request popup.

  • Move the .jar into a folder that isn’t (and isn’t under) Documents, Desktop, or Downloads.
  • Manually grant the permission. Go to System Preferences → Security and Privacy → Privacy → Files and Folders → java, and check the appropriate folders.

If you are using OSX, downloaded files are tagged with a security flag that prevents unsigned applications from running.

to check this you can view extended attributes on the file

$ ls -l@ -rw-r--r--@ 1 dave staff 17663235 13 Oct 11:08 server-0.28.2-java8.jar com.apple.metadata:kMDItemWhereFroms 619 com.apple.quarantine 68 

You can then clear the attributes with

I had a similar problem and I even tried running my CMD with administrator rights, but it did not solve the problem.

The basic thing is to make sure to change the Directory in cmd to the current directory where your jar file is.

  1. Copy jar file to Desktop.
  2. Run CMD
  3. Type command cd desktop
  4. Then type java -jar filename.jar

Edit: From JDK-11 onwards ( JEP 330: Launch Single-File Source-Code Programs )

Since Java 11, java command line tool has been able to run a single-file source-code directly. e.g.

It can also happen if you don’t properly supply your list of parameters. Here’s what I was doing:

java -jar test@gmail.com testing_subject file.txt test_send_emails.jar 

Instead of the correct version:

java -jar test_send_emails.jar test@gmail.com testing_subject file.txt 
cd /path/to/the/jar/ java -jar ./Calculator.jar 

For me it happens if you use native Polish chars in foldername that is in the PATH. So maybe using untypical chars was the reason of the problem.

Читайте также:  Операционная система linux применению

sometime it happens when you try to (run or create) a .jar file under /libs folder by right click it in android studio. you can select the dropdown in top of android stuio and change it to app. This will work

enter image description here

My particular issue was caused because I was working with directories that involved symbolic links (shortcuts). Consequently, trying java -jar ../../myJar.jar didn’t work because I wasn’t where I thought I was.

Disregarding relative file paths fixed it right up.

In my case the suggested file name to be used was jarFile*.jar in the command line. The file in the folder was jarFile-1.2.3.jar . So I renamed the file to jarFile . Then I used jarFile.jar instead of jarFile*.jar and then the problem got resolved

It can happen on a windows machine when you have spaces in the names of the folder. The solution would be to enter the path between » «. For example:

java -jar c:\my folder\x.jar --> java -jar "c:\my folder\x.jar" 

To avoid any permission issues, try to run it as administrator. This worked for me on Win10.

I know this thread is years ago and issue was fixed too. But I hope this would helps someone else in future since I’ve encountered some similar issues while I tried to install Oracle WebLogic 12c and Oracle OFR in which its installer is in .jar format. For mine case, it was either didn’t wrap the JDK directory in quotes or simply typo.

Run Command Prompt as administrator and execute the command in this format. Double check the sentence if there is typo.

«C:\Program Files\Java\jdk1.xxxxx\bin\java» -jar C:\Users\xxx\Downloads\xxx.jar

If it shows something like JRE 1.xxx is not a valid JDK Java Home , make sure the System variables for JAVA_HOME in Environment Variables is pointing to the correct JDK directory. JDK 1.8 or above is recommended (2018).

Источник

Unable to access jarfile

I’m trying to run a .jar file on the start up of my Linux machine (Ubuntu 12.04 server) My script works as long as I run it inside the directory which it is in. If I try to run it outside the directory I get the error «Cannot access jarfile settasks.jar». I suppose my other script is having the same issue. Is this possibly a script error or a permissions error? I’m completely lost and I have not found anything as of yet to resolve the issue. Any help will be welcomed.

Little unclear here. Is settasks.jar another file which you didn’t move or is it the one you did move?

4 Answers 4

Right click on the file and select Copy .

Now, say you are executing the file using this in the directory with the file in:

Type the beginning of the command ( java -jar ), and then paste — Ctrl + Shift + V — you should end up with something like this, where is specifies the full path to the file:

java -jar file:///home/wilf/settask/settask.jar 

Remove the file:// and press ↵ :

java -jar /home/wilf/settask/settask.jar 

If it works, then the same command should work in your script.

Читайте также:  Find all images linux

I hope this answer is OK, I think you are asking about bash scripts.

./ tells it the command to search the directory it is currently in.

Having file:// at the beginning means it won’t work.

I ran into Unable to access jarfile when trying to start a Spring Boot SysVinit service.

It turned out the directory and content in /srv/myapp/ had wrong ownership.

Running sudo sh -c «chown -R myapp:myapp /srv/myapp/ && chmod -R u=rx,g=,o= /srv/myapp» gave all relevant files and directories correct ownership and permissions.

I had the same problem. Starting it in the Terminal with the error

Unable to access unicentaopos.jar 

The solution is more simple than the problem.

Add to the known starter the line Path=/usr/bin/unicenta/ and the problem is solved.
The folder /unicenta is of course the folder where the program is.

In that way the starter looks like:

[Desktop Entry] Encoding=UTF-8 Version=1.0 Name=Unicenta Comment=Fires up Unicenta oPOS Type=Application Path=/usr/bin/unicenta/ Exec=/usr/bin/unicenta/start.sh Icon=/usr/bin/unicenta/unicentaopos.ico 

To create the starter just CTRL + ALT + T to open the terminal.

Type cd Desktop (or Bureaublad if its Dutch) (Case sensitive)

Type nano unicenta.desktop . Copy and paste the mentioned code.

Press CTRL + O to save is. Close is by pressing CTRL + X . Type chmod +x unicenta.desktop .

Источник

Unable to access jarfile in Ubuntu, even with full permissions?

I’m fairly new to Linux/Unix and I’m having trouble making a shell script run an executable jar file. This is the content of my shell script start.sh:

java -Xmx4096 -Xms4096 -jar "/home/user/Documents/Mserver/fserver.jar" 
Error: Unable to access jarfile /home/user/Documents/Mserver/fserver.jar 
chmod u+x /home/user/Documents/Mserver/start.sh chmod u+x /home/user/Documents/Mserver/fserver.jar chmod -R 777 /home/user/Documents/Mserver 

To give all of my files read, write, and execution permissions Also, I originally just had the name of the jar file in the shell script and not the whole path it was in. After being told that adding the path may fix the problem, I added it but nothing changed. When I was looking at another similar question on the site I saw someone was having the same problem with a pearl script and it was because of something with a configuration file, but I have no idea if this is relevant to me at all. I’m a newbie and I have no idea what to try next, so please let me know if you’ve noticed anything wrong with how I’m doing this, have any suggestions, or think I left out any important details. EDIT: When running the command

ls -l /home/user/Documents/Mserver/fserver.jar 
-rwxrwxrwx 1 user user 4883911 Dec 12 17:15 /home/user/Documents/Mserver/fserver.jar 
path="$HOME/Documents/Mserver/fserver.jar" java -Xmx4096 -Xms4096 -jar $path 
Error: Unable to access jarfile /home/user/Documents/Mserver/fserver.jar 

Also, another thing I forgot to note is when I navigate to the directory where the jar file is and run the command

java -Xmx4096 -Xms4096 -jar fserver.jar 

Источник

Оцените статью
Adblock
detector