So I have a spring mvc web application that I built in IntelliJ 9, using maven.
When I run a:
mvn clean install
It packages everything up in both a .war file and an exploded war.
My project layout is using a maven simple web app arch type.
How can I have my classes compiled into a .jar file also?
Currently my classes are in:
/target/myapp/WEB-INF/classes/
What I want is for it to compile my code in .jar like:
myapp-1.0.jar
And that have this in my /target/myapp/WEB-INF/lib
folder like all my other jars.
Update
I want this done via maven, not intellij specific.
You can easily create two artifacts - a JAR and a WAR.
I'm not sure what the advantage is of having your .class files in a JAR as opposed to WEB-INF/classes. Both are compressed; the JAR won't provide an extra compression. You might want to be re-using those .class files in other applications. if that's the case, you might consider moving those Java classes into a separate module and adding the JAR file you create just as you would any other 3rd party JAR in your WAR file. Other applications would easily be able to check out the JAR file from your repository and simply reuse it. This arrangement is best done by moving the shared Java classes into a separate repository in your version control system.
The simple solution is in the configuration for the war-plugin:
<attachClasses>true</attachClasses>
which will do the job and create a separate jar file. This jar has a classifier "classes" which can be changed by giving into the configuration. This can be useful if you have separated integration-tests which rely on classed from the war project to publish them and make them available as dependencies. This has nothing to do with separation of responsibilities.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With