从 ProcessBuilder 执行 jar 给出 ClassNotFoundException
当我尝试从命令行执行 jar 时,它工作正常。我试图在另一个 java 程序中执行同一个 jar,如下所示:
ProcessBuilder pb = new ProcessBuilder("java", "-Xmx1024m -Xms1024m -DTOOLS_DIR="/home/IM/work/dist" -Daoi=whole -jar "/home/IM/work/dist/idt_tools.jar");
pb.start()
但是,这给了我一个 ClassNotFoundException
ERR>Exception in thread "main" java.lang.NoClassDefFoundError: -Xmx1024m -Xms1024m -DTOOLS_DIR="/home/IM/work/dist" -Daoi=whole -jar "/home/IM/work/dist/idt_tools/jar"
ERR>Caused by: java.lang.ClassNotFoundException: -Xmx1024m -Xms1024m -DTOOLS_DIR=".home.IM.work.dist" -Daoi=whole -jar ".home.IM.work.dist.idt_tools.jar"
ERR> at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
ERR> at java.security.AccessController.doPrivileged(Native Method)
ERR> at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
ERR> at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
ERR> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
ERR> at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
ERR>Could not find the main class: -Xmx1024m -Xms1024m -DTOOLS_DIR="/home/IM/work/dist" -Daoi=whole -jar "/home/IM/work/dist/idt_tools.jar". Program will exit.
为什么它认为这是一个类?你不能在一个长字符串中指定你的参数吗?
When I try to execute a jar from command line it works fine. I am trying to execute that same jar in another java program like so:
ProcessBuilder pb = new ProcessBuilder("java", "-Xmx1024m -Xms1024m -DTOOLS_DIR="/home/IM/work/dist" -Daoi=whole -jar "/home/IM/work/dist/idt_tools.jar");
pb.start()
However, this is giving me a ClassNotFoundException
ERR>Exception in thread "main" java.lang.NoClassDefFoundError: -Xmx1024m -Xms1024m -DTOOLS_DIR="/home/IM/work/dist" -Daoi=whole -jar "/home/IM/work/dist/idt_tools/jar"
ERR>Caused by: java.lang.ClassNotFoundException: -Xmx1024m -Xms1024m -DTOOLS_DIR=".home.IM.work.dist" -Daoi=whole -jar ".home.IM.work.dist.idt_tools.jar"
ERR> at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
ERR> at java.security.AccessController.doPrivileged(Native Method)
ERR> at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
ERR> at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
ERR> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
ERR> at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
ERR>Could not find the main class: -Xmx1024m -Xms1024m -DTOOLS_DIR="/home/IM/work/dist" -Daoi=whole -jar "/home/IM/work/dist/idt_tools.jar". Program will exit.
Why does it think that is a class? Can you not specify your arguments in one long string?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对我来说很有意义。
也许您不打算运行一个名为“-Xmx1024m -Xms1024m -DTOOLS_DIR="/home/IM/work/dist”的类 -Daoi=whole -jar "/home/IM/work/dist/idt_tools.jar" 也许 是这些是单独的论点?
你的意思
Makes sense to me.
Perhaps you didn't intend to run a class called "-Xmx1024m -Xms1024m -DTOOLS_DIR="/home/IM/work/dist" -Daoi=whole -jar "/home/IM/work/dist/idt_tools.jar" perhaps you meant those to be seperate arguments?
try