0

I'm trying to create an executable jar, which contains my external jar. I have already read the articles mentioned below, but in my case, with this external jar I have to use the followings: #MYgroup# #myArtifact# #VERSION# system ${project.basedir}/lib/#myjar#.jar Because of the systemPath, I have to use scope system, and that's why, my jar won't be inlcuded in my final executable jar. When I try to run my jar, it will end up with NoClassDefFoundError to my external jar. Could you help my, how to include my external jar into my final runnable jar.

Here is my current plugins:
 <!-- compiler plugin -->
            <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>

            <!-- Make this jar executable -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>#MYMAINCLASS#</mainClass>
                            <classpathPrefix>lib/</classpathPrefix>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

            <!-- Copy project dependency , can be used when we have repository.-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.5.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>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Thanks you answer in advance!

http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven
https://www.mkyong.com/maven/create-a-fat-jar-file-maven-assembly-plugin/
hunszab
  • 29
  • 4

1 Answers1

0

install your external jar manually to your repository, and then use the jar with default scope, and that would be simplest solution.

mvn install:install-file -Dfile=<path-to-file> \
                         -DgroupId=<myGroup> \
                         -DartifactId=<myArtifactId> \
                         -Dversion=<myVersion> \
                         -Dpackaging=<myPackaging> 

And you can also refer possible other options here

Community
  • 1
  • 1
kuhajeyan
  • 10,727
  • 10
  • 46
  • 71