jdbc exception after jar creation - java

I've got an application, where I use a JDBC connection. When I run it from the Eclipse environment, there's no problem.
But, when I pack it into jar, the line
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
causes an exception:
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
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.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
I put a line into manifest file, but it didn't help:
Class-Path: sqljdbc4.jar
Can anyone help?

I finally solved the problem.
I installed the jdbc driver also on the remote server, and I packed the files to an executable jar (not only jar as before).

Related

Can not refer to class packed in Jar1 that zipped in Jar2 while running Jar2

I'm getting this weird issue when my colleague runs my Jar in JRE of same version as my development environment (Java1.7 + Eclipse Indiago).
Add a Jar to build path and refer to some Classes in this jar;
Compile, run the project as Java application successfully in Eclipse;
Export the project as Runnable Jar with option - 'Package required libraries into generated Jar'.
Run the exported Jar in command line 'java -jar xxx.jar' in my computer and get expected result.
Run the same Jar in another computer with same JRE but get something error like 'ClassNotFound' telling that the class referred from inner Jar can not be found, as shown below:
Exception in thread "main" java.lang.NoClassDefFoundError: com/test/commo
n/communication/BaseNotificationEvent
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 java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:56)
Caused by: java.lang.ClassNotFoundException: com.test.common.communicatio
n.BaseNotificationEvent
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 java.lang.ClassLoader.loadClass(Unknown Source)
... 14 more
The solution so far is to export runnable jar with option 'copy required libraries into sub-folder next to generated Jar', and this works both in my and another computer.
But I am not take this as ultimate solution for I have to transfer multiple files rather a single Jar while releasing my program...which seems not elegant ^_^

Exporting Runnable JAR in eclipse with User Libraries included

I am trying to create a runnable JAR file from a project of which I'm importing org.apache.commons.io. I tried exporting and checked the box to include all dependant libraries but I keep getting this output:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/io
/filefilter/TrueFileFilter
at tvSort.Main.main(Main.java:36)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.filefilter.Tr
ueFileFilter
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)
... 1 more
Any help would be appreciated, thank you.
Did you try setting up classpath in the Manifest?
e.g. Class-Path: commons-io-xyzversion.jar
If you can please try to add this manifest entry manually by saving this in a text file and adding it via the jar tool.
Hopefully eclipse has already done this,so did you run the jar with dependencies(jars) in the same folder/path?

Getting the c3p0 "ClassNotFound" Exception on MCServer start

iam trying to use MySQL Connection Pooling using c3p0.
I want to use c3p0 for a bukkit plugin.
The MANIFEST.MF looks as follow and is placed at Pooling.jar/META-INF/MANIFEST.MF
Manifest-Version: 1.0
class-path: ./Pooling/lib/c3p0.jar ./Pooling/lib/mchange.jar
I've placed the 2 files at
plugins/Pooling/lib/
However, it keeps printing this error:
2013-09-13 16:35:19 [SEVERE] Error occurred while enabling Pooling
v1.0.0 (Is it up to date?) java.lang.NoClassDefFoundError:
com/mchange/v2/c3p0/ComboPooledDataSource at
com.frostforce.Pooling.Database.setup(Database.java:11) at
com.frostforce.Pooling.Main.onEnable(Main.java:16) at
org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217) at
org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:457)
at
org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
at
org.bukkit.craftbukkit.v1_6_R2.CraftServer.loadPlugin(CraftServer.java:282)
at
org.bukkit.craftbukkit.v1_6_R2.CraftServer.enablePlugins(CraftServer.java:264)
at
net.minecraft.server.v1_6_R2.MinecraftServer.l(MinecraftServer.java:313)
at
net.minecraft.server.v1_6_R2.MinecraftServer.f(MinecraftServer.java:290)
at
net.minecraft.server.v1_6_R2.MinecraftServer.a(MinecraftServer.java:250)
at
net.minecraft.server.v1_6_R2.DedicatedServer.init(DedicatedServer.java:151)
at
net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:391)
at
net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
Caused by: java.lang.ClassNotFoundException:
com.mchange.v2.c3p0.ComboPooledDataSource 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
org.bukkit.plugin.java.PluginClassLoader.findClass0(PluginClassLoader.java:80)
at
org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:53)
at java.lang.ClassLoader.loadClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) ... 13 more
I have no idea at all what Iam doing wrong at the moment.
Thanks in advance!

ClassNotFoundException for TestApp when I start hazelcast/bin/run.bat

I started exploring hazelcast today I downloaded hazelcast-2.0 from the site, and following the ScreenCast provided in their site. I went to the bin directory and started run.bat from the command prompt.
I am getting the ClassNotFoundException. Can somebody please let me know what would have went wrong?
Caused by: java.lang.ClassNotFoundException: com.hazelcast.examples.TestApp
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)
As noted in duffymo's comment, there is a problem in the .bat file as it adds the following to the classpath ../lib/hazelcast-${project.version}.jar.
Just replace ${project.version} with the version number you downloaded, or check the correct jar name from the lib directory and everything should work properly.

What's wrong with this .jar file?

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.

Categories

Resources