run class file as separate process from java code

不问归期 提交于 2020-01-05 08:11:41

问题


public static void main(String args[]) throws IOException
{
    Process p = Runtime.getRuntime().exec("java E:/workspace/JNIProgram/src/JNIProgram.class");
}   

so I have this code and am trying to run the JNIProgram.class file however the program gets terminated instantly without doing its job (which is to create a new txt file and write to it)

So what am I doing wrong


回答1:


The java command expects a Java class name, not a filename.

So the command java E:/workspace/JNIProgram/src/JNIProgram.class is wrong. If you try this manually from a command prompt window you'll get an error message.

The command should be something like this:

java -cp E:\workspace\JNIProgram\src JNIProgram

Note: What's after the -cp option is the classpath, and after that the fully-qualified class name (which is just JNIProgram, if the class is not in a package).

First make sure that you can run the command manually from the command line before you make it work from another Java program.



来源:https://stackoverflow.com/questions/11614112/run-class-file-as-separate-process-from-java-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!