简体   繁体   English

Java编译器在第一次编译后不会编译所有子文件夹

[英]Java compiler doesn't compile all subfolders after the first compile

I have a problem with the java compiler. 我的Java编译器有问题。
The folders of my java project looks like this: 我的Java项目的文件夹如下所示:

  • main folder 主文件夹
    • delivery folder 送货文件夹
      • Box.java Box.java
      • Factory.java 工厂.java
      • FragileBox.java FragileBox.java
      • Supplier.java Supplier.java
    • test folder 测试文件夹
      • Test.java Test.java
      • Test2.java Test2.java
      • Test3.java Test3.java
      • Test4.java Test4.java
      • Test5.java Test5.java
    • DeliveryTest.java DeliveryTest.java

Clearly I have 2 packages aswell, a delivery package and a test package . 显然,我还有2个软件包,一个delivery package和一个test package It's a school project, so the test package was given, we had to write the delivery package which is tested by the test package . 这是一个学校项目,因此给出了test package ,我们必须编写由test package测试过的delivery package test package

The DeliveryTest.java looks like this: DeliveryTest.java看起来像这样:

import java.util.ArrayList;

import java.util.List;

import test.*;

import delivery.*;

public class DeliveryTest {

    public static void main(String[] args) {

        List<Test> tests = new ArrayList<Test>();
        tests.add(new Test2());
        tests.add(new Test3());
        tests.add(new Test4());
        tests.add(new Test5());

        int level = 1;

        for (Test test : tests) {
            if (test.test()) {
                ++level;
            }
        }
        System.out.println("Az elert szint: " + level);
    }
}

I really don't want to detail the work and the purpose of the code, I don't think it's relevant here. 我真的不想详细说明代码的工作和目的,在这里我认为它无关紧要。
My problem is that if I compile the DeliveryTest.java as javac DeliveryTest.java , it creates the class files, and successfully compiles, but: after the first compile, when all the class files created I make any changes on delivery package it won't compile again, only the test package , and after compiler finishes the compile it will just return as everything went well. 我的问题是,如果我将DeliveryTest.java编译为javac DeliveryTest.java ,它将创建类文件并成功编译,但是:在第一次编译后,当所有类文件创建后,我都会在delivery package上进行任何更改。再次编译,仅test package ,并且在编译器完成编译后,它将随着一切顺利进行而返回。 It won't even create the class files again if I remove one of the class files from the delivery folder . 如果我从delivery folder删除了一个类文件,它甚至不会再创建类文件。 However, the test package compiles fine after the first compile, it has no problem with that. 但是, test package在第一次编译后可以正常编译,这没有问题。
How can I achieve that I can compile the delivery package aswell after the first compile? 在第一次编译后,如何实现可以编译交付程序包?

Thanks for any help 谢谢你的帮助

The Java compiler doesn't look around for files to compile. Java编译器不会寻找要编译的文件。 If you call it from the command line, you better use a call that names all Java files in their folders. 如果从命令行调用它,则最好使用以其文件夹中的所有Java文件命名的调用。 Assuming that the main folder is your working directory, 假设主文件夹是您的工作目录,

javac DeliveryTest.java delivery/*.java test/*.java

If you don't change files in the test package you may not have to use the last parameter. 如果您不更改测试包中的文件,则可能不必使用last参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM