Java - ClassNotFoundException: java.net.http.HttpClient - java

I'm attempting to run a jar file on a windows VM. When testing it using the CMD prompt, I get this error -
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)
Caused by: java.lang.NoClassDefFoundError: java/net/http/HttpClient
at jarName.Main.removeExtinct(Main.java:250)
at jarName.Main.main(Main.java:93)
... 5 more
Caused by: java.lang.ClassNotFoundException: java.net.http.HttpClient
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
This is my MANIFEST.MF:
Manifest-Version: 1.0
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
Rsrc-Class-Path: ./ selenium-server-standalone-3.7.1.jar aws-java-sdk-s3
-1.11.529.jar aws-java-sdk-kms-1.11.529.jar aws-java-sdk-core-1.11.529.
jar ion-java-1.0.2.jar jackson-dataformat-cbor-2.6.7.jar jmespath-java-
1.11.529.jar aws-java-sdk-dynamodb-1.11.529.jar httpclient-4.0.1.jar co
mmons-logging-1.1.1.jar commons-codec-1.3.jar httpcore-4.0.1.jar jackso
n-core-2.9.3.jar jackson-databind-2.9.3.jar jackson-annotations-2.9.0.j
ar postgresql-42.2.8.jar json-20190722.jar commons-net-3.6.jar jasypt-1
.9.0.jar ebay-oauth-java-client-1.1.0.jar okhttp-3.10.0.jar okio-1.14.0
.jar snakeyaml-1.20.jar joda-time-2.9.9.jar slf4j-api-1.7.25.jar seleni
um-java-3.11.0.jar selenium-api-3.11.0.jar selenium-chrome-driver-3.11.
0.jar selenium-edge-driver-3.11.0.jar selenium-firefox-driver-3.11.0.ja
r selenium-ie-driver-3.11.0.jar selenium-opera-driver-3.11.0.jar seleni
um-remote-driver-3.11.0.jar selenium-safari-driver-3.11.0.jar selenium-
support-3.11.0.jar byte-buddy-1.7.9.jar commons-exec-1.3.jar guava-23.6
-jre.jar jsr305-1.3.9.jar checker-compat-qual-2.0.0.jar error_prone_ann
otations-2.1.3.jar j2objc-annotations-1.1.jar animal-sniffer-annotation
s-1.14.jar jjwt-0.9.0.jar commons-lang3-3.7.jar gson-2.8.6.jar
Rsrc-Main-Class: jarName.Main
Class-Path: .
I think the class it's saying it can't find is httpclient-4.0.1.jar which is on the 6th line if the MANIFEST file. The only issue I can think of is the Class-Path at the end of the MANIFEST being just .
I also unzipped the .jar file, to make sure the relevant .jar files are actually present, which it is (assuming httpclient-4.0.1.jar is the correct file).
I can run other .jar files on this VM, though none with this class in it. I've updated Java as well, just in case, which didn't help.

httpclient-4.0.1.jar most probably means version v4.0.1 of org.apache.httpcomponents:httpclient.
And java.net.http.HttpClient was intriduced since 11 version of JDK.
Didn't you forget to use correct version of jre/jvm?

Related

Problems exporting Jar using Weka

i've got a big problem exporting my project as a jar file (inside my project i use weka). I'm using Eclipse.
I've added in Java Build Path weka.jar and i've attached to it weka-src.jar, testing my classifier under eclipse everything works, so i've decided to create a jar (because i need that another program use it).
First of all i've created the manifest file:
Manifest-Version: 1.0
Rsrc-Class-Path: ./ weka.jar weka-src.jar
Class-Path: .
Rsrc-Main-Class: start.Home
Main-Class: start.Home
The main class of the program is Home (inside the package start), while weka.jar and weka-src.jar are inside the /src/ directory of the eclipse program.
When i try to execute the jar created i receive this output:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: weka/classifiers/Classifier
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: weka.classifiers.Classifier
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)
... 7 more
I think that the problem is the CLASSPATH so i've tried to solve it in this way:
I've created the Environment Variable CLASSPATH with this values:
C:\Users\tomma\Desktop\workspace Eclipse\AndroidPermissionsClassifier\src\weka.jar
C:\Users\tomma\Desktop\workspace Eclipse\AndroidPermissionsClassifier\src\weka-src.jar
but nothing changed, can someone help me please?
You are right: the classpath is the problem. Did you remove the items from the manifest classpath when you added them to the environment CLASSPATH? (Side note: place the source jar in the -sourcepath, not the classpath.)

LWJGL with Eclipse i cannot fix the issue

Hello so I'm new with libraries and i followed a Youtube tutorial
https://www.youtube.com/watch?v=HRaJXVuZjRM
and he imports the libraries there and it works, i did too as he did and it works (when in eclipse), however the problem comes later, when i export the app (i always click package but have tried extract and doesn't work either), i cannot open the .jar file.
I have seen already countless threads with this problem, i searched on google and found this:
http://wiki.lwjgl.org/index.php?title=Setting_Up_LWJGL_with_Eclipse
which is basically what he did in the video, i open my manifest file inside of the jar file with 7zip and i get this:
``
Manifest-Version: 1.0
Rsrc-Class-Path: ./ jinput.jar jogg-0.0.7.jar jorbis-0.0.15.jar lwjgl.
jar slick.jar
Class-Path: .
Rsrc-Main-Class: com.tutorial.main.Game
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader"
And if i run the application with the console i get this error:
Sun Dec 06 16:42:40 COT 2015 INFO:Initialising sounds..
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.UnsatisfiedLinkError: no lwjgl in
java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.lwjgl.Sys$1.run(Sys.java:73)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
at org.lwjgl.Sys.loadLibrary(Sys.java:95)
at org.lwjgl.Sys.<clinit>(Sys.java:112)
at org.lwjgl.openal.AL.<clinit>(AL.java:59)
at org.newdawn.slick.openal.SoundStore$1.run(SoundStore.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at org.newdawn.slick.openal.SoundStore.init(SoundStore.java:292)
at org.newdawn.slick.Sound.<init>(Sound.java:54)
at com.tutorial.main.AudioPlayer.load(AudioPlayer.java:17)
at com.tutorial.main.Game.<init>(Game.java:41)
at com.tutorial.main.Game.main(Game.java:159)
... 5 more
``
I suppose it means that it cannot find the libraries and stuff but i have already tried creating a lib folder and a natives folder inside, placing the stuff there and changing the manifest into this:
"
Manifest-Version: 1.0
Class-Path: lib/jinput.jar lib/jogg-0.0.7.jar lib/jorbis-0.0.15.jar
lib/lwjgl.jar lib/slick.jar
Main-Class: com.tutorial.main.Game
"
But it doesn't run it either, i really don't know what I'm doing wrong...
I found a temporal fix for anyone with this problem, remove the natives from eclipse (the native link) and then export and use JarSplice to generate the .jar, if you are using music and cannot open it just open the .jar create the folder you used for your files in your workplace (mine was res) and then drag the music files in there instead of outside... this is temporal since I'm sure there's better ways to do it.

Apache POI Java program working fine in IDE (Eclipse) but encounter NoClassDefFoundError when I tried to run it as a runnable jar

I got a very strange problem that my program runs in Eclipse but doesn't run well wen exported as a runnable jar. I am getting ClassNotFoundException.
C:\Users\43156557\workspace\CAF3_IDE\MFTRelease>java -jar MSDocWriter.jar
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:58)
Caused by: java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:149)
at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:136)
at org.apache.poi.openxml4j.opc.Package.<init>(Package.java:54)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:81)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:220)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:39)
at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:1
11)
at com.hsbc.glt.automation.test.mft.util.MSDocumentWriter.initializeDocu
ment(MSDocumentWriter.java:92)
at com.hsbc.glt.automation.test.mft.util.MSDocumentWriter.main(MSDocumen
tWriter.java:70)
... 5 more
Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentException
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 java.lang.ClassLoader.loadClass(Unknown Source)
... 14 more
C:\Users\43156557\workspace\CAF3_IDE\MFTRelease>
ClassNotFoundException usually depicts that JVM is not able to load the required class file from the defined classpath (either the path is not correct or the class / jar is not present at the path).
The Error in current scenario might be cause have missed to include the Dependency libraries when creating the jar file. Since on eclipse you have the class-path correctly including those its working perfectly.
Make sure that you check "Package Required Jar into generated JAR" , this will include the jar files automatically from your eclipse build path.
for detailed info this might come handy Include Dependent Jars in Executable Jar

NoClassDefFoundError hibernate criterion exporting jar

I'm trying to export a java stand-alone class that uses hibernate. It's a really simple read/insert procedure. I'm stuck with this error
C:\Users\Admin\Desktop>java -jar ImportDatiMeteo2.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/criteri
on/Criterion
at openplan.openergy.standalone.ImportDati.main(ImportDati.java:24)
Caused by: java.lang.ClassNotFoundException: org.hibernate.criterion.Criterion
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)
... 1 more
I was thinking it could be a manifest file problem so i checked. It seem ok to me.
Manifest-Version: 1.0
Class-Path: lib/antlr-2.7.6rc1.jar lib/asm-attrs.jar lib/asm.jar
lib/c3p0-0.8.5.2.jar lib/cglib-2.1.3.jar lib/cleanimports.jar
lib/commons-collections-2.1.1.jar lib/commons-logging-1.0.4.jar lib/concurrent-1.3.2.jar
lib/connector.jar lib/dom4j-1.6.1.jar lib/ehcache-1.1.jar lib/hibernate3.jar
lib/jaas.jar lib/jacc-1_0-fr.jar lib/jaxen-1.1-beta-7.jar
lib/jdbc2_0-stdext.jar lib/jgroups-2.2.7.jar lib/jta.jar lib/log4j-1.2.11.jar
lib/log4j-1.2.9.jar lib/oscache-2.1.jar lib/proxool-0.8.3.jar
lib/swarmcache-1.0rc2.jar lib/xerces-2.6.2.jar lib/xml-apis.jar
Created-By: 1.6.0_21 (Sun Microsystems Inc.)
Main-Class: openplan.openergy.standalone.ImportDati
In my Eclipse all the project work properly, does anyone know where the problem is?
You need to add those libraries in classpath as you are running it from command line :
C:\> java -classpath <referenced-jars> -jar ImportDatiMeteo2.jar
in myEclipse all the project work properly, does anyone know where the problem is ?
--> Because Eclipse will take care of your classpath and adding libraries in your classpath.
Please check Library handling option in your Eclipse export dialog. On my side it works fine with hibernate with Extract required libraries into generated JAR selected.

com4j wrapper gen problems

I am trying to generate wrapper for com4j using tlbimp-20110320.jar. I also tried a 2008 version with the same errors. I get the same errors even when I try running against the example in the tut.
C:\Users\matthew\Documents\NetBeansProjects\test>"C:\Program Files (x86)\Java\jr
e7\bin\java.exe" -jar tlbimp-20110320.jar -o excel -p excel "C:\Program Files (x
86)\Microsoft Office\Office14\EXCEL.EXE"
Exception in thread "main" java.lang.NoClassDefFoundError: org/kohsuke/args4j/Cm
dLineException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.kohsuke.args4j.CmdLineException
at java.net.URLClassLoader$1.run(Unknown Source)
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)
... 6 more
After Iceman provided a link to a required library I was able to get it to run a little. However I had to copy the arg4j contents into the tlbimp jar, and the com4j contents into the tlbimp jar as well. Now I get
C:\Users\matthew\Documents\NetBeansProjects\test>"C:\Program Files (x86)\Java\jr
e7\bin\java.exe" -jar tlbimp-20110320.jar -o excel -p excel "C:\Program Files (x
86)\Microsoft Office\Office14\EXCEL.EXE"
Generating definitions from Excel
A referenced type library "Office" is generated into the same package "excel"
Unable to handle the type SAVEARRAY(Variant)*
method ConnectData
interface IRtdServer
A referenced type library "VBIDE" is generated into the same package "excel"
Exception in thread "main" java.lang.NullPointerException
at com4j.tlbimp.driver.Driver$1.resolve(Driver.java:64)
at com4j.tlbimp.Generator$LibBinder.<init>(Generator.java:382)
at com4j.tlbimp.Generator.getTypeLibInfo(Generator.java:686)
at com4j.tlbimp.Generator.getTypeName(Generator.java:663)
at com4j.tlbimp.TypeBinding.bind(TypeBinding.java:173)
at com4j.tlbimp.MethodBinder.declareReturnType(MethodBinder.java:542)
at com4j.tlbimp.MethodBinder.declareWithDefaults(MethodBinder.java:399)
at com4j.tlbimp.MethodBinder.declare(MethodBinder.java:118)
at com4j.tlbimp.InvocableInterfaceGenerator.generateMethod(InvocableInte
rfaceGenerator.java:39)
at com4j.tlbimp.InterfaceGenerator.generate(InterfaceGenerator.java:94)
at com4j.tlbimp.Generator$LibBinder.generate(Generator.java:491)
at com4j.tlbimp.Generator.generate(Generator.java:112)
at com4j.tlbimp.driver.Driver.run(Driver.java:107)
at com4j.tlbimp.driver.Main.doMain(Main.java:132)
at com4j.tlbimp.driver.Main.main(Main.java:56)
tlbimp-20110320.jar is required args4j-2.0.1.jar and com4j-20110320.jar
Note: com4j-20110320.jar, it is necessary to change the name to com4j.jar
Additional Info
The tlbimp of the latest version (tlbimp-2.1.jar), requires args4j-2.0.8.jar and com4j-2.1.jar.
In this version, file name change is not required.
From the stack trace, it looks like you are missing dependent jars from the java class path. The program seems to be looking for Koshuke's args4j library - http://args4j.kohsuke.org/.
Unjar tlbimp.jar and check out its manifest. It has a classpath where args4j and com4j must be in the same directory as tlbimp.jar and require specific names. The specifics of the name depend on the build and may or may not include version number. Name your com4j and arg4j as indicated and you're good to go.

Categories