Answer the question
In order to leave comments, you need to log in
How to build jar with external libraries folder in IDEA?
Hello.
Moved from Eclipse to IDEA.
I have my own home project. In Eclipse, I created jar using standard tools.
But it doesn't work in IDEA. Although I tried all the options found on the Internet.
You need to build the jar, and put the external jar libraries in the lib folder.
Create jar+lib works, but my jar doesn't see external jars.
Is there a working example on the Internet, or who has their own example - please tell me.
Both methods are of interest: using IDEA and using maven.
Answer the question
In order to leave comments, you need to log in
I'll try to answer in the maven part.
In my project I place libraries inside jar using Apache Maven Shade Plugin
https://maven.apache.org/plugins/maven-shade-plugin/
In pom.xml it looks like this:
<!-- Maven Shade Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<!-- add Main-Class to manifest file -->
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>JCheck.App</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
dunbox , thanks, but I've already tried that, but the list of libraries doesn't even get into the manifest.
Here is this part of my pom:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>mmmmm.sssssss.main.Main</mainClass>
<packageName>mmmmm.sssssss.main</packageName>
<classpathPrefix>lib/</classpathPrefix>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
<scope>system</scope>
<systemPath>${basedir}/lib/commons-codec-1.10.jar</systemPath>
</dependency>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question