如何在命令提示符下运行 Java 程序 [英] How to run Java program in command prompt
问题描述
我创建了一个 Java 项目来调用 Web 服务.它有一个 Main java 文件和另一个类文件.我为 HTTP 客户端使用了一些 jar 文件.
在 Eclipse 中它运行良好.我需要通过传递一些参数在命令提示符下运行 Java 程序.
在命令提示符中,我转到包含主 java 和子类 java 文件的 src 文件夹,并给出以下命令
javac mainjava.java
我收到以下错误
<块引用>mainjava.java:14:找不到符号
符号:类子类
这里的 SubClass 是我用来调用 web 服务的另一个 java 类文件.
如何通过传递参数来运行程序?
javac
是 Java 编译器.java
是 JVM 和用于执行 Java 程序的东西.您不执行 .java
文件,它们只是源文件.大概有 .jar
某处(或包含 .class
文件的目录)是在 Eclipse 中构建它的产物:
从目录java
执行:
java -cp lib/mypackage.jar 主 arg1 arg2
I created a Java project to call a Web service.
It has one Main java file and another class file.
I have used some jar files for HTTP client.
In Eclipse it runs fine.
I need to run the Java program in command prompt by passing some arguments.
In command prompt I went to src folder containing main java and sub class java file and gave the following command
javac mainjava.java
I'm getting following error
mainjava.java:14: cannot find symbol
symbol : class SubClass
here SubClass is my another java class file used to call the web service.
How to run the program by passing arguments?
javac
is the Java compiler. java
is the JVM and what you use to execute a Java program. You do not execute .java
files, they are just source files.
Presumably there is .jar
somewhere (or a directory containing .class
files) that is the product of building it in Eclipse:
java/src/com/mypackage/Main.java java/classes/com/mypackage/Main.class java/lib/mypackage.jar
From directory java
execute:
java -cp lib/mypackage.jar Main arg1 arg2
这篇关于如何在命令提示符下运行 Java 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!