在cmd中编译运行java,如何在CMD中的包中编译和运行特定的.java文件?

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

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.

1zb3t.png

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)

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

This is the folder structure in windows -

5iPvb.png

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

解决方案

Answering my own question,

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

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.

Command to run it -

java IP_proj2.serverStart

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值