Home » Java » "Unable to access jarfile" in linux land

"Unable to access jarfile" in linux land

Posted by: admin December 28, 2021 Leave a comment

Questions:

We have an web application running under JBoss 5 which periodically launches a ‘java’ process (using ProcessBuilder) to compile files on Linux. The process works without problems on the Windows development machine and on a Ubuntu virtual machine that we’ve got installed. The command is as follows:

/usr/java/jdk1.6.0_18/bin/java -Xmx256M -DiDesigner.javabin=java -jar "/aplicaciones/jboss/nfs/pmc_tdt/bin/lib/iDesigner.jar" --compiler --obfuscate --in "81.ida" --out "directory:OUTPUT"

Which creates the error:

Unable to access jarfile "/aplicaciones/jboss/nfs/pmc_tdt/bin/lib/iDesigner.jar"

All paths are confirmed to be correct and the jar file path is enclosed by double quotes. After two beers and a Big Mac the Systems Department confirmed that the user (jbossadmin) running JBoss is also the owner of the file:

[[email protected] lib]# pwd
/aplicaciones/jboss/nfs/pmc_tdt/bin/lib
[[email protected] lib]# ls -l iDesigner.jar
-rw-r--r-- 1 jbossadmin jbossadmin 1329162 ene 22  2010 iDesigner.jar

I suspect that it’s a rights issue so we asked them to change the permissions to execute but alas, still no gratification.

The only thing I can think of is that it’s a path translation error or that we haven’t applied the right rights to the right place!

Edit: An excellent suggestion by Andrea Spadaccini, however it seems that we already have the traversal permissions through the path:

drwxr-xr-x 3 root root 4096 abr  6  2010 /aplicaciones/
drwxr-xr-x+ 16 jbossadmin jbossadmin 4096 mar  7 10:13 /aplicaciones/jboss/
drwxrwxr-x+ 5 jbossadmin jbossadmin 4096 ene 25 09:21 /aplicaciones/jboss/nfs/
drwxr-xr-x 4 jbossadmin jbossadmin 4096 abr  6 16:03 /aplicaciones/jboss/nfs/pmc_tdt
drwxr-xr-x 4 jbossadmin jbossadmin 4096 sep  3  2010 /aplicaciones/jboss/nfs/pmc_tdt/bin/
drwxr-xr-x 3 jbossadmin jbossadmin 4096 abr  6 16:03 /aplicaciones/jboss/nfs/pmc_tdt/bin/lib/ 

Edit: With Eva we can confirm that executing the line via the command line (bash) that it works but it throws the error if we execute the line from the ProcessBuilder class, embedded in a jar file, in Linux. Just as our JBoss would do. The double quotes around the parameters are the most likely cause of the issue here.

Answers:

@ian_scho Hi!, I think the problem here is that by command line quotation marks is allowed because is interpreted by the process bash in linux (which is the command line interpret)… When ProcessBuilder class is used inside java code, quotation marks are interpreted as part of the path…for that the error “Unable to access jarfile” is showed. You can see the process parent with the command ps -adf , try to run your comand line in background (&) as follow:

/usr/java/jdk1.6.0_18/bin/java -Xmx256M -DiDesigner.javabin=java -jar "/aplicaciones/jboss/nfs/pmc_tdt/bin/lib/iDesigner.jar" --compiler --obfuscate --in "81.ida" --out "directory:OUTPUT" &

and then call the command

ps -adf

you will see that bash process is the parent… If you do the same when jboss is running you could see that the process’ parent of the java execution is another process that can’t interpret quotation marks.

I hope that this will help you 🙂

###

Check if all the directories leading to the JAR file have read and traversing permissions (+rx) for the jbossadmin user.

###

If you are running the Java command from a shell script, check that the shell script has Linux/Unix line terminators and not Windows ones, as might happen if the shell script was created on a Windows platform. The stated error will definitely occur in that circumstance.

Use the Kate editor on Linux to check & correct, or the dos2unix utility if available.

###

Go to the directory where the jar file located.

cd /aplicaciones/jboss/nfs/pmc_tdt/bin/lib/

Then execute the .jar file in the directory using,

java -jar ./iDesigner.jar

That worked for me.