在Terminal中编译/运行Java文件 [英] Compiling/Running Java files in Terminal

查看:435
本文介绍了在Terminal中编译/运行Java文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个调用多个文件的文件,但是我遇到了一些错误。

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

在当前目录中名为 day4Measurement ,我有13个文件:BuggyMeasurement.java,BuggyMeasurement01.java,BuggyMeasurement02.java,BuggyMeasurement03.java,BuggyMeasurement04.java ... BuggyMeasurement10.java,MeasurementTest.java和Measurement.java。

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 包含 main()并调用所有其他文件。

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

这是 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);
}

在Mac终端,我运行

javac Measurement.java

和我得到问题。这是我得到的:

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


任何建议?

推荐答案

一旦你有一个目录中的所有文件(它们可能在子目录中 - 只要它们都在一些共享内目录),让我们称之为dir,使用以下内容:

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

假设您从Measurement.java所在的同一目录运行命令。如果没有,并且无论哪种方式,您都更安全方式,使它成为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

这对java编译器说我想要编译Measurement.java,就在这里,在这里你可以找到它需要的所有类和/或源文件。然后它将只编译Measurement.java引用的文件,因此您无需担心意外编译所有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.

这篇关于在Terminal中编译/运行Java文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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