If you want your stuff to be compiled as a .jar as well as a .war, you can do this by specifying the jar goal in the command line:
[shell>mvn clean jar install
Note this will make myproject.jar in target/, not in target/myproject/WEB-INF/lib, so you will need to use the Ant plugin to move this stuff around.
But this is not always an option: for deep, modular builds using the reactor, you may want to build your whole thing using one "mvn install". To do this, do the following:
- Specify "war" packaging at the top of your pom.xml.
- Then add the following to your build section.
And that's it. Do a " maven install" and you get a jar and a war.
Thanks for posting this. I found it helpful. In addition for those interested in also having the jar file installed in the local repository I added the following to do so:
Thanks for this - I had tried and failed with a few attempts before I stumbled upon this elegant solution
And what do you think about this solution:
Thanks for a nice solution :) In addition to installing to the local repository, one may be interested in deploying the Jar to the release repository as well. It can be accomplished like this:
note: the install and deploy options assume you do NOT have finalName defined, make sure you comment it out or adjust.
Identified an issue - the url configuration needs to change between SNAPSHOT and production builds.
Also, it looks like SNAPSHOT deploy builds to not follow previous SNAPSHOT configurations (i.e. I turn off unique versions, but this deploy turns it back on by default).
Works like a charm.
I used all three plugins, and was able to force the deploy-file plugin to use my SNAPSHOT version, instead of a unique version, by adding this line within the configuration element:
I addded this line:
to the configuration element of the deploy-file plugin to allow my repository to continue using SNAPSHOT.
Thanks. Exactly what I was looking for.
Great, It was so helpful! Thanks.
Can you please share more information about your setup ?
I am trying to setup 3rd party maven repository to share with our team.
Can I deploy jar file to artifactory repository using your setup ?
Thanks a lot
It very use full to me
And i have a question
How can i create a different META_INF for jar ?
I used following tags under Configuration tag but no luck
< useDefaultManifestFile > true < /useDefaultManifestFile >
< addMavenDescriptor > false < /addMavenDescriptor >
The proposed solution is not working if the webapps having any resources, it is just making whole thing as a jar, but expected was only classes should go in jar.
Is the best of all .
Great! i thought i want something wrong, but here it is.
Thanks to Lynn W for install issue solution.
I came across this post looking for how to publish my war file and it's jar'd classes at the same time. It was definitely helpful, but then I discovered the maven-war-plugin now has a configuration parameter: attachClasses which does the same thing when set to true. I just thought I'd pass that along.
Thanks Marlon and Lynn. Very helpful.
When I use the original posts method the jar file gets created on the same level as the war file. How can I put that jar file inside the war file under a folder name of 'applet'? Kind of like on this post here http://stackoverflow.com/questions/34662156/maven-jar-inside-a-war
Worked like a charm. Thanks Marlon!!
Post a Comment