my maven project needs some local dependencies and i put them in the lib directory, my project structure is as follows(test_local_jar is my project name)
test_local_jar ->lib ->json-20210307.jar
->commons-codec-1.10.jar ...
->src...->org.example->Main ->target ->pom.xml
I tried to package my maven project using maven shade plugin (i also want to learn about some common maven package plugins ) and i hope to use the project.jar in another PC without installing the jdk, dependencies and so on. I can include other dependencies into my project by typing mvn clean package in the terminal, but i can’t include json-20210307.jar(other versions can’t be included, either). Error message is as follows: Exception in thread “main” java.lang.NoClassDefFoundError: org/json/JSONObject at org.example.Main.main(Main.java:9) Caused by: java.lang.ClassNotFoundException: org.json.JSONObject at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) …
my pom.xml is as follows, where i use maven shade plugin and set the mainClass, location of my dependencies and so on. All dependencies in my project are local dependencies. i want to find out the way to include json-20210307.jar(or other version) into my jar and understand why i can’t include json.jar into my project jar. In fact, i dont know the meaning of memu structure **/*.jar, i dont know what’s the ** meaning. Besides, i want to learn more about some other maven package plugins which can be used to package dependencies.
<dependencies>
<dependency>
<groupId>test_local_jar</groupId>
<artifactId>commons-codec-1.10</artifactId>
<version>1.10</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/commons-codec-1.10.jar</systemPath>
</dependency>
<dependency>
<groupId>test_local_jar</groupId>
<artifactId>httpclient</artifactId>
<version>4.4.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/httpclient-4.4.1.jar</systemPath>
</dependency>
<dependency>
<groupId>test_local_jar</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/httpcore-4.4.1.jar</systemPath>
</dependency>
<dependency>
<groupId>test_local_jar</groupId>
<artifactId>json</artifactId>
<version>20210307</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/json-20210307.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution> <!-- <id>make-assembly</id>-->
<phase>package</phase>
<goals> <goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <manifestEntries>
<Main-Class> org.example.Main </Main-Class>
</manifestEntries>
</transformer>
</transformers>
<finalName>test-jar-with-dependencies</finalName>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<targetPath>lib/</targetPath>
<directory>lib/</directory>
<includes> <include>**/*.jar</include>
</includes>
</resource>
</resources>
</build>
my jar structure is as follows, i can find the json.jar in the lib directory, however, when i use java -jar …..jar in the cmd, error message appears(see details of my problems)
test-jar-with-dependencies.jar ->lib ->…other jars
->json-20210307.jar ->META-INF ->org->example->Main.class
user25051949 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.