Java Maven 编译不创建类文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23538349/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 23:43:18  来源:igfitidea点击:

Maven compile does not create class files

javamavenintellij-idea

提问by Spring

I have a 3 module maven project with parent pom. From parent when I run a maven clean-compile-test. It fails at test phase and gives tons of compilation errors saying "symbol not found" for my local classes.

我有一个带有父 pom 的 3 模块 maven 项目。当我运行 maven clean-compile-test 时,来自父级。它在测试阶段失败,并为我的本地类提供大量编译错误,提示“找不到符号”。

I discovered using IntelliJ ideif I use the "Make Project" button beforeI run a maven test, then maven test works!

如果我运行 maven 测试之前使用“制作项目”按钮我发现使用IntelliJ ide,然后 maven 测试工作!

Edit:Now I figured out that probelem is maven compile does not create class files in target folder for some reason this is my maven compiler plugin configuration in parent pom file:

编辑:现在我发现problem是maven compile由于某种原因不会在目标文件夹中创建类文件这是我在父pom文件中的maven编译器插件配置:

  <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>

                <source>1.6</source>
                <target>1.6</target>
                <excludes>
                    <exclude>**/*.*</exclude>
                </excludes>
            </configuration>
        </plugin>
    </plugins>

</build>

Any ideas?

有任何想法吗?

采纳答案by Aaron Digulla

Maven doesn't care about missing symbols in the packagephase; missing symbols will only be reported during the compilephase (= when the Java compiler is run by Maven).

Maven 不关心package阶段中丢失的符号;丢失的符号只会在compile阶段(= 当 Java 编译器由 Maven 运行时)报告。

To find out why it can't find the symbols, you need to examine one of the errors. Look into the folder targetand check if the missing class exists in there (at the right place).

要找出它找不到符号的原因,您需要检查其中一个错误。查看文件夹target并检查其中是否存在缺少的类(在正确的位置)。

mvn cleandeletes this folder but mvn compileshould put new files in there.

mvn clean删除此文件夹,但mvn compile应将新文件放入其中。

If you can't see anything obvious, then save a list of all the files in the targetfolder somewhere. Then build the project in IDEA. Again create a list of all files.

如果您看不到任何明显内容,请将文件target夹中所有文件的列表保存在某处。然后在IDEA中构建项目。再次创建所有文件的列表。

Sort both lists and then compare them. That might give you an idea what is wrong. My guess is that you configured Maven in an odd way (moving source folders or target folders).

对两个列表进行排序,然后比较它们。这可能会让你知道什么是错的。我的猜测是您以一种奇怪的方式配置了 Maven(移动源文件夹或目标文件夹)。

EDITThe configuration

编辑配置

<excludes>
    <exclude>**/*.*</exclude>
</excludes>

tells Maven "ignore all source files" which is equivalent to "don't do anything". Remove this and try again.

告诉 Maven“忽略所有源文件”,相当于“什么都不做”。删除它并重试。

回答by Vasily Pozdeev

One more thing.

还有一件事。

Look in pom.xml, tag <packaging>. If it sets in pom, Maven shouldn`t create class-files for you. Change it for appropriate package - jar, war...

查看 pom.xml,标记<packaging>。如果设置为pom,Maven 不应该为您创建类文件。将其更改为适当的包 - jar, war...