Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing packaging based on active profile in pom

Tags:

java

maven-2

I have a project which I compile with maven. I have different profiles declared in pom.xml. For some of these profiles, I prefer building a war, and for other profiles I prefer a jar. I use to manually edit the pom.xml file and change packaging variable to either

<packaging>war</packaging> 

or

<packaging>jar</packaging> 

before doing a

$ mvn clean package -Pchosenprofile 

How can I tell mvn the packaging corresponding to each profile so I don't need to edit pom.xml?

like image 556
matiasg Avatar asked Nov 23 '11 19:11

matiasg


People also ask

What is the default packaging in POM xml?

1 Answer. Show activity on this post. The current core packaging values are: pom, jar, maven-plugin, ejb, war, ear, rar, par.

What is packaging type POM in Maven?

“pom” packaging is nothing but the container, which contains other packages/modules like jar, war, and ear. if you perform any operation on outer package/container like mvn clean compile install. then inner packages/modules also get clean compile install. no need to perform a separate operation for each package/module.


1 Answers

If you want to use profile you can use something like:

<?xml version="1.0" encoding="UTF-8"?> <project>     <modelVersion>4.0.0</modelVersion>     ..     <packaging>${packaging.type}</packaging>      <profiles>         <profile>             <id>webapp</id>             <activation>                 <activeByDefault>true</activeByDefault>             </activation>             <properties>                 <packaging.type>war</packaging.type>             </properties>         </profile>         <profile>             <id>batch</id>             <properties>                 <packaging.type>jar</packaging.type>             </properties>                 </profile>           </profiles> </project> 
like image 198
Torres Avatar answered Sep 19 '22 19:09

Torres