Search code examples
javaspringmavenjar

Maven: How to include my external jar into build executable jar


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.


Solution

  • 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