In Maven, How can I get 2 copies of the jar with dependencies, but with different names? - maven

I'm working on a Maven project and the assembly that I have setup creates a jar with all the dependencies that I need, as of now the configuration builds 2 different jars "project-jar-with-dependencies.jar" and "project-plugin.jar", but I would like to build a copy of the "project-plugin.jar" that does not contain the "-plugin" at the end.
I'm aware of the usage of the tag "appendAssemblyId", however when I try to use it I always end up with a jar that contains much more that what's needed even if that is the only change in the configuration tag. I also tried using the "finalname" tag, but this one does not seem to change anything.
This is the pom.xml that I'm using:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>"groupId"</groupId>
<artifactId>"ProjectName"</artifactId>
<version>1.0-SNAPSHOT</version>
<name>"ProjectName"</name>
<description>"ProjectName"</description>
<repositories>
<repository>
<id>public</id>
<name>oXygen public artifacts</name>
<url>https://www.oxygenxml.com/maven</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>RepoId</id>
<name>RepoName</name>
<url>RepoURL</url>
</repository>
</repositories>
<dependencies>
...
</dependencies>
<distributionManagement>
<repository>
<id>Repoid</id>
<name>RepoName</name>
<url>RepoURL
</url>
</repository>
<snapshotRepository>
<id>RepoId</id>
<name>RepoName</name>
<url>RepoUrl
</url>
</snapshotRepository>
</distributionManagement>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>dd-MM-yyyy HH:mm</maven.build.timestamp.format>
</properties>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<configuration>
<archive>
<manifestEntries> <Build-Time>${maven.build.timestamp}</Build-Time></manifestEntries>
</archive>
<outputDirectory>${project.build.directory}/build</outputDirectory>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<!--Where i ussually add the AppendAssemblyId false -->
<archiveBaseDirectory>${project.basedir}</archiveBaseDirectory>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
<configuration>
<archive>
<manifestEntries> <Build-Time>${maven.build.timestamp}</Build-Time></manifestEntries>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>"MainClass".ContentManager</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef> <!--This is an intended extra jar we also need-->
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}</directory>
<includes>
<include>addon.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
And this is the Assembly.xml:
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>plugin</id>
<formats>
<format>jar</format>
</formats>
<fileSets>
<fileSet>
<directory>target/lib</directory>
<outputDirectory>lib</outputDirectory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
</fileSets>
<files>
<file>
<source>target/build/${project.build.finalName}.jar</source>
<outputDirectory>/lib</outputDirectory>
</file>
<!--This is an attempt at generating a jar without the '-plugin' in the target directory -->
<file>
<source>target/build/${project.build.finalName}.jar</source>
<outputDirectory>${basedir}/target/</outputDirectory>
</file>
<file>
<source>plugin.xml</source>
<outputDirectory>/</outputDirectory>
<filtered>true</filtered>
</file>
</files>
</assembly>
As mentioned, I tried to use the AppendAssemblyId false, but whenever I use it it also changes the contents of the jar, I could also be that I'm putting it in the wrong place.
Is there a way to create a jar that's and exact copy of the mentioned jar, but without the "-plugin" at the end? Or is there a way to take that string out of the jar that's already being created?
Thanks

Related

No error in netbeans ide but java.lang.ClassNotFoundException: org.netbeans.lib.awtextra.AbsoluteLayout ERROR when java -jar jarfilename.jar

the maven app is running with no error on netbeans ide and the clean and build are running also without errors , the dependencies i didnt mention are :(mongodb,mongodb driver,mysql,itext) i tried launch4j , the .exe file didnt open.
this is the POM file :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>billing-system</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<repositories>
<repository>
<id>unknown-jars-temp-repo</id>
<name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name>
<url>file:${project.basedir}/lib</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.netbeans.external</groupId>
<artifactId>AbsoluteLayout</artifactId>
<version>RELEASE120</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<itext.version>7.1.13</itext.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/libs
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>login</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
i tried creating a awtextra folder in lib/ and copy absolutelayout folder in it from external/ and it did not work .and this the command line error :
OneDrive\Desktop\billing-system\target>java -jar billing-system-1.0-SNAPSHOT.jar
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/netbeans/lib/awtextra/AbsoluteLayout
at login.initComponents(login.java:41)
at login.<init>(login.java:21)
Problem solved
1.installed maven
2.added configuration to java JAVA_HOME
3.added configuration to maven MAVEN_HOME
4.added plugin with goals to pom file
5.added built with dependencier to jar file
6.used launch4j for an exe file
my pom file :
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/libs
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>login</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>login</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>login</mainClass>
</configuration>
</plugin>
</plugins>
<defaultGoal>install</defaultGoal>
<!-- Source directory configuration -->
<sourceDirectory>src</sourceDirectory>
</build>

Effective POM is not equal to super POM + project POM?

This question asks what makes up the effective POM. The answer states that effective POM consists of:
Application POM.
Super POM.
settings.xml
Plugins bound to the lifecycle by default based on the packaging type chosen.
I created a minimal POM to observe the effective POM of this minimal POM. The files are as below:
Minimal POM:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>
Super POM:
<project>
<modelVersion>4.0.0</modelVersion>
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
<build>
<directory>${project.basedir}/target</directory>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
<pluginManagement>
<!-- NOTE: These plugins will be removed from future versions of the super POM -->
<!-- They are kept for the moment as they are very unlikely to conflict with lifecycle mappings (MNG-4453) -->
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<outputDirectory>${project.build.directory}/site</outputDirectory>
</reporting>
<profiles>
<!-- NOTE: The release profile will be removed from future versions of the super POM -->
<profile>
<id>release-profile</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<inherited>true</inherited>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<inherited>true</inherited>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<inherited>true</inherited>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Effective POM:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</pluginRepository>
</pluginRepositories>
<build>
<sourceDirectory>/Users/utku/Minimal_POM_Test/src/main/java</sourceDirectory>
<scriptSourceDirectory>/Users/utku/Minimal_POM_Test/src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>/Users/utku/Minimal_POM_Test/src/test/java</testSourceDirectory>
<outputDirectory>/Users/utku/Minimal_POM_Test/target/classes</outputDirectory>
<testOutputDirectory>/Users/utku/Minimal_POM_Test/target/test-classes</testOutputDirectory>
<resources>
<resource>
<directory>/Users/utku/Minimal_POM_Test/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>/Users/utku/Minimal_POM_Test/src/test/resources</directory>
</testResource>
</testResources>
<directory>/Users/utku/Minimal_POM_Test/target</directory>
<finalName>my-app-1</finalName>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>default-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>default-testResources</id>
<phase>process-test-resources</phase>
<goals>
<goal>testResources</goal>
</goals>
</execution>
<execution>
<id>default-resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<executions>
<execution>
<id>default-site</id>
<phase>site</phase>
<goals>
<goal>site</goal>
</goals>
<configuration>
<outputDirectory>/Users/utku/Minimal_POM_Test/target/site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
<execution>
<id>default-deploy</id>
<phase>site-deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<outputDirectory>/Users/utku/Minimal_POM_Test/target/site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
</executions>
<configuration>
<outputDirectory>/Users/utku/Minimal_POM_Test/target/site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<outputDirectory>/Users/utku/Minimal_POM_Test/target/site</outputDirectory>
</reporting>
</project>
However, observe the following:
<repositories> tag of the effective POM and the Super POM are not the same:
The order which elements of the <repositories> tag appear are different.
Effective POM is missing the <layout>default</layout> part.
Similar differences exist for other tags as well.
What is the reason for this? Two questions regarding this topic are:
From the linked question, I thought that effective POM is just a summation of the project POM and the Super POM. However the results show that it is not as simple as this. Does further processing goes into the effective POM?
If yes, which Maven plugins (or other tools) are used to create the effective POM?
The <repositories> tags of the effective POM and the Super POM are the same regarding their effective content. <layout>default is, no wonder, the default. The order of declarations usually is not relevant due to the declarative nature of a POM. (If it is it's mentioned in the documentation.)
See Maven: The Complete Reference, 3.2.1. The Super POM for further information.
See also the Maven Model Builder:
The effective model builder, with profile activation, inheritance, interpolation, ...
...
phase 1
...
parent resolution until super-pom
...

Generate several war for spring boot application

It seems that spring boot will repackage the package generated by maven package phase, and then repacke the war to make it executable.
Now I want to genrate multiple wars for different environments by a single maven command, I tried to use maven-assembly-plugin:
1 unzip the war generated by `spring-boot-maven` plugin to a directory
2 Assembly with the files in the directory, and add some other filtered resources
3 create the war
Check this post:generate multiple artifacts in maven
While it works, and I got multiple wars, but none of them can be executeable by java -jar xx.war. It seems that the classes are corrupted.
So I wonder if there is an alternative solution?
update my pom.xml:
<project>
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.1.RELEASE</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/as-common</source>
<source>src/main/as-server</source>
<source>src/main/as-app</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<!-- unzip the contents of the war(executeable) generated by spring-boot to a certain directory -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>extract_spring_war</id>
<phase>package</phase>
<configuration>
<target>
<echo message="extract war generated by spring-boot-maven-plugin"/>
<delete dir="${basedir}/target/${project.build.finalName}-spring" includeemptydirs="true"/>
<unzip src="${basedir}/target/${project.build.finalName}.war" dest="${basedir}/target/${project.build.finalName}-spring/"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>iterator-maven-plugin</artifactId>
<version>0.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>iterator</goal>
</goals>
<configuration>
<items>
<item>test</item>
<item>dep1</item>
<item>dep2</item>
</items>
<pluginExecutors>
<pluginExecutor>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
</plugin>
<goal>single</goal>
<configuration>
<archive>
<manifest>
<mainClass>org.springframework.boot.loader.WarLauncher</mainClass>
</manifest>
</archive>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</pluginExecutor>
</pluginExecutors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
assmbly.xml:
<assembly>
<id>${item}</id>
<formats>
<format>war</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<!-- file from the unpacked contents -->
<fileSet>
<directory>target/${project.build.finalName}-spring</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**/*</include>
</includes>
<filtered>true</filtered>
</fileSet>
<!-- add environment awared resources -->
<fileSet>
<outputDirectory>/WEB-INF/classes</outputDirectory>
<directory>${basedir}/src/main/custom/</directory>
<includes>
<include>${item}.properties</include>
</includes>
</fileSet>
</fileSets>
</assembly>
Update:
At first I got the error:
No main class detected
Then I add the following for maven-assembly-plugin,
<archive>
<manifest>
<mainClass>org.springframework.boot.loader.WarLauncher</mainClass>
</manifest>
</archive>
After that I repackage the wars, and I got error when I ran:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.ClassFormatError: Incompatible magic value 4022320623 in class file org/springframework/boot/loader/WarLauncher
The class files are being corrupted when you're repackaging the war file. I suspect that's because you're filtering all of the files:
<fileSet>
<directory>target/${project.build.finalName}-spring</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**/*</include>
</includes>
<filtered>true</filtered>
</fileSet>
You don't want to filter binary files as they may happen to contain data that looks like a ${} placeholder. You should update the assembly to avoid applying the filtering to class files. The simplest way to do that would be to disable filtering entirely:
<fileSet>
<directory>target/${project.build.finalName}-spring</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**/*</include>
</includes>
<filtered>false</filtered>
</fileSet>
If you need filtering for text files, you should use two fileSets. One that includes the binary files and disables filtering, and one that includes the text files and enables filtering.

How to deploy only zip artifacts in maven

I have done some zip packaging in maven using the below descriptor and pom file. But in maven by default it created both jar and zip in target folder. Now i want to deploy only zip contents where i am using deploy:deploy-file plugin. but it is not deploying instead it is showing error. Not sure what is wrong with tag and how it should be resolved.
Pom file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wyndhamvo.prototype.dbscripts</groupId>
<artifactId>DB_SCRIPTS</artifactId>
<version>2.0.0.1</version>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptor>src/assembly/descriptor.xml</descriptor>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<distributionManagement>
<snapshotRepository>
<id>wvoNexus</id>
<file>${project.artifactId}-${project.version}.zip</file>
<url>http://nexus.corproot.com/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>wvoNexus</id>
<file>${project.artifactId}-${project.version}.zip</file>
<url>http://nexus.corproot.com/nexus/content/repositories/releases/</url>
</repository>
</distributionManagement>
</project>
assembly plugin descriptor file:
<assembly>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
<outputDirectory>DB_Files</outputDirectory>
</fileSet>
</fileSets>
</assembly>
Command Executed:
mvn -X clean package deploy:deploy-file
Error:
[ERROR] Malformed POM C:\Divakar\MavenPrototype\DB_Maven_Test\dev\pom.xml: Unrecognised tag: 'file' (position: START_TAG seen ...<id>wvoNexus</id>\r\n\t\t\t<file>... #37:10) # C:\Divakar\MavenPrototype\DB_Maven_Test\dev\pom.xml, line 37, column 10
First you have to fix you error in distributionManagement area like this:
<distributionManagement>
<snapshotRepository>
<id>wvoNexus</id>
<url>http://nexus.corproot.com/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>wvoNexus</id>
<url>http://nexus.corproot.com/nexus/content/repositories/releases/</url>
</repository>
</distributionManagement>
If you fixed that you can simple deploy the files to your nexus via:
mvn clean deploy
If you don't like having a jar deployed as well you need to change the packing type in your pom like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wyndhamvo.prototype.dbscripts</groupId>
<artifactId>DB_SCRIPTS</artifactId>
<version>2.0.0.1</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptor>src/assembly/descriptor.xml</descriptor>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Furthermore i recommend to define the versions of your used plugins like this:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<descriptor>src/assembly/descriptor.xml</descriptor>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>some file</file>
<type>extension of your file </type>
<classifier>optional</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
You made a mistake: the <file/> element is not a part of <snapshotRepository/>, it's an config item of deploy plugin! you should deploy your zip file as following:
mvn -X clean package deploy:deploy-file -Dfile=/path/to/your-artifact-1.0.zip

POM How to include properties file inside a jar. The pom also creates a war

I developed a pom that creates a war file and a jar file. How do I insert a properties file into the JAR(not the war)? The file I need to insert into the JAR is located in the directory, properties/its, within the project. You can see in the pom below in the maven-resources-plugin where I have attempted to add the properties file in the package phase with the associated jar goal. Then I tried again in the maven-jar-plugin, using the process-resources phase and jar goal.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xxx.xx.Lookup</groupId>
<artifactId>lookup</artifactId>
<packaging>war</packaging>
<version>${env.ENVIRONMENT}</version>
<name>elookup</name>
<url>http://maven.apache.org</url>
<description>Lookup</description>
<dependencies>
<dependency>
<groupId>xxx.xxx.utils</groupId>
<artifactId>Utils</artifactId>
<version>${env.ENVIRONMENT}</version>
</dependency>
</dependencies>
<parent>
<groupId>xxx.xx.parent_project</groupId>
<artifactId>xxxProject</artifactId>
<version>master-version-1.0</version>
<relativePath>../Project/pom.xml</relativePath>
</parent>
<profiles>
<profile>
<id>development</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<env>${env.ENVIRONMENT}</env>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<env>${env.ENVIRONMENT}</env>
</properties>
</profile>
<profile>
<id>production</id>
<properties>
<env>${env.ENVIRONMENT}</env>
</properties>
</profile>
</profiles>
<build>
<finalName>${project.name}-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>properties/its</directory>
<!-- override the destination directory for this resource -->
<targetPath>properties/its</targetPath>
</resource>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>src/main/webapp/META-INF</directory>
<!-- override the destination directory for this resource -->
<targetPath>META-INF</targetPath>
<filtering>true</filtering>
</resource>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>src/main/webapp/WEB-INF</directory>
<!-- override the destination directory for this resource -->
<targetPath>WEB-INF</targetPath>
<filtering>true</filtering>
</resource>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>images</directory>
<!-- override the destination directory for this resource -->
<targetPath>images</targetPath>
</resource>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>style</directory>
<!-- override the destination directory for this resource -->
<targetPath>style</targetPath>
</resource>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>html</directory>
<!-- override the destination directory for this resource -->
<targetPath>.</targetPath>
</resource>
</webResources>
<packagingExcludes>WEB-INF/lib/stax-api-1.0.1.jar</packagingExcludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<downloadSources>true</downloadSources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
<configuration>
<!-- specify UTF-8, ISO-8859-1 or any other file encoding -->
<encoding>UTF-8</encoding>
<executions>
<execution>
<id>make-a-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<resources>
<resource>
<directory>properties/its</directory>
<includes>
<include>**/*</include>
</includes>
<!-- <targetPath>.</targetPath> -->
</resource>
</resources>
</execution>
</executions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>make-a-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</execution>
<execution>
<id>jar-resources</id>
<phase>process-resources</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>properties/its</directory>
<targetPath>.</targetPath>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptor>src/main/assembly/jar.xml</descriptor>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<filters>
<filter>../../Project/workspace/src/main/filters/eddb.${env.ENVIRONMENT}.properties</filter>
</filters>
</build>
</project>
How do I insert a properties file into the JAR(not the war)? The file I need to insert into the JAR is located in the directory, properties/its, within the project.
Before package the jar use maven-antrun-plugin to copy your file into the same directory the maven-jar-plugin uses as source directory for jar-ing.

Resources