Mobile Technologies Mobile Computing . 1 year ago

Including all the jars in a directory within the Java classpath

Including all the jars in a directory within the Java classpath

2 views   1   0 likes   0 shares Tuteehub forum manpreet 1 answers
_x000D_ _x000D_ Is there a way to include all the jar files within a directory in the classpath? I'm trying java -classpath lib/*.jar:. my.package.Program and it is not able to find class files that are certainly in those jars. Do I need to add each jar file to the classpath separately?
tuteehub_quiz
Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

profilepic.png

Tuteehub forum answer Answers (1)


profilepic.png
manpreet Tuteehub forum best answer Best Answer 1 year ago
_x000D_ I am trying to run Java file either as jar or as classes in Ubuntu. I failed in both options. The following exception is its output. Download link: https://upload.cat/f694139f88c663b1 java org.statmetrics.Statmetric or java -cp /home/elias/statmetrics/statmetrics.jar:. org.statmetrics.Statmetrics or java -classpath "/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/*" -jar /home/elias/statmeics/statmetrics.jar org.statmetrics.Statmetrics Exception in thread "Thread-0" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/adapters/XmlAdapter at java.base/java.lang.ClassLoader.defineClass1(Native Method) at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016) at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174) at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:802) at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:700) at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:623) at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) at org.statmetrics.c.a(Unknown Source) at org.statmetrics.dw.a(Unknown Source) at org.statmetrics.dx.run(Unknown Source) Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.adapters.XmlAdapter at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ... 12 more I found the answer: My stupidity. First step: You must set the corresponding Java: I had Java 11 but I set as Java lib path the 8th version! - You can do set the Java version from here: sudo update-alternatives --config java 2nd step: Then run the following command, by changing path and file names to your corresponding path and files: java -classpath "/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/*" -jar /home/elias/statmetrics/statmetrics.jar org.statmetrics.Statmetrics It was run succesfully!
2 views   0 shares
Related Tags

AskAnything Ask Anything

Ask Me Anything

ask me anything tuteehub

Hello! How can I assist you today?
Whether you have questions, need information, or just want to chat, feel free to let me know