终端运行java文件,在Terminal中编译/运行Java文件

I'm attempting to run a file that calls multiple files, but I'm getting some errors.

Inside the current directory called day4Measurement, I have 13 files: BuggyMeasurement.java, BuggyMeasurement01.java, BuggyMeasurement02.java, BuggyMeasurement03.java, BuggyMeasurement04.java...BuggyMeasurement10.java, MeasurementTest.java, and Measurement.java.

Measurement.java contains the main() and calls all the other files.

Here's the main():

public static void main(String [] args){

JUnitCore tester = new JUnitCore();

String s = "Failed to detect: ";

int count = 0;

String [] tests = {"toString prints reverse inches then feet", // 01

"plus modifies this", // 02

"minus modifies this", // 03

"multiple modifies this", // 04

"plus incorrect roll over", // 05

"minus incorrect roll over", // 06

"multiple incorrect roll over", // 07

"plus incorrect non-roll over", // 08

"minus incorrect non-roll over", // 09

"multiple incorrect non-roll over", // 10

"CORRRRECTTT!!!"

};

for (int i = 1; i < tests.length + 1; i++){

testRound = i;

System.out.println("Running: " + tests[i-1]);

TestRunner.run(day4Measurement.MeasurementTest.class);

Result temp = tester.run(day4Measurement.MeasurementTest.class);

if (temp.wasSuccessful()) {

s += tests[i-1] + "; ";

count++;

}

}

System.out.print(10-(count-1)*0.5 + " ");

System.out.println(s);

}

In the Mac Terminal, I run

javac Measurement.java

and I get issues. Here's what I get:

35ca13f578a8b844251c04677c5c5c40.png

YDa5J.png

Any suggestions?

解决方案

Once you have all the files in a directory (they may be in subdirectories - as long as they are all inside some shared directory), let's call it dir, use the following:

javac -classpath dir Measurement.java

Assuming that you are running the command from the same directory that Measurement.java is in. If not, and either way you are safer this way, make it an explicit path to both dir and Measurement.java, such as:

javac -classpath /home/yourusername/dir /home/yourusername/dir/Measurement.java

This says to the java compiler "I want to compile Measurement.java, here's where it is, and here's where you can find all the class and/or source files that it needs." It will then compile only the files referred to by Measurement.java, so you don't need to worry about accidentally compiling all of your java files ever.

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值