如何在命令提示符下运行Java程序 [英] How to run Java program in command prompt

查看:256
本文介绍了如何在命令提示符下运行Java程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Java项目来调用Web服务。
它有一个主java文件和另一个类文件。
我为HTTP客户端使用了一些jar文件。

在Eclipse中它运行良好。
我需要通过传递一些参数在命令提示符下运行Java程序。

在命令提示符下,我去了src文件夹,包含主java和子类java文件,并给出以下命令

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    


$ b b

我收到以下错误

I'm getting following error


mainjava.java:14:找不到符号

symbol:class SubClass

这里SubClass是我用来调用Web服务的另一个Java类文件。

here SubClass is my another java class file used to call the web service.

如何通过传递参数来运行程序?

How to run the program by passing arguments?

推荐答案

javac 是Java编译器。 java 是JVM和您用于执行Java程序。你不执行 .java 文件,它们只是源文件。
大概有 .jar 在某处(或一个包含 .class 文件的目录)在Eclipse中构建它:

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

从目录 java execute:

From directory java execute:


java -cp lib / mypackage.jar主要arg1 arg2

java -cp lib/mypackage.jar Main arg1 arg2

这篇关于如何在命令提示符下运行Java程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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