I have a Maven project which generates a jar file and copies all dependencies to target/lib
folder. I want to execute this project on client's machine (windows). So, I copied myproject.jar
to C:\xyz
folder and all dependencies to C:\xyz\lib
folder. How do I execute this project from client's command prompt?
I tried to use java -cp lib\*.jar -jar myproject.jar
from C:\xyz
folder but it throws following error.
Exception in thread "main" java.lang.NoClassDefFoundError: lib\commons-codec-1/3/jar
Caused by: java.lang.ClassNotFoundException: lib\commons-codec-1.3.jar
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: lib\commons-codec-1.3.jar. Program will exit.
I think if I specify all dependencies in classpath (like java -cp lib\dep1.jar;dep2.jar
), it will get rid of the problem but I don't want to do this as I have 40 libraries already and it might grow in future releases. Is there a better way to do this?