0

I am trying to generate a WAR using Maven via command line with the following command:

mvn clean package

Which correctly builds a WAR file, but when I open the file with 7-Zip I can see that there are some classes with compilation problems where the body of the methods just contain something like this:

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

Although the compiled classes in target/classes are correct. They do not have compilation problems.

Looking at the Maven debug log I can it for the problematic classes:

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

Here is the build part of my 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>

Can you guys help me on that?

EDIT 1:

The dependencies are correctly set in my pom.xml. That's even a good point. It seems that the unresolved compilation problems come from unresolved classes that are in a different jar in my project.

Here is my full 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>
  • Did you add all dependencies?? Try run `maven clean install package` – Fernando Zamperin Jul 19 '16 at 19:41
  • The error is probably coming from a missing dependency in your jsp's. I would expect there to be some dependencies listed here, even if it's just to your own application jar module(s) – Gus Jul 19 '16 at 19:47
  • The dependencies are correctly set in my pom.xml. Please see my edited (EDIT 1) post. – Diego Marques Jul 19 '16 at 19:57
  • Are you using Eclipse? It's compiler can inject this kind of code. – Robert Scholte Jul 19 '16 at 20:04
  • I am running from the command line using `mvn clean package` – Diego Marques Jul 19 '16 at 20:09
  • If the missing dependency is in that `test/test-client/1` dependency, you probably need to run `maven clean install -U` on the the jar package, then the war package. Also consider using SNAPSHOT version numbers for your projects until you're ready to release; see http://stackoverflow.com/q/5901378/535515 – Gus Jul 19 '16 at 20:10
  • I tried `mvn clean install -U` on all projects but it didn't work, I got the same error – Diego Marques Jul 19 '16 at 20:21
  • I noted that `mvn compile` works fine but `mvn package` does not. Any idea? – Diego Marques Jul 19 '16 at 21:48

0 Answers0