0

When i run my jar file an it comes during runtime to access a class from a dependency (which is included by the maven-addjars-plugin), i get a java.lang.NoClassDefFoundError error.

Note: i also include some jars normaly by just specifying the dependency in the POM.xml, i only use the addjar plugin for the custom jars which i only have locally.

Part of POM.XML (If you need more information, pls tell)

<build>
    <defaultGoal>install</defaultGoal>
    <directory>${basedir}/target</directory>
    <finalName>${project.artifactId}-${project.version}</finalName>
    <pluginManagement>
    <plugins>
        <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>Swapper</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.googlecode.addjars-maven-plugin</groupId>
            <artifactId>addjars-maven-plugin</artifactId>
            <version>1.0.5</version>
            <executions>
                <execution>
                    <goals>
                        <goal>add-jars</goal>
                    </goals>
                    <configuration>
                        <resources>
                            <resource>
                                <directory>${basedir}/my-repo</directory>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    </pluginManagement>
</build>
....
<dependency>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-codegen</artifactId>
    <version>2.1.4-SNAPSHOT</version>
</dependency>

The swagger lib was copied into "target/com.googlecode.addjars-maven-plugin" folder which idk is the right place to have those libs since i dont see the libraries that are downloaded from maven repository. But the class is not found during runtime.

UPDATE: When running with mvn exec instead of java -jar the program runs.

Anyone has an idea what i did wrong?

Gobliins
  • 3,848
  • 16
  • 67
  • 122
  • Try to add Class-Path element in your Manifest file. you may need true my-repo/ – Bhushan Oct 19 '15 at 13:44
  • Hi i tried it but it strangely resulted in, throwing the same error even sooner, when accesing a jar which i included outside the add jar plugin. – Gobliins Oct 19 '15 at 13:50
  • Instead of ${basedir}/my-repo, try ${project.build.directory}/my-repo, as your compile jar will go inside target folder and from their it will run. – Bhushan Oct 19 '15 at 13:56
  • its true and i did it, but still the maven-dependencies are not found... – Gobliins Oct 19 '15 at 14:04
  • Ok i found a workaround with Duncans answer from https://stackoverflow.com/questions/97640/force-maven2-to-copy-dependencies-into-target-lib – Gobliins Oct 19 '15 at 14:43
  • If you have jars locally than the best solution is to start using a repository manager and install the jar there. Afterwards you can use it as a default dependency which makes life easier. – khmarbaise Oct 20 '15 at 06:51

0 Answers0