运行类文件作为单独的进程从java代码 [英] run class file as separate process from java code

查看:190
本文介绍了运行类文件作为单独的进程从java代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

所以我有这个代码,我试图运行JNIProgram.class文件程序会立即终止而不执行其工作(这是创建一个新的txt文件并写入)

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)

所以我做错了

推荐答案

java 命令需要Java 类名,而不是filename

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

所以命令 java E:/workspace/JNIProgram/src/JNIProgram.class 是错误的。

命令应该是这样的:

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

注意: -cp 选项后的是类路径,然后是完全限定类名称(只是 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).

首先确保您可以从命令手动运行命令在你使用另一个Java程序工作之前。

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

这篇关于运行类文件作为单独的进程从java代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆