I'm on a project working with openrdf, and I require the shade plugin to transform my service entries. I would like to build a war and a jar simultaneously, as both usages are possible. However, I cannot get the shade plugin to produce a shaded jar and a shaded war at the same time - shade only invokes on the package type defined in the properties, and binding e.g. the jar plugin to the package phase in order to create a jar next to the war results in an unshaded jar. How can I create both a shaded jar and a shaded war at the same time?
Asked
Active
Viewed 6,385 times
7
-
Possible duplicate of [What is the maven-shade-plugin used for, and why would you want to relocate java packages?](http://stackoverflow.com/questions/13620281/what-is-the-maven-shade-plugin-used-for-and-why-would-you-want-to-relocate-java) – javapapo Jan 16 '16 at 17:48
1 Answers
13
If by "shaded war" you mean just the regular war with all dependencies packed into WEB-INF/lib
, then you might just use maven-war-plugin
separately and use jar
as packaging type. This way shade plugin will work correctly. And .war
will be built by plugin.
Below is pom.xml. And here is working example.
<?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>so.test</groupId>
<artifactId>stackoverflow-test2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${project.build.finalName}-fatjar</finalName>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.14.9</version>
</dependency>
</dependencies>
</project>

Gabriel Belingueres
- 2,945
- 1
- 24
- 32

Dzmitry Paulenka
- 1,879
- 12
- 14
-
I have the same configuration. Locally i indeed obtain WAR + shadded JAR when i run mvn package, but for some reason the WAR is not deployed. Should the WAR be somehow explicitely declared to get deployed? – Julien Berthoud Dec 17 '21 at 08:39