0
votes

My pom.xml looks like this (note I'm building a JAR as well as a WAR):

            ...
            <packaging>war</packaging>
            ...
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <containerConfigXML>src/main/webapp/META-INF/context.xml</containerConfigXML>
                    <archiveClasses>true</archiveClasses>
                    <attachClasses>true</attachClasses>
                </configuration>
            </plugin>

However, the generated JAR only includes the classes in WEB-INF/classes. How can I get the JAR to include the classes in src/main/java/com/... etc as well - without having to add all the classes to the WEB-INF directory?

Thanks!

2
What kind of packaging did you defined in your pom ? May be you can give a little bit more of your pom? - khmarbaise
What is your goal actually? Don't break conventions. You obviously trying to do. - Michael-O

2 Answers

1
votes

Fixed by removing the archiveClasses node from the above code sample. New pom.xml looks like this:

            ...
            <packaging>war</packaging>
            ...
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <containerConfigXML>src/main/webapp/META-INF/context.xml</containerConfigXML>
                    <attachClasses>true</attachClasses>
                </configuration>
            </plugin>

Now the generated JAR includes all classes, not just those in WEB-INF/classes

0
votes

Generally if your resources are configured correctly (or standard layout) you should just be able to run

mvn package

Which should generate the jar file in your target directory.

Hope this helps.