生成后生成的目标文件不包含必须存在的所有已编译类

时间:2011-10-04 07:55:51

标签: java netbeans maven-2 maven

在构建项目时,控制台显示源包已编译(px10包内的包)

但是,如果我看到生成的目标文件,那么源包中没有任何类。

  1. 多次尝试clean & build但没有帮助
  2. 清除了.../var/cache/
  3. 的netbeans缓存

    以下是构建Web应用程序时生成的日志

    ------------------------------------------------------------------------
    Building ABCApp Java EE 6 Webapp 1.0
    ------------------------------------------------------------------------
    
    [antrun:run]
    Executing tasks
    Executed tasks
    
    [resources:resources]
    Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
    Copying 13 resources
    
    [compiler:compile]
    File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
    Compiling 81 source files to C:\dev\ABCApp\target\classes
    px10/BusinessLayer/LOBERs/connect.java:[248,38] ';' expected
    px10/BusinessLayer/User/User_2.java:[127,52] '.class' expected
    
    [resources:testResources]
    Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
    Copying 1 resource
    
    [compiler:testCompile]
    Nothing to compile - all classes are up to date
    
    [surefire:test]
    Surefire report directory: C:\dev\ABCApp\target\surefire-reports
    
    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    There are no tests to run.
    
    Results :
    
    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
    
    
    [war:war]
    Packaging webapp
    Assembling webapp [ABCApp] in [C:\dev\ABCApp\target\ABCApp]
    Processing war project
    Copying webapp resources [C:\dev\ABCApp\src\main\webapp]
    Webapp assembled in [1841 msecs]
    Building war: C:\dev\ABCApp\target\ABCApp.war
    Warning: selected war files include a WEB-INF/web.xml which will be ignored 
    (webxml attribute is missing from war task, or ignoreWebxml attribute is specified as 'true')
    
    [install:install]
    Installing C:\dev\ABCApp\target\ABCApp.war to C:\dev\mavenRepository\w93\ABCApp\1.0\ABCApp-1.0.war
    Installing C:\dev\ABCApp\pom.xml to C:\dev\mavenRepository\w93\ABCApp\1.0\ABCApp-1.0.pom
    ------------------------------------------------------------------------
    BUILD SUCCESS
    ------------------------------------------------------------------------
    Total time: 9.053s
    Finished at: Tue Oct 04 11:49:46 IST 2011
    Final Memory: 6M/15M
    ------------------------------------------------------------------------
    

    由于我从{I}文件夹中删除了一个名为classes的文件夹,这个问题似乎就出现了。

    以下是项目的有效POM:

    web-inf

4 个答案:

答案 0 :(得分:2)

我发现问题是由于源包中的一些不可编译的类,因为没有类被复制到/target/classes/文件夹。在删除无法编译的源代码时,我发现它工作正常。

答案 1 :(得分:1)

maven不会将生成的内容放在src/main/webapp/WEB-INF/classes文件夹中。

默认情况下(以及上面的pom片段),它将已编译的类放在target/classes文件夹中。如果是war项目,maven war plugin会将类复制到webapp中的WEB-INF/classes文件夹。

因此,在您的情况下,请检查以下文件夹:

  • C:\ dev的\ ABCApp \目标\类
  • C:\ dev的\ ABCApp \目标\ ABCApp \ WEB-INF \类

答案 2 :(得分:1)

某些版本的maven-compiler-plugin

也会出现这种情况

以下修复程序为我解决了问题,maven现在可以正确报告编译器错误。 使用下面的注释版本,尽管代码无法编译,maven仍会成功构建。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.0</version>
    <!--This version will happily build successfully when the code fails to compile-->
    <!--<version>3.1</version>-->
</plugin>

答案 3 :(得分:0)

如果在使用Spring Boot应用程序构建Maven项目的代码时未在classes文件夹中创建包。 某些版本的maven-compiler-plugin

也会发生这种情况
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.0</version>
    <!--This version will happily build successfully when the code fails to compile-->
    <!--<version>3.1</version>-->
          <configuration>
                <!--<skipMain>true</skipMain>-->
                <skip>true</skip>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
</plugin>