在Linux中使用非root用户运行jar时,外部jar不可用

时间:2019-05-10 13:25:55

标签: java linux apache jar root

我有1个jar文件,这些文件依赖于外部jar,我已将外部jar打包在我的jar文件中,并能够使用root用户在Linux上成功运行jar文件。

我还有另一个用户只能访问/ user / bin和/ proc。

当我使用该用户运行jar文件时,出现以下错误:

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/text/RandomStringGenerator$Builder        
Caused by: java.lang.ClassNotFoundException: org.apache.commons.text.RandomStringGenerator$Builder
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 9 more

我无法向用户授予任何其他访问权限。如何使用相同的访问权限解决上述异常。 受限访问用户是jar的所有者,并且对整个文件夹拥有完全权限。

  

我为捆绑的jre提供jar,并且仅使用该jre执行jar。

运行jare的sh文件如下:

#unzip jre if not exists
if [ ! -d "$PWD/jre" ]
then
   unzip jre_64.zip
fi

#export java path
export PATH=$PWD/jre/bin:$PATH

#make all files executable
chmod 755 jre/bin/*

#run jar file
java  -jar jarName.jar

运行sh文件时没有任何错误,我的主类也已执行(通过添加日志已确认),但是无法加载外部jar。

0 个答案:

没有答案