How to create a war and a bank from a web project?

I have a maven web project that has packaging as a "war". the package generates a war file that confirms the format of the war. But I like to pack the project as a "jar", as well as the default "military" format. So, I'm trying to use the "maven jar" plugin to achieve this. I am using the following jar plugin configuration.

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <executions> <execution> <id>make-a-jar</id> <phase>package</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> <configuration> <classesDirectory>${project.build.outputDirectory}</classesDirectory> <includes> <include>../../src/main/webapp/**</include> <include>**/*</include> </includes> </configuration> </plugin> 

The package command creates a jar file that contains the classes, and the contents of the resources folder and the war file create the correct war file.

But the contents of "src / main / webapp" is not included in the jar file. How to include src / main / webapp contents in jar using jar plugin?

+4
source share
2 answers

Usually Maven war: war provides 2 significant parameters: -

1 archiveClasses

Will a JAR file be created for classes in webapp. Using this optional configuration parameter will make the compiled classes archived into a JAR file , and the class directory will be excluded from webapp. The default value is false. User Property : archiveClasses.

2 attachClasses

Whether classes (i.e. the contents of the WEB-INF / classes directory) should be added as an additional artifact. The default classifier for an additional artifact is β€œclasses”. You can change it using the <classesClassifier>someclassifier</classesClassifier> .

Even this function provides Maven War Plugin , it does not include src/main/webapp in the generated jar file. Then you can consider the Maven Asssembly Plugin

The build plugin for Maven is designed primarily so that users can aggregate the project output with its dependencies, modules, site documentation, and other files into a single distributed archive. Currently, it can create distributions in the following formats:

  • lightning
  • tar
  • tar.gz
  • tar.bz2
  • bank
  • folder
  • war
  • and any other format that has been configured for ArchiveManager for

Using Assembly Descriptors , you can Filter some distribution files and Include and exclude artifacts , etc. This means that you can create your own archive with any necessary content / resources.

If you want to use Maven Jar Plugin , as you already mentioned. It also provides the following: -

  • Inclusion / exclusion of content from jar artifact
  • To create an additional jar artifact attached from a project
  • and etc.

The use page will give you more information.

Hope this helps.

+1
source

The only clean way to do this with Maven is to split the project into two projects: one for building a can, one for building a war (simpler standard projects are better than one big non-standard project, especially with Maven)

Now If you want to also share files in src / main / webapp, you can use military overlays (wars as dependencies), or use something like spring servletDispatcher and mvc: resources tags.

+2
source

All Articles