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 /
Related
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.
I'm using Synthetica Look and Feel in my application and it works fine on Eclipse. But when i export the Jar file and execute it i got these errors :
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: sun/swing/plaf/synth/SynthUI
at de.javasoft.plaf.synthetica.SyntheticaDefaultLookup.getDefault(SyntheticaDefaultLookup.java:105)
at sun.swing.DefaultLookup.get(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.getInputMap(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.installKeyboardActions(Unknown Source)
at javax.swing.plaf.basic.BasicButtonUI.installKeyboardActions(Unknown Source)
at javax.swing.plaf.basic.BasicButtonUI.installUI(Unknown Source)
at javax.swing.JComponent.setUI(Unknown Source)
at javax.swing.AbstractButton.setUI(Unknown Source)
at javax.swing.JButton.updateUI(Unknown Source)
at javax.swing.AbstractButton.init(Unknown Source)
at javax.swing.JButton.<init>(Unknown Source)
at javax.swing.JButton.<init>(Unknown Source)
at de.javasoft.plaf.synthetica.SyntheticaLookAndFeel.installCompatibilityDefaults(SyntheticaLookAndFeel.java:925)
at de.javasoft.plaf.synthetica.SyntheticaLookAndFeel$4.propertyChange(SyntheticaLookAndFeel.java:582)
at java.beans.PropertyChangeSupport.fire(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at javax.swing.UIManager.setLookAndFeel(Unknown Source)
at com.evaluator.MainWindow.<init>(MainWindow.java:85)
at com.evaluator.Main$1.run(Main.java:15)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(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 Source)
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: sun.swing.plaf.synth.SynthUI
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)
... 35 more
I don't know where is the problem exactly. Here is the way I'm applying the Synthetica Blue Steel Look And Feel :
try
{
UIManager.setLookAndFeel(new SyntheticaBlueSteelLookAndFeel());
UIManager.put("Synthetica.rootPane.titlePane.title.center", true);
UIManager.put("Synthetica.translucency4DisabledIcons.enabled", true);
}
catch (Exception e) {}
Please see the error it can't find the sun/swing/plaf/synth/SynthUI
Library. In development mode You are include that jar file in eclipse library but when you are create a jar file then you are not include the Synthui theme jar. Put that Synthui jar file in jar, ext/ folder and it work fine
I think the way you are exporting the jar file is not correct.
Try exporting the jar as a Runnable jar file.
Follow these steps to export your app as a runnable jar.
1) select export from the file menu.
2) select Java->Runnable JAR file
3) Select the launch configuration i.e your main class.
4) first two option of library handling if you want to package the substance library file in your own jar and the third option(copy required library into a sub folder next to the generated jar) if you want to separate the generated jar file and substance libs.
5)Press finish.
I hope this would solve your problem. :)
There seems to be a number of similar questions related to this, but none have been able to provide me with any help. I'm running Microsoft's JDBC driver on SQL Server (I am using sqljdbc4.jar) and using integrated authentication to access my database. The code snippet for connecting is as follows:
String connectionUrl="jdbc:sqlserver://servername:1433;integratedSecurity=true;";
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
}//catch, etc...
When I run the project in Eclipse, it starts up without a hitch. When I run Maven clean install and pack it into a .jar, however, I get the error:
java.lang.ClassNotFoundException: Failure to load: com.microsoft.sqlserver.jdbc.SQLServerDriver
at launch.JarClassLoader.loadClass(JarClassLoader.java:964)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at ui.SearchWindow$1.run(SearchWindow.java:97)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(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 Source)
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)
I have attempted the solutions posted in other threads; I have a System CLASSPATH variable that directs to the .jar and it is located in my build path and my runtime classpath. Perhaps the problem is staring me in the face. My best guess is that it is related to Maven, but how should I go about solving this?
Also, please let me know if I need to clarify any points; I'd be more than happy to do so.
In your comment you confirm that you manually added it to the build path and not to the maven POM. You really need to add a dependency, otherwise Maven won't know about it when building.
And add the dependency to the POM:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>8.1.1.jre8</version>
</dependency>
See also:
https://github.com/Microsoft/mssql-jdbc
I'm trying to export my project as executable jar, and all is good except one thing: there are 2 windows - the first is main jframe and second is jframe for making 3D surfaces using jzy3d library; the first window contains button "Show" for executing the second jframe. When I execute this project in Eclipse it works good, but when I make executable jar it is executed, but if I click by "Show" button the second jframe doesn't open. So, please, tell me, how can I fix it?
UPDATE: the info from cmd:
Catched FileNotFoundException: C:\destination-natives-windows-i586.jar (═х єфр
ё эрщЄш єърчрээ√щ Їрщы), while TempJarCache.bootstrapNativeLib() of jar:file:
:/destination-natives-windows-i586.jar!/ (file:/C:/ + destination-natives-wind
s-i586.jar)
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: no glue
n-rt 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 com.jogamp.common.jvm.JNILibLoaderBase.loadLibraryInternal(JNILibLo
erBase.java:454)
at com.jogamp.common.jvm.JNILibLoaderBase.access$000(JNILibLoaderBase.
va:59)
at com.jogamp.common.jvm.JNILibLoaderBase$DefaultAction.loadLibrary(JN
ibLoaderBase.java:90)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibrary(JNILibLoaderBase
ava:328)
at com.jogamp.common.os.DynamicLibraryBundle$GlueJNILibLoader.loadLibr
y(DynamicLibraryBundle.java:390)
at com.jogamp.common.os.Platform$2.run(Platform.java:249)
at java.security.AccessController.doPrivileged(Native Method)
at com.jogamp.common.os.Platform.loadGlueGenRTImpl(Platform.java:231)
at com.jogamp.common.os.Platform.<clinit>(Platform.java:183)
at javax.media.opengl.GLProfile.<clinit>(GLProfile.java:99)
at org.jzy3d.global.Settings.<init>(Settings.java:12)
at org.jzy3d.global.Settings.getInstance(Settings.java:21)
at com.nda.fuzzy.views.SurfaceViewerFrame.<init>(SurfaceViewerFrame.ja
:102)
at com.nda.fuzzy.views.MainFrame$26.actionPerformed(MainFrame.java:579
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknow
Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(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 So
ce)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown So
ce)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown So
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)
Probaly on command line you did not specify the classpath for jzy3d library
You can run a jar file with lib:
"java -cp libs/* -jar program.jar"
where you put your lib (jzy3d.jar) in the libs folder
If you have used some special tool that creates an executable jar file,
then you have to configure that tool to include the jzy3d.jar lib to be used inside the exe.
You'll need to do one of the following:
repack the contents of each jarfile dependency in your own executable jarfile
use an .exe wrapper such as Launch4j to pack your jarfiles into a self-extracting-and-launching executable
include the jarfile dependencies in the Class-Path attribute of your MANIFEST.MF when creating the executable jarfile from Eclipse, and include those dependencies in the appropriate relative location when you distribute your application
Of the above options, 1 might be the easiest and most convenient for you. If you extract the contents of the jarfile dependencies into an Eclipse project, it is then very easy to include those resources when you create your jarfile using Eclipse's wizard.
Options 2 and 3 are also pretty straightforward but I would recommend making an ant script so you can have a 1-click build.
I'm trying to turn my JoGL project into a jar file. What am I doing wrong?
Exception in thread "main" java.lang.NoClassDefFoundError: javax/media/opengl/GL
EventListener
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$000(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 java.lang.ClassLoader.loadClassInternal(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.media.opengl.GLEventListener
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 java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 12 more
Could not find the main class: chartest. Program will exit.
Contents of the JAR file:
META-INF\MANIFEST.MF
gluegen-rt.jar
jogl.jar
chartest$1.class
chartest.class
gluegen-rt.dll
jogl.dll
jogl_awt.dll
jogl_cg.dll
test.png
You can check your classpath. It should include atleast
The jar file with classes you have written
Supporting jars with classes like javax.media.opengl (jogl.jar?)
Try placing all these jars in your classpath and run it.
is Jogle jar file in your classpath ?
I see you have included the jars themselves in your jar... this unfortunately wil not work out of the box.
Either get the jars out then place in your classpath (that can be part of your manifest also) or write your own classloader...
http://java.sun.com/docs/books/tutorial/deployment/jar/downman.html
This is why it worked for William and not for you... he got the jogl from somewhere else and did not use the one within your jar.
Switch to Netbeans to build your jar file. I find using other libraries inside of my projects including dll files its best to use something like Netbeans or just package it with maven.
mvn clean package
You need to be well versed in xml though if you want to use maven to package all of your jar files.