linux 环境中的“无法访问 jarfile”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5569591/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Unable to access jarfile" in linux land
提问by ian_scho
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:
我们有一个在 JBoss 5 下运行的 Web 应用程序,它定期启动一个“java”进程(使用 ProcessBuilder)来编译 Linux 上的文件。该过程在 Windows 开发机器和我们已经安装的 Ubuntu 虚拟机上运行没有问题。命令如下:
/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:
确认所有路径都正确,jar 文件路径用双引号括起来。在喝了两杯啤酒和一个巨无霸之后,系统部门确认运行 JBoss的用户 ( jbossadmin) 也是该文件的所有者:
[root@miv-multicanalidad-01 lib]# pwd
/aplicaciones/jboss/nfs/pmc_tdt/bin/lib
[root@miv-multicanalidad-01 lib]# ls -l iDesigner.jar
-rw-r--r-- 1 jbossadmin jbossadmin 1329162 ene 22 2010 iDesigner.jar
I suspect that it's a rights issueso we asked them to change the permissions to executebut alas, still no gratification.
我怀疑这是一个权利问题,所以我们要求他们更改执行权限,但唉,仍然不满意。
The only thing I can think of is that it's a path translation erroror 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:
编辑:Andrea Spadaccini 的一个很好的建议,但是我们似乎已经拥有了通过路径的遍历权限:
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.
编辑:使用 Eva,我们可以确认通过命令行 (bash) 执行该行是否有效,但如果我们在 Linux 中从 ProcessBuilder 类(嵌入在 jar 文件中)执行该行,则会引发错误。正如我们的 JBoss 所做的那样。参数周围的双引号是这里问题的最可能原因。
采纳答案by evita
@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:
@ian_scho 嗨!,我认为这里的问题是通过命令行引号是允许的,因为它是由linux中的进程bash解释的(这是命令行解释)......在java代码中使用ProcessBuilder类时,引号被解释为路径的一部分...因为显示错误“无法访问 jarfile”。您可以使用命令查看进程父进程ps -adf
,尝试在后台 (&) 中运行您的命令行,如下所示:
/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.
你会看到 bash 进程是父进程......如果你在 jboss 运行时做同样的事情,你会看到 java 执行的进程的父进程是另一个不能解释引号的进程。
I hope that this will help you :)
我希望这会帮助你:)
回答by Andrea Spadaccini
Check if all the directories leading to the JAR file have read and traversing permissions (+rx
) for the jbossadmin
user.
检查通向 JAR 文件的所有目录+rx
是否对jbossadmin
用户具有读取和遍历权限 ( ) 。
回答by Jool
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.
如果您从 shell 脚本运行 Java 命令,请检查 shell 脚本是否具有 Linux/Unix 行终止符而不是 Windows 行终止符,如果 shell 脚本是在 Windows 平台上创建的,则可能会发生这种情况。在这种情况下肯定会发生所述错误。
Use the Kate editor on Linux to check & correct, or the dos2unix utility if available.
使用 Linux 上的 Kate 编辑器进行检查和更正,或使用 dos2unix 实用程序(如果可用)。
回答by Koga
Go to the directory where the jar file located.
转到 jar 文件所在的目录。
cd /aplicaciones/jboss/nfs/pmc_tdt/bin/lib/
Then execute the .jar file in the directory using,
然后使用执行目录中的 .jar 文件,
java -jar ./iDesigner.jar
That worked for me.
那对我有用。