4

I am writing Spring app and I have two external jars there. It works in IDE, but when I building the executable jar with maven it fails with error java.lang.NoClassDefFoundError: to my external jars. How can I solve this? My dependency in pom file is:

<dependency>
            <groupId>com.myapp.myappawsprovider</groupId>
            <artifactId>MyAppProvider</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>/Users/Projects/Java/MyApp/MyAppProvider/target/MyAppProvider Provider-1.0.0.jar</systemPath>
        </dependency>

I build it just with men package.

halfer
  • 19,824
  • 17
  • 99
  • 186
user3742622
  • 1,037
  • 3
  • 22
  • 40
  • You can refer to this: [How to add local jar files in maven project?](http://stackoverflow.com/a/4955695/2201637) – Jose-Rdz Nov 27 '15 at 22:34

3 Answers3

6

If your external jars are not present in the central maven repo, you can always add them to your local maven repo with below command

mvn install:install-file -DlocalRepositoryPath=[path of local maven repo] -DcreateChecksum=true -Dpackaging=jar -Dfile=[jar file path] -DgroupId=[xxx] -DartifactId=[yyy] -Dversion=[zzz]

You can then add proper dependencies for these external jars in your pom.xml.

Hope this helps

R Sawant
  • 241
  • 1
  • 8
1

Add the jar to maven local repository first. mvn install:install-file -Dfile="path of jar" -DgroupId="com.external.jar" -DartifactId="externalJar" -Dversion="version of your jar" -Dpackaging=jarIn pom.xml of your project add the dependency - <dependency> <groupId>com.external.jar</groupid> <artifactId>externalJar</artifactId> <version>version of your jar</version> </dependency> Reference

AKASH KHATRI
  • 69
  • 1
  • 3
1

Add the maven-assembly-plugin with jar-with-dependencies descriptorRef as specified below in your pom.xml <buid><plugins>...</plugins></build>section. It creates the uber jar with all required dependencies. See the configuration section here

<build>
   <plugins> 
       <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
    </build>

You can also use the maven-shade-plugin as described here.

Community
  • 1
  • 1
Omkar Puttagunta
  • 4,036
  • 3
  • 22
  • 35