Maven not including manifest attributes for LWJGL install - java

I am trying to setup a LWJGL project using Maven. I am using the example "getting started" source code from the official website.
This includes a few lines accessing LWJGL's manifest attributes, such as a simple version check:
System.out.println("Hello LWJGL " + Version.getVersion() + "!");
This runs without any problems in the Eclipse environment (of course after having built the project with Maven), but when running clean install and then running **-jar-with-dependencies.jar through cmd, the following exception get's thrown:
java.lang.NullPointerException
at org.lwjgl.system.APIUtil.apiGetManifestValue(APIUtil.java:97)
at org.lwjgl.Version.getVersion(Version.java:33)
at HelloWorld.run(HelloWorld.java:43)
at HelloWorld.main(HelloWorld.java:130)
This is because the Manifest object created by APIUtil does not include any attributes - but only in the built version by Maven.
Why is this? Is my pom.xml buggy, or is LWJGL 3.0.0 just not ready for this?
This is my pom.xml:
<properties>
<mainClass>HelloWorld</mainClass>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<finalName>${project.artifactId}-${project.version}.jar</finalName>
</properties>
<dependencies>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-platform</artifactId>
<version>3.0.0</version>
<classifier>natives-windows</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-platform</artifactId>
<version>3.0.0</version>
<classifier>natives-linux</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-platform</artifactId>
<version>3.0.0</version>
<classifier>natives-osx</classifier>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>

This errors happens because LWJGL 3.0.0 is looking inside the Manifest a property called "Implementation-Version", but when you made the uber-jar, this property was not set.
This is not really an issue with how you made the uber-jar: the Manifest that was created by maven-assembly-plugin looks like:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: Me
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_102
Main-Class: HelloWorld
You can see it inside META-INF/MANIFEST.MF of the jar-with-dependencies. This file does not have a "Implementation-Version" property. This is normal: when this executable JAR was created, all the MANIFEST of all dependencies were (rightfully) ignored, only to generate one containing the "Main-Class", just so that the JAR is executable.
The uber-jar cannot contain what is inside each of the dependencies manifest. For example, "Implementation-Version" is a property that is present in the manifest of multiple libraries, so which one should it keep? (There can be only one Manifest at the end, in the uber-jar). So the issue comes up because we're making an executable JAR, which can only have 1 Manifest so it cannot aggregate all the properties inside each of the dependencies manifest.
There are 2 possible solutions:
Ignore it. After all, this is not really an error.
Don't make an executable jar by embedding all the dependencies inside a single JAR, but create a ZIP assembly with each dependencies inside a lib folder: this way, each Manifest will be kept. This is done by telling the maven-jar-plugin to add a Manifest entry for the main class with the addition of the classpath and creating a custom assembly descriptor.
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<mainClass>${mainClass}</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>/path/to/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
where /path/to/assembly.xml is the path to the assembly descriptor, relative to the location of the POM, being:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>dist</id>
<formats>
<format>zip</format>
</formats>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
</dependencySet>
</dependencySets>
</assembly>
With such a configuration, running mvn clean install will create a ZIP file artifactId-version-dist.zip. Unpacking it and running (replacing <finalName> with the finalName of your JAR)
java -jar lib\<finalName>.jar
will print the version without any issues.

Related

Force Maven to Pick up Dependencies in Project Directory

I am using Maven to manage my dependencies and am trying to pull a few, proprietary, jar files from my project directory. (Yes, I know, I'm a crazy idiot who doesn't get the purpose of Maven and should never do this.) On compilation, I get the typical warnings about pointing to files in my project directory. However, the specified jar files are not placed in my .m2 directory, and thus, the project does not compile as dependencies are missing.
In pom.xml:
<dependency>
<groupId>org.sample</groupId>
<artifactId>sample</artifactId>
<scope>system</scope>
<version>2.0.3</version>
<systemPath>${project.basedir}/WebContent/WEB-INF/lib/my_file.jar</systemPath>
<type>jar</type
<optional>true</optional>
</dependency>
Question is, am I declaring my groupId and artifactId correctly? Is there a way to force Maven to use several, random, jar files in my project directory?
Thanks for the help.
You have to add the jar in your classpath as well for mvn to pickup your system dependencies.
<Class-Path>libs/my_file.jar</Class-Path>
Plugin Config
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven.jar.plugin.version}</version>
<configuration>
<archive>
<manifestEntries>
<Build-Jdk>${jdk.version}</Build-Jdk>
<Implementation-Title>${project.name}</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Specification-Title>${project.name} Library</Specification-Title>
<Specification-Version>${project.version}</Specification-Version>
<Class-Path>libs/my_file.jar</Class-Path>
</manifestEntries>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.app.MainClass</mainClass>
<classpathPrefix>libs/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<repositories>
<repository>
<id>my-local-repo</id>
<url>file:///${project.parent.basedir}/dependencies/lib</url>
</repository>
</repositories>
regardless you can add maven plugin to copy the depdencies from m2
to the same directory with this plugin
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<copyPom>true</copyPom>
<!-- <addParentPoms>true</addParentPoms>-->
<outputDirectory>${project.basedir}/../dependencies/lib/</outputDirectory>
<!-- <useSubDirectoryPerArtifact>true</useSubDirectoryPerArtifact>-->
<useRepositoryLayout>true</useRepositoryLayout>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<descriptors>
<descriptor>repository.xml</descriptor>
</descriptors>
</configuration>
</plugin>

Optaplanner - NullPointerException when creating jar file

My program works fine from my IDE (IntelliJ) but for some reason, when I try to create a jar file I get following error when I run the program from a terminal:
Exception in thread "main" java.lang.NullPointerException at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildDroolsScoreDirectorFactory(ScoreDirectorFactoryConfig.java:461)
org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildScoreDirectorFactory(ScoreDirectorFactoryConfig.java:331)
org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:220)
org.optaplanner.core.impl.solver.AbstractSolverFactory.buildSolver(AbstractSolverFactory.java:57)
org.optaplanner.EmployeeRoster.main(EmployeeRoster.java:31)
This is my line 31 in EmployeeRoster:
Solver solver = SolverFactory.createFromXmlResource(SOLVER_CONFIG_XML).buildSolver();
SOLVER_CONFIG_XML is a String containing my path for my XML solver-config,
it looks like this
<?xml version="1.0" encoding="UTF-8"?>
<solver>
<solutionClass>org.optaplanner.solver.Roster</solutionClass>
<entityClass>org.optaplanner.domain.Assignment</entityClass>
<scoreDirectorFactory>
<scoreDrl>org/optaplanner/solver/employeeShiftsScoreRules.drl</scoreDrl>
</scoreDirectorFactory>
<localSearch>
<termination>
<secondsSpentLimit>5</secondsSpentLimit>
<bestScoreLimit>0hard/0medium/0soft</bestScoreLimit>
</termination>
<!--<termination>
<unimprovedStepCountLimit>5</unimprovedStepCountLimit>
</termination>-->
<acceptor>
<entityTabuSize>7</entityTabuSize>
</acceptor>
<forager>
<acceptedCountLimit>1000</acceptedCountLimit>
</forager>
</localSearch>
</solver>
Also here's my pom.xml file if that should be relevant:
<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>org.btrg.dfb</groupId>
<artifactId>optaplanner</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.optaplanner</groupId>
<artifactId>optaplanner-core</artifactId>
<version>7.3.0.Final</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.8</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>com.jolira</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>org.avalin.optaplanner.EmployeeRoster</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.jolira</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
What might I be doing wrong?
For me, the issue had to deal with how I wanted to run the jar (java -jar), and consequently how I built the jar. The NullPointerException arose when I upgraded to optaplanner-core/7.4.1 from 6.4.0. This issue was not present back when I was still using 6.4.0.
Exception:
java.lang.NullPointerException
at org.kie.internal.io.ResourceFactory.newByteArrayResource(ResourceFactory.java:66)
at org.drools.compiler.kie.builder.impl.AbstractKieModule.getResource(AbstractKieModule.java:299)
at org.drools.compiler.kie.builder.impl.AbstractKieModule.addResourceToCompiler(AbstractKieModule.java:264)
at org.drools.compiler.kie.builder.impl.AbstractKieModule.addResourceToCompiler(AbstractKieModule.java:259)
at org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:243)
at org.drools.compiler.kie.builder.impl.AbstractKieProject.verify(AbstractKieProject.java:74)
at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildKieProject(KieBuilderImpl.java:250)
at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:218)
at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:176)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildDroolsScoreDirectorFactory(ScoreDirectorFactoryConfig.java:503)
The following is a temporary workaround I did to resolve the NullPointerException and just get the application to run.
Use IntelliJ's gradle to build one big jar with all dependencies.
Unzip the jar, for example, to unzippedJar/ directory.
Modify unzippedJar/META-INF/kie.conf
Rejar the files.
Run the jar with java.
Step 1. Building the jar
dependencies {
...
compile group: 'org.optaplanner', name: 'optaplanner-core', version:'7.4.1.Final'
compile group: 'org.optaplanner', name: 'optaplanner-benchmark', version:'7.4.1.Final'
...
}
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Self contained jar with all dependencies',
'Implementation-Version': version,
'Main-Class': 'path.to.class.with.main.method'
}
baseName = 'fatJar'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
Step 2. Unzip
unzip fatJar.jar -d unzippedJar/
Step 3. Modify kie.conf
The "fatJar" task flattened the dependencies - duplicate file names are allowed in the jar. This resulted in four unzippedJar/META-INF/kie.conf files, only one of which was used. Regardless of whichever kie.conf file was used, this was my final kie.conf.
org.kie.api.internal.assembler.KieAssemblers = +org.optaplanner.core.impl.solver.kie.KieSolverAssemblerService
org.kie.api.internal.assembler.KieAssemblers = org.kie.internal.services.KieAssemblersImpl
org.kie.api.internal.runtime.KieRuntimes = org.kie.internal.services.KieRuntimesImpl
org.kie.api.internal.weaver.KieWeavers = org.kie.internal.services.KieWeaversImpl
org.kie.api.internal.runtime.beliefs.KieBeliefs = org.kie.internal.services.KieBeliefsImpl
org.kie.api.io.KieResources = org.drools.core.io.impl.ResourceFactoryServiceImpl
org.kie.api.marshalling.KieMarshallers = org.drools.core.marshalling.impl.MarshallerProviderImpl
org.kie.api.concurrent.KieExecutors = org.drools.core.concurrent.ExecutorProviderImpl
org.kie.api.KieServices = org.drools.compiler.kie.builder.impl.KieServicesImpl
org.kie.internal.builder.KnowledgeBuilderFactoryService = org.drools.compiler.builder.impl.KnowledgeBuilderFactoryServiceImpl
Step 4. Rejar
For whatever reason, specifying the MANIFEST.MF file did nothing for me, hence I left it out.
jar cf rejard.jar .
Step 5. Run the jar
java -cp rejard.jar path.to.class.with.main.method
Following #Arturo W's answer, I can suggest another fix using maven's
assembly plugin to
make a fat jar.
As stated in the documentation:
"If two or more elements (e.g., file, fileSet) select different sources for
the same file for archiving, only one of the source files will be archived.
[...] The order of the phases is as follows: 1) FileItem 2) FileSets
3) ModuleSet 4) DependencySet and 5) Repository elements."
META-INF/kie.conf is provided in org.optaplanner.core's archive, hence
maven packages optaplanner's version over the custom one define in your
repository.
To include it, we exclude all META-INF/kie.conf files during unpackaging
and manually copy our version using the <file></file>
option in a custom descriptor file.
Here's how we do it:
pom.xml
<?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">
<!-- ... -->
<build>
<plugins>
<!-- ... -->
<!-- fat jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptors>
<descriptor>src/assembly/distribution.xml</descriptor>
</descriptors>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.veryseriouscompany.veryseriousproject.app.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- ... -->
To fix the inclusion of kie.conf, we'll have to write a custom descriptor,
defined in src/assembly/distribution.xml. We start from a predefined
descriptor:
jar-with-dependencies.
That's a good starting point.
src/assembly/distribution.xml
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>epigno-jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
<!-- Exclude all META-INF/kie.conf during unpacking -->
<unpackOptions>
<excludes>
<exclude>META-INF/kie.conf</exclude>
</excludes>
</unpackOptions>
</dependencySet>
</dependencySets>
<files>
<file>
<!-- Manually copy your custom kie configuration file from your repository. -->
<!-- Please replace this path by whatever path is relevant for your project. -->
<source>src/main/resources/META-INF/kie.conf</source>
<outputDirectory>META-INF</outputDirectory>
</file>
</files>
</assembly>
When you are finished, run
mvn package
Hopefully, this will package the correct kie.conf in your fat jar!

How to add extra custom classpath entry into a spring boot run via maven?

How do I add an extra classpath entry into my spring boot run from maven?
I think I need to add something like this to my pom.xml:
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>C:/resources</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
However, I do not know what plugin is applicable.
I assume what you want is to add your additional resources/configuration files to the classpath in the generated executable jar of Spring Boot. The only off the shelf solution I have found was to use the maven-jar-plugin in addition to the spring-boot-maven-plugin to add the classpath to the manifest, for example:
<!-- setup jar manifest to executable with dependencies -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.3.RELEASE</version>
<configuration>
<fork>true</fork>
<mainClass>Application</mainClass>
<classifier>executable</classifier>
<layout>JAR</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- add configuration to manifest -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifestEntries>
<Class-Path>conf/</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
Note that the class-path will be relative to the generated executable JAR file.
Wouldn't:
java -cp <path to classpath entry> -jar <path to program.jar>
work for you?

.jar with Maven and Eclipse

I have a java project done with Eclipse and Maven with this estructure folder:
enter image description here
Ok, when i make a Maven install to create the .jar take this structure folder:
enter image description here
So that the hierarchy is not the same and links to the images and css do not work.
I show you the code of pom.xml
enter code here
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.wepall
palle
0.4.0
com.thoughtworks.xstream
xstream
com.thoughtworks.xstream
xstream
1.4.9
palle
<!-- download source code in Eclipse, best practice -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
</configuration>
</plugin>
<!-- Set a compiler level -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<!-- Maven Assembly Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>com.wepall.palle.MainApp</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Any ideas?
thanks a lot!!
Best regards
You should add a build section to your pom.xml:
<build>
<directory>${basedir}/target</directory>
<resources>
<resource>
<targetPath>${basedir}/target/resources</targetPath>
<directory>${basedir}/src/main/resources</directory>
</resource>
</resources>
</build>
Further Reference:
POM Reference (Build Section)
I think that you should create a war instead of a jar, because you are talking about css and images and jars should not contains that kind of files (see jar vs war).
In maven you only need to change the <packaging> of the project inside the POM.

Import only one dependency in Java Maven project [duplicate]

This question already has an answer here:
How can I package a jar with Maven and include some dependencies in WEB-INF/lib?
(1 answer)
Closed 6 years ago.
I need to make a jar out of my Java project, and I need it to also contain the class files of one of the dependencies, but not all of them. I've used maven-assembly-plugin which includes all the files and creates a huge jar, but I only need
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.10.45</version>
</dependency>
I've also tried the maven shade plugin but with no result: I somehow end up including all the dependencies or excluding all of them
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>org.apache.spark:*</exclude>
<exclude>com.google.code.gson:*</exclude>
<exclude>edu.stanford.nlp:*</exclude>
<exclude>log4j:*</exclude>
<exclude>com.optimaize.languagedetector:*</exclude>
<exclude>info.debatty:*</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
Use 'provided' for the scope tag of the dependencies that you don't want to include in the final jar file.
<dependency>
<groupId>GROUP_ID</groupId>
<artifactId>ARTIFACT_ID</artifactId>
<version>VERSION</version>
<scope>provided</scope>
</dependency>
And use maven-assembly-plugin to build the jar
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>MAIN_CLASS</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

Categories