Jar depends on classes in a military project

Suppose I have war and jar projects defined in maven.

Jar project depends on War project

I managed to get this work to work in package mode by adding

In the military project <attachClasses> , true in the military plugin.

And creating dependency

  <groupId>com</groupId> <artifactId>oneway-delegator</artifactId> <version>1.0</version> <classifier>classses</classifier> 

in jar pom.

But at startup, only compiling jar classes is not created and everything fails.

Any ideas from people

+6
java maven-2
source share
2 answers

But at startup, only compiling jar classes is not created and everything fails.

You really can configure the maven-war plugin to package / deploy the classes and resources included in your webapp as a “sticky” JAR artifact with a classifier with the following configuration:

 <project> ... <artifactId>mywebapp</artifactId> <version>1.0-SNAPSHOT</version> ... <build> <plugins> <plugin> <artifactId>maven-war-plugin</artifactId> <version>XY</version> <configuration> <attachClasses>true</attachClasses> </configuration> </plugin> </plugins> </build> ... </project> 

But this artifact is created during the package phase, so don't expect it to be there if you only run compile .

Please note that this configuration option was introduced for a very specific use case, a skinny military use case. If you need to reuse this JAR in another project, it is recommended that you use the general approach to move the classes to a separate module that creates the JAR, and then declare a dependency on this JAR on your webapp, as well as on any other projects that need it.

+12
source share

Do not do this.

It is not an acceptable dependency to make a jar (simple Java code) depending on the war (special Java EE application package). If you have code in your war that you depend on, then this code should be in its own bank, and then both the web application and the jar project will have a common dependence on it.

+7
source share

All Articles