Currently using IntelliJ for an IDE.
I inherited a project, and when I went through to make an artifact, I think the compiler is including my local JDK in the build, meaning that if my JRE and JDK are not the same, the program fails on a java.long.SecurityException because a quick signature check of the versions is run when my bundled "artifact" (the jar) runs.
Does anyone know how to make an artifact not bind to a specific JDK/JRE at build time? This program needs to be end user agnostic/independent.
Any help appreciated and thanks folks.
Here is the exact exception found when running the jar file:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
at java.base/sun.security.util.SignatureFileVerifier.processImpl(Unknown Source)
at java.base/sun.security.util.SignatureFileVerifier.process(Unknown Source)
at java.base/java.util.jar.JarVerifier.processEntry(Unknown Source)
at java.base/java.util.jar.JarVerifier.update(Unknown Source)
at java.base/java.util.jar.JarFile.initializeVerifier(Unknown Source)
at java.base/java.util.jar.JarFile.getInputStream(Unknown Source)
at java.base/jdk.internal.loader.URLClassPath$JarLoader$2.getInputStream(Unknown Source)
at java.base/jdk.internal.loader.Resource.cachedInputStream(Unknown Source)
at java.base/jdk.internal.loader.Resource.getByteBuffer(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(Unknown Source)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Unknown Source)
at java.base/sun.launcher.LauncherHelper.loadMainClass(Unknown Source)
at java.base/sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Related
I try to compile my code on Mobaxterm and am getting all these strange errors. Any idea what I'm doing wrong?
Exception in thread "main" java.lang.UnsatisfiedLinkError:
/usr/java/jre1.8.0_151/lib/i386/libawt_xawt.so: libXext.so.6: cannot open
shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)//
at java.lang.System.loadLibrary(Unknown Source)
at java.awt.Toolkit$3.run(Unknown Source)
at java.awt.Toolkit$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.loadLibraries(Unknown Source)
at java.awt.Toolkit.<clinit>(Unknown Source)
at java.awt.Component.<clinit>(Unknown Source)
at biuoop.GUI.<init>(GUI.java:36) //this is a library
at AbstractArtDrawing.DrawRandomLines(AbstractArtDrawing.java:37)
at AbstractArtDrawing.main(AbstractArtDrawing.java:15)
make: *** [run2] Error 1
If anyone has any idea what's going wrong, i'd really appreciate it.
According to this error message you need to install libXext for i386 (the processor architecture)
libXext is a package for X11 window system
you can check the below links for installation instructions:
ubuntu
Can't find/install libXtst.so.6?
centos
CentOS: error: libXext.so.6: cannot open shared object file: No such file or directory
:)
I have a java program that uses dynamic reports fine in netbeans, and even works in exe and jar when I first run it. However, if I share the jar/exe (I've even sent it and re-downloaded it on my own computer), I get an error java.lang.classnotfoundexception: net.sf.jasperreports.engine.jrdatasource. However, I have double checked my jars and I do have this class. What could be the source of this problem then?
Thanks
Edit: full error:
Exception in thread "main" java.lang.NoClassDefFoundError:
net/sf/jasperreports/engine/JRDataSource
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:
net.sf.jasperreports.engine.JRDataSource
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
if you get Caused by: java.lang.ClassNotFoundException: inside a jar file then, you need to provide the classpath arguments;
example:
java -cp my.jar -jar ExternalJarFileName.jar
you can also provide all jars use below command, only need to create a directory and put all external jars in to it and use path of directory in to below command:
java -cp my.jar;C:\externalJar\* mainpackage.MainClass
My jar file doesn't work outside the project folder, unless i put it in the same directory as the lib folder. When i run the jar from command line i get this:
C:\Users\Computer>java -jar SG.jar
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/hiber
nate/cfg/AnnotationConfiguration
at view.PessoaView.<init>(PessoaView.java:27)
at view.PessoaView$7.run(PessoaView.java:291)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour
ce)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.AnnotationConfigu
ration
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)
... 16 more
The same with other "windows", cause my application has many menu itens. I have extracted the jar file, just to check and there's no lib folder there. I believe it should.
The jar files needed for hibernate and all others required are all in the lib folder. Can someone help?Thanks..
And here is a link to a similar question:
why doesn't my jar file run outside netbeans??
Your problem is that your jar does not includes dependancies that it requires for execution.
Your program requires hibernate jars. You can compile all dependancies with your current jar using maven.
Try this :
Build jar with dependancies
Jar file can not contain any other jar files.
Some tools like ant, can pack several jars inside one you can take a look on the ant.
Another way is directly specify class path to your libraries during running using java -cp instead of java -jar
You can directly specify class path to the needed libraries during running using java -cp /
My projects is running on a Windows 2008 Server.
My project source code sit in the following folders:
com.company.division.dao
com.company.division.entity
com.company.division.main
com.company.division.junit
My junit test class are in the folder C:\Sample\com\company\division\junit.
I am using JUnit 4.11
When I run this from Eclipse it runs fine.
I have tried the following from DOS command line:
First I cd C:\Sample\com\company\division\junit\
From C:\Sample\com\company\division\junit> where the compiled EventTests.class file exists I run:
java -classpath "C:\Sample\lib\junit.jar;" org.junit.runner.JUnitCore com.company.division.junit.EventTests
OR
java -cp "C:\Sample\lib\junit.jar;" org.junit.runner.JUnitCore com.company.division.junit.EventTests
OR
java -cp ".;C:\Sample\lib\junit.jar;" org.junit.runner.JUnitCore com.company.division.junit.EventTests
But nothing seems to work. I get an exception:
JUnit version 4.11
Could not find class: com.company.division.junit.EventTests
Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at org.junit.runner.Computer.getSuite(Computer.java:28)
at org.junit.runner.Request.classes(Request.java:75)
at org.junit.runner.JUnitCore.run(JUnitCore.java:117)
at org.junit.runner.JUnitCore.runMain(JUnitCore.java:96)
at org.junit.runner.JUnitCore.runMainAndExit(JUnitCore.java:47)
at org.junit.runner.JUnitCore.main(JUnitCore.java:40)
Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
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)
... 18 more
Edited - New update
So from one of the other threads I figured out what the command eclipse was using to run the unit tests. Eclipse was using javaw.exe, I replaced javaw with java.exe tool.
Here is the command,
C:\Java\64bit_Browser_Plugin\bin\java.exe -Dfile.encoding=Cp1252 -classpath C:\working_dir\bin;C:\working_dir\lib\mysql-connector-java-5.0.8-bin.jar;C:\working_dir\lib\ojdbc14.jar;C:\working_dir\lib\spring-beans-3.2.4.RELEASE.jar;C:\working_dir\lib\spring-context-3.2.4.RELEASE.jar;C:\working_dir\lib\spring-core-3.2.4.RELEASE.jar;C:\working_dir\lib\spring-expression-3.2.4.RELEASE.jar;C:\working_dir\lib\spring-jdbc-3.2.4.RELEASE.jar;C:\working_dir\lib\spring-tx-3.2.4.RELEASE.jar;C:\working_dir\lib\commons-logging-1.1.3.jar;C:\working_dir\lib\nzjdbc.jar;C:\working_dir\lib\junit.jar;C:\working_dir\lib\spring-batch-core-2.2.5.RELEASE.jar;C:\working_dir\lib\spring-batch-infrastructure-2.2.5.RELEASE.jar;C:\working_dir\lib\hamcrest-core-1.3.jar;C:\working_dir\lib\log4j-1.2.14.jar;C:\working_dir\lib\mail.jar;C:\working_dir\lib\spring-context-support-4.0.1.RELEASE.jar;/C:/eclipse/configuration/org.eclipse.osgi/bundles/167/1/.cp/;/C:/eclipse/configuration/org.eclipse.osgi/bundles/166/1/.cp/ org.eclipse.jdt.internal.junit.runner.RemoteTestRunner -version 3 -port 54536 -testLoaderClass org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader -loaderpluginname org.eclipse.jdt.junit4.runtime -classNames com.omnitracs.fra.junit.EventTests
I am still getting an exception:
Could not connect to: : 54536
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.connect(Remote
TestRunner.java:570)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTest
Runner.java:381)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTes
tRunner.java:197)
What am I missing?
Try including hamcrest-core.jar in the classpath.
https://github.com/junit-team/junit/wiki/Download-and-Install
Changing directories to where your test is located is a mistake. The java program will start from the classpath you give it and assume the package directory structure starts from there, so if you are in C:\Sample\com\company\division\junit\ and you give the java command -cp = "." then it will look for the class com.company.division.junit.EventTests in C:\Sample\com\company\division\junit\com\company\division\junit\.
Also if you don't include your classes in the classpath (your last example is the only one to include them) then the java exe won't find them.
You need to add the current directory to the classpath, first changing directories so that the top of the package structure is at your current directory:
cd c:\Sample
java -cp ".;lib\*.jar" org.junit.runner.JUnitCore com.company.division.junit.EventTests
This way . points to where your packages are defined.
If you would rather use absolute paths then try
java -cp "C:\Sample;C:\Sample\lib\*.jar" org.junit.runner.JUnitCore com.company.division.junit.EventTests
You can use the * as a wildcard to include multiple jars starting with jdk 6.
For the future, consider using the directory layout used by default in Maven. Keeping tests separate from code is typically a good thing. I wonder if part of this problem isn't that test-only dependencies are located in a different spot than other libraries.
Right-click on your project in Eclipse and find the menu Build Path -> Configure Build Path, and make sure you know where Eclipse is getting these jars from.
Good Morning, I have a problem when I try to execute my .jar. My program read some file from distant server by JSch.
C:\Documents and Settings\julie\Bureau>java -jar myFile.jar
Exception in thread "main" java.lang.NoClassDefFoundError: com/jcraft/jsch/SftpE xception
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: com.jcraft.jsch.SftpException
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
You have a missing classes in this package : com.jcraft.jsch.
If this package come from a third part library, then make sure that the jar contais this package inside a lib folder at the same level of your executable jar.
[Edit]
First: to add a third part jars in eclipse:
Right click on your project
Select properties -> Java Build Path -> Libraries tap.
Select Add External JARs
Navigate to your jars and press OK
Second: to generate an executable Jar file:
Right click on your project
Select Export -> Java -> Runnable JAR File.
This should work just fine.