如何从cmd运行多个类的java程序? [英] How do I run java program with multiple classes from cmd?

查看:1151
本文介绍了如何从cmd运行多个类的java程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在寻找另一种方式来从命令行运行我的Java程序,除了将其添加到JAR文件。我的程序有以下几个类:

At the moment I am looking for another way to run my Java program from command line, other than adding it to a JAR file. My program has the following number of classes:

程序文件的名称 - MyProgram

主类 - Server1

第二类 - 客户端处理程序

软件包名称 - 项目

第三类 - User1

第四类 - User2

The name of the program file - MyProgram
Main class - Server1
second class - Client Handler
Package name - Items
3rd class - User1
4th class - User2

主类和客户端处理程序与程序包一起将必须首先运行,以便用户1&

The main class and client handler alongside the package will have to run first in order for user 1 & user 2 to run, because they are client classes and are dependent on the main class.

推荐答案

javac *.java // compliles all java files in the dir

java MyClass // runs the particular file

如果一个类依赖于另一个尚未编译的类,程序将不会运行。因此,您应该在尝试运行依赖于其他文件的程序之前编译所有文件。

If one class is dependent on another class that hasn't been compiled yet, the program won't run. So you should compile all files before trying to run the program dependent on other files.

如果您的文件已打包,则此类

If your files are packaged, then something like this

javac com.mypackage/.*java

java com.mypackage.MyClass

这篇关于如何从cmd运行多个类的java程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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