如何在CMD中的包中编译和运行特定的.java文件? [英] How do I compile and run a particular .java file in a package from CMD?

查看:169
本文介绍了如何在CMD中的包中编译和运行特定的.java文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然有许多问题与此相关,但我找不到专门回答这个问题的问题。

While there have been many questions related to this, I couldn't find one that specifically answers this.

这是Eclipse中我的源代码的文件结构。现在我想在一些机器上运行serverStart.java,在其他机器上运行clientStart.java。

This is the file structure of my source code in Eclipse. Now I want to run serverStart.java in some machines, and clientStart.java in some other machines.

它必须从源代码中编译并从命令行运行。我不允许使用Eclipse。我使用什么命令来编译和运行项目?我应该为此创建一个jar文件,还是使用javac? (我试过在clientStart上使用javac,它给我一些错误(找不到符号),与其他类像clientData在同一个包相关)

It has to be compiled and run from command line (CMD) from the source code. I am not allowed to use Eclipse. What command do I use to compile and run the project? Should I create a jar file for this, or use javac? (I tried using javac on clientStart and it gave me some errors (Cannot find symbol), related to other classes like clientData that are in the same package)

注意clientStart和serverStart有public static void main(String args []),并且还创建类似clientACK.java的其他类的对象。

Note that clientStart and serverStart have "public static void main(String args[])" and also create objects of other classes like clientACK.java.

这是Windows中的文件夹结构 -

This is the folder structure in windows -

编辑:我也有.class文件为每个在bin文件夹。

I also have .class files for each in the bin folder. Are they useful in any way?

推荐答案

回答自己的问题,

我不得不导航到父目录,在这种情况下是C:\IP \IP_proj2 \src。从这里,我使用命令。

I had to navigate to the parent directory, which is C:\IP\IP_proj2\src in this case. From here, I use the command.

javac IP_proj2/*.java

这里的关键是使用* .java同时编译它们。当我单独尝试它,它给出不能找到符号的错误。

The key here is to compile them all at the same time using *.java I believe. When I tried it out individually, it gave "cannot find symbol" errors.

命令运行它 -

java IP_proj2.serverStart

这篇关于如何在CMD中的包中编译和运行特定的.java文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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