I have a GUI application that connects to a SQL Server 2008 database using sqljdbc4.jar. If I run this from the command line it works great.
However, once I wrap it into an executable JAR, I get a "No suitable driver found for jdbc:sqlserver://myServer:1433;databaseName=myDb" error. I know that my Windows system CLASSPATH is ignored once it's in a JAR, but I can't figure out include the sqljdbc4.jar within the executable JAR and get a portable application.
My most recent attempt to fix this is as follows:
My MANIFEST.MF file:
Manifest-Version: 1.0
Class-Path: lib/sqljdbc4.jar
Created-By: 1.7.0_11 (Oracle Corporation)
Main-Class: MyApp
The command I use to compile the JAR:
jar cmf MANIFEST.MF MyApp.jar MyApp.class help.html lib
My directory structure is below. I am running the jar command inside the MyApp directory.
+ MyApp
+ lib
- sqljdbc.jar
- help.html
- MANIFEST.MF
- MyApp.class
- MyApp.java
When I create the JAR and run it inside the MyApp directory, it works fine. As soon as I pull it out of the directory, I get the error. How can I make the JAR access the sqljdbc.jar that is available internally?
Thanks in advance.
When you have an executable jar MyApp.jar with entry in the manifest.mf:
Class-Path: lib/sqljdbc4.jar
This means that the jar has an external dependency to sqljdbc4.jar in the (relative) folder lib. It is not included in the jar you created! So you need to make sure that there is a lib-folder containing sqljdbc4.jar relative to that jar when you execute it. So the folder structure when executing needs to be;
+ (a folder)
+ lib
- sqljdbc.jar
- MyApp.jar
Related
When I am compiling the Java code, I have written the command line shows the following:
C:\HTML>javac Jdbc.java
Jdbc.java:5: error: package com.mysql does not exist
Class.forName(com.mysql.jdbc.Driver);
^
1 error
I have installed XAMPP and started the Apache, MySQL and Tomcat and they are working. I have installed MySQL Connector which is platform independent and latest. I have copied the JAR executable file to the JDK folder. I have added the jar executable file path in the edit system environment variables,
''' Class.forName(com.mysql.jdbc.Driver);'''
If you reference classes from a library, you should add that library to the classpath (i.e. javac -cp .;path\to\your\mysql-connector.jar Jdbc.java). However, that would immediately result in a different error, because that code should be Class.forName("com.mysql.jdbc.Driver") (passing a String).
Some further remarks:
I have copied the JAR executable file to the JDK folder.
You should never manually copy files to the JDK folder (in older versions there was the ext mechanism, but this no longer exists in recent Java versions). In addition, MySQL Connector/J is a library, not an executable jar.
I have added the jar executable file path in the edit system environment variables
Java JARs do not belong on the PATH. In theory you can add them to CLASSPATH environment variable, but that is generally considered a bad idea: most ways of executing Java do not actually use it, and if it does get used, it can result in unexpected behaviour because of conflicting or unexpected libraries on the classpath, etc.
I am working with a simple JDBC program. While executing the program i notice the following behaviour.
The program works only when the mysql-connector-java-5.1.35-bin file is copied in the location C:\Program Files\Java\jdk1.6.0_43\jre\lib\ext
I changed the mysql-connector-java-5.1.35-bin file to the location(C:\Program Files\Java\jdk1.6.0_43\bin) and changed the classpath to C:\Program Files\Java\jdk1.6.0_43\bin. But in this case the program execution fails with
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver exception
So my question is, Is it mandatory to copy the mysql-connector-java-5.1.35-bin in C:\Program Files\Java\jdk1.6.0_43\jre\lib\ext ?
Don't put any file under the JDK installation directory. Add the jar file itself to the classpath, and not the directory containing the jar file:
java -cp c:\path\to\mysql-connector-java-5.1.35-bin.jar;yourApplication.jar com.foo.bar.YourMainClass
I am a newbie and I wanted to know how build path and all mysql.jar to Eclipse so that I can use it for JSP and I have already made a dynamic web project configured with Tomcat. Only the database connection is not happening.
The error is:
java.sql.SQLException : No suitable driver found for jdbc:mysql://localhost/pj_company
You could create a lib folder your WEB-INF folder and paste the mysql driver jar in it, and then in eclipse, right click on the jar file --> Build Path --> Add to Build Path
I've been using Flashdevelop (version 4.4) for some time now with zero problems. I recently reinstalled Windows 7 however, and after installing Flashdevelop it is demanding Java 1.6 and won't compile without it. Let me be more specific, here is the error I get when I try to compile a simple HelloWorld-type test:
"Running process: C:\Program Files (x86)\FlashDevelop\Tools\fdbuild\fdbuild.exe "C:\Users\marc\Documents\DeleteMe\DeleteMe\DeleteMe.as3proj" -ipc 01be003c-6cb5-4d0b-9c35-c59dd2ea7a19 -version "4.6.0; 3.3" -compiler "C:\Program Files (x86)\FlashDevelop\Tools\flexsdk" -library "C:\Program Files (x86)\FlashDevelop\Library" -cp "C:\Program Files (x86)\Java\jdk1.6.0_34\bin" -cp "C:\Program Files (x86)\Java\jdk1.6.0_34"
Building DeleteMe
mxmlc -load-config+=obj\DeleteMeConfig.xml -debug=true -incremental=true -swf-version=16 -o obj\DeleteMe634829909556672047
Starting java as: C:\Program Files (x86)\Java\jdk1.6.0_34\bin\java.exe;\bin\java.exe
Unable to start java.exe: The system cannot find the file specified
Could not compile because the fcsh process could not be started.
Build halted with errors (fcsh).
INITIALIZING: Failed, unable to run compiler
Done(1)"
The GlobalClasspath setting for the Java 1.6 JDK is set to: C:\Program Files (x86)\Java\jdk1.6.0_34\bin
I have also set my JAVA_HOME environment variable to the same location as well. Might I be neglecting to set another environment variable?
JAVA_HOME should be
C:\Program Files (x86)\Java\jdk1.6.0_34
and not
C:\Program Files (x86)\Java\jdk1.6.0_34\bin
FlashDevelop currently doesn't support that your JAVA_HOME environment var contains several paths (C:\Program Files (x86)\Java\jdk1.6.0_34\bin\java.exe, \bin\java.exe).
Modify it to only indicate the first path (C:\Program Files (x86)\Java\jdk1.6.0_34\bin\java.exe).
As someone who was dealing with this, I just found an answer that doesn't involve mucking with the PATH variables.
Go into your Flex SDK, /bin directory, look for the JVM config file conveniently named jvm.config
Inside, there is a param 'java.home' which, if left empty, will cause it to search for it's own value. Enter in the main path to the JRE - in my case,
java.home=C:\Program Files\Java\jre1.6.0_07\
I found mine by going to "Control Panel > Java > Java tab > View... button" to see all the installed versions and their paths
I prefer this method because I feel like you shouldn't have to modify settings on your whole system to get 1 program to work, if you have the option instead to just modify that program's settings.
jvm.config in C:\Program Files (x86)\FlashDevelop\Tools\flexsdk\bin\jvm.config is much more better than path variable.
Please avoid Path variable.
In jvm.config just set jre URL directory
java.home=C:\Program Files\Java\jre1.6.0_07
May be you update the Java, last version of Java ask you to delete older version. Then go into the file
C:\Program Files (x86)\FlashDevelop\Tools\flexsdk\bin\jvm.config
and replace
java.home=C:\Program Files\Java\jre1.6.0_07\
by the folder were is your new version
java.home=C:\Program Files (x86)\Java\jre1.8.0_25\
I am trying to use Rawr to turn a simple 3-file Ruby project into an executable jar to be run on Ubuntu. I ran jruby -S rawr install to create the Rakefile and set up the directory layout. All my .rb files are under the src directory at the root of the project. When I run jruby -S rake rawr:jar, it compiles all the Ruby files and creates the jar just fine. It then places it in my deploy directory along with lib/java/jruby-complete.jar.
I try executing the jar from inside deploy with java -jar hg_analyzer.jar. However, when I do this I am greeted with this error:
Exception in thread "main" <script>:1:in `require': Linkage error loading compiled script; you may need to recompile 'file:/home/marcw/Documents/hg_analyzer/deploy/jar/hg_analyzer.jar!/main.class': java.lang.NoClassDefFoundError: org/jruby/ast/executable/AbstractScript$RuntimeCache (LoadError)
from <script>:1
...internal jruby stack elided...
from Kernel.require(<script>:1)
from (unknown).(unknown)(:1)
I've also tried running it as java -cp lib/java/** -jar hg_analyzer.jar, but to no avail. The Class-Path entry in the jar's manifest file looks okay as well. main.rb is the main Ruby file.
Running java with the -verbose option shows that it is finding the JRuby jar and is loading it from the expected location.
Any ideas?
Figured it out! The problem was that Rawr was downloading version 1.5 of the JRuby runtime and I have version 1.4 of the compiler on my system.