Maven生成的WAR具有未解决的编译问题

时间:2016-07-19 19:34:46

标签: java maven war

我正在尝试使用Maven通过命令行使用以下命令生成WAR:

mvn clean package

哪个正确构建了一个WAR文件,但是当我用7-Zip打开文件时,我可以看到有些类有编译问题,其中方法的主体只包含这样的内容:

throw new Error("Unresolved compilation problem: \n");

虽然target/classes中编译的类是正确的。他们没有编译问题。

查看Maven调试日志,我可以查找有问题的类:

[DEBUG]  - WEB-INF/classes/test/Test.class wasn't copied because it has already been packaged for overlay [currentBuild].

这是我的pom.xml的构建部分:

<build>
    <sourceDirectory>JavaSource</sourceDirectory>
    <resources>
        <resource>
            <directory>JavaSource</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <warSourceDirectory>WebContent</warSourceDirectory>
                <failOnMissingWebXml>true</failOnMissingWebXml>
                <archive>
                    <manifest>
                        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        <addClasspath>true</addClasspath>
                    </manifest>
                    <manifestEntries>
                        <Implementation-Build>${project.version}</Implementation-Build>
                    </manifestEntries>
                    <addMavenDescriptor>false</addMavenDescriptor>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

你能帮助我吗?

编辑1:

在我的pom.xml中正确设置了依赖项。这甚至是一个好点。似乎未解决的编译问题来自我项目中不同jar中的未解析类。

这是我的完整pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>test</groupId>
    <artifactId>test-war</artifactId>
    <version>1</version>
    <packaging>war</packaging>
    <parent>
        <groupId>test</groupId>
        <artifactId>test-pom</artifactId>
        <version>1.0.0</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.0.6</version>
        </dependency>
        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.6</version>
        </dependency>
        </dependency>
        <dependency>
            <groupId>javaee</groupId>
            <artifactId>javaee-api</artifactId>
            <version>5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>test</groupId>
            <artifactId>test-client</artifactId>
            <version>1</version>
        </dependency>
    </dependencies>
    <build>
        <sourceDirectory>JavaSource</sourceDirectory>
        <resources>
            <resource>
                <directory>JavaSource</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <failOnMissingWebXml>true</failOnMissingWebXml>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            <addClasspath>true</addClasspath>
                        </manifest>
                        <manifestEntries>
                            <Implementation-Build>${project.version}</Implementation-Build>
                        </manifestEntries>
                        <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

0 个答案:

没有答案