Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

war project dependency in maven

Tags:

java

maven

I need to access one bean class from war project into my another war project. The bean class is exists in MyProject. I wrote pom of another project called NewProject as follows.

<groupId>MyProject</groupId>
    <artifactId>MyProject</artifactId>
    <version>1</version> 
</parent>
<artifactId>MyProject</artifactId>
<packaging>war</packaging>

Is it possible to add war dependency in another war project?

like image 323
Pinky Avatar asked Oct 15 '13 07:10

Pinky


People also ask

Can we add war as dependency in Maven?

war archive which Maven can't handle as a dependency. I had no idea how to solve the problem until I stumbled upon a StackOverflow answer with a snippet that used maven-war-plugin to generate an additional artifact with classes which can be referenced from other modules.

What is war in Maven?

war:war is the default goal invoked during the package phase for projects with a packaging type of war . It builds a WAR file. war:exploded is generally used to speed up testing during the developement phase by creating an exploded webapp in a specified directory.


1 Answers

If you configure the maven-war-plugin with the following attribute:

<attachClasses>true</attachClasses>

you would get an supplemental artifact with the following coordinates:

<dependency>
  <groupId>myGroup</groupId>
  <artifactId>myArtifact</artifactId>
  <version>myVersion</myVersion>
 <classifier>classes</classifier>
</dependency>

which contains all classes within your war project which can be used as dependency which is a jar file which will solve your problem.

like image 52
khmarbaise Avatar answered Oct 27 '22 01:10

khmarbaise