We have a simple [spring-hibernate] application (console app) where in we have set the classpath in manifest file of the executable JAR file. And the app connects to the database using jTDS JDBC Driver, Everything works as expected on Windows machine and JDK 1.6, but on Linux, the app is unable to find the driver,
We are running the program using java -jar MainClassName.
Any suggestions why this might be happening is greatly appreciated.
This issue occurred because our jdbc.url had invalid url. This was because maven treats jdbc.url property as a special property and while profiling, instead of url defined in the filter.properties. And that is the reason "No Suitable Driver" exception. The question should have been more clear.
Anyways to fix that we had to rename jdbc.url properties to jdbc.url.somename. This fixed our issue with maven profiling. We also had a similar maven profiling issue for a property called "server.name" This filter property was also confusing maven profiling . We had to change the name of that property as well.
Thanks again Fernando.
Honestly it sounds like bad CLASSPATH. One thing I suggest to start debugging this problem is copying the jtds package to same path as your main packages/classes and see if it works. This way you can assure the Classpath manifest is or isn't the problem. The Spring/Hibernate relies on the lib directory, so it will always be on classpath because it's main structure. Use the lib directory also to test.
Hope this guidelines will help. Also send more information, like paths, classpath and manifest files.
It is a Maven bug
http://jira.codehaus.org/browse/MNG-3563
Related
I want to keep the copy of my eclipse and spring tool suite in a shared path so that anybody can run the application logged in from their machine and use the common workspace settings.
However, except me when anyone else tries to run eclipse/STS they are getting the below error. I thought it is because of the .eclipse settings file is loaded from the C:/users/user-id/.eclipse. Apart from this the JDK, JRE etc.. are also configured in the shared path.
So even after relocating this settings file also to the shared path, I am facing the same error. Can some one help me to fix this?
below is the configuration folder
Well, first of all, I don't recommend you do this. You're better off sharing code in a central git repository than doing it this way.
However, the following SO thread talks about this: Change location where eclipse create .eclipse, .p2, and other folders .
I have java code which connects to a MS-SQL database and procures some data.
Before running the code I set the class path in the Unix Server and it used to work fine.
But for some reason the same jar file which was working a few days back is throwing a Class not found exception java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver
I have un-jared the jar file and found that the driver class which I'm loading :
Class.forName("net.sourceforge.jtds.jdbc.Driver");
is present in the specified package structure.
I don't understand how this is happening.
Can anyone suggest any tips to resolve this.
The issue of java.lang.ClassNotFoundException might be the outcome of several reasons:
Jar file is not available in class path. (This is not your case. as
you have mentioned).
Your jar file is corrupted.
Your environment variable value is not accessible by current user.
(Permission revoked by administrator).
Current user don't have permission to read jar file.
Please verify the last three options.
Right button on project-> Properties - > Java built Path -> Order and Export -> And check checkBox with you jar.
If you connect on Android project to Use 1.2.7 version.
I know it's late, but for others facing the same problem..
If you are using eclipse:
1. Go to Project -> Properties -> Java Build Path -> Order and export.. and check the jar file for jtds.version.jar
2. Go to Run Configurations and add this jar file to the user defined jars.
Hope this helps..:)
Ok I am on Win Vista and correctly set my MAVEN_HOME, JAVA_HOME stuff. but I do not have a class path yet. I have also installed MySQL. now I have opened a Hibernate book and at the very first pages it says "make sure the jdbc driver is in your classpath" . I have also downloaded some Zip file that is ConnectorJ or some name like that which is basically the mySql driver for java... but my problem for now is this sentence that I have no clue how to do it: "make sure the jdbc driver is in your classpath"
would you please help me about this classpath thing?
thanks
Here is a good tutorial regarding, setting the class path. Further you might like to read Managing the Java classpath (Windows).
Having said that, you should not set the classpath for your driver in Windows environment variable. Instead, you should include that driver jar inside your IDE under project properties. But I noticed that you are actually using Maven. In this case you should look for the driver under Maven in order to fulfil that dependency. Maven will download the driver jar, if doesn't exist, and make it local.
In case, you are not using any IDE, then you can create a lib directory and tell the compiler that all required jars are in there, at the time of compilation/execution. You can find HOW, in the former link given above.
Since you are using Maven, you just need to put the JDBC driver as a dependency in your pom.xml file. Maven will add it to the classpath whenever it compiles/runs your application.
What you do when deploying your application is dependent on the technologies in use.
If it's a command line application create a %CLASSPATH% variable or add the path to the jdbc.jar file using the java -cp {path\to\jdbc.jar} option.
If it's a web application, you'll need to package the driver jar in your .war/.ear/.sar (the maven assembly plugin can do this) or include it in the ./lib folder of the application container and declare it as scope=provided in maven.
Steps to setup JDBC for Eclipse projects
Download JDBC zip archive from
https://dev.mysql.com/downloads/connector/j/5.0.html
Extract the file and copy the executable jar file to program files->Java->jdk->bin
Right click on the project and select Buildpath->Add external archives->(Jar file)
Compile the program
you can directly connect database by following steps:
1) download mysql-connector-java 5.0.8 and extract the files.
2) then place the folder in program files.
3) then simply add this library on your project by right clicking on it.
4) and here you go. Run your app with db connectivity.
I successfully introduced xuggle in my tomcat environment and it worked perfectly.
Than something happens , and from that moment on, any time my thumbnail generator is called ( is the class that uses xuggle the most) i got the
*java.lang.UnsatisfiedLinkError: Native Library /usr/local/xuggler/lib/libxuggle-xuggler.so.3.4.1012 already loaded in another classloader* exception.
The only way I have to fix it is by restarting tomcat.
Since I can't reproduce the error nor on my laptop, I really appreciate a little help.
This happens probably because you have the Xuggler Jars in a webapp lib directory, and it needs to be at the CATALINA_ROOT directory. See the Xuggler FAQ for details. Stop tomcat, move the Xuggler jar files to the ${CATALINA_HOME}/shared/lib directory and restart tomcat and all should be OK.
If you can't reproduce the same problem on other devices, try to check if your system classpath has entry for this specific jar file because in usual tomcat configuration, system classpath is added along-with lib jar files.
I'm working on a small Java project that now connects to a MS SQL Server 2000 database, but will be shortly connecting to MS SQL Server 2005 database. I'm creating a single jar for ease of deployment. I was trying to set it up so I could just change a configuration file and change drivers (as I would in .NET). However, because of the limitations of Java's Jar embedded classpath, and the lack of the wildcard character on the embedded classpath(1). Is there any way to get around this problem without referencing every driver jar explicitly?
If I have to do that I'll have to recompile every time the database changes ...
(1): However, class path wildcards are not honored in the Class-Path jar-manifest header.
Generally, you can modify the classpath at runtime. Approaches like this are the general way to deal with "plugin" type jars in Java (very similar requirements to your case).
You could include the information about which driver to use in e.g. a config file. Or in the manifest of the JAR file itself. Simply include all JAR files when starting your application but load the driver’s name from the configuration.
I would say that it is not the Java way (as in the standard practice) to include third party code in the same Jar as you are deploying. However a jar is just a zip file, so in most cases (excepting some fancy stuff going on in the manifests) you can combine them, if you need to.
That being said, you can include in your jar file a classpath reference to all potential JDBC driver jars, or simply call the JDBC driver jar the right way. Then have a configuration file in the same directory (be sure to include . in your JAR's classpath) and then read the driver name from that, and use Class.forName() to load the driver.
You can do fancier things (like find the right jar at runtime and dynamically load it even though it wasn't on the classpath) but those things are a bit complicated, so something simple like the above should work.
You should never have to recompile. You aren't really doing JDBC right if you have to recompile when you change drivers.
You have to seperate the driver jar file and the actual name of the JDBC driver for the particular provider.
I would really encourage to not to include jdbc driver jars in your own jar.
Just at them to the path at runtime.
Similarly you can get the name of the JDBC driver manager from the system properties during runtime, or even a config file.
So running app like this:
java -jar myapp.jar -cp sqlserver.jar -DdriverManager=com.microsoft.sqlserver.jdbc.SQLServerDriver -DdbUrl=jdbc:some:url
and in your application, do something like this (I leave out exception handling):
Class.forName(System.getProperty("driverManager"));
Connection conn = DriverManager.getConnection(System.getProperty("dbUrl"))
;
This way you can change drivers simply by adding appropriate jar file to the classpath and changing the driverManager and dbUrl properties. This way you don't have to recompile to support new drivers.
That's the simplest solution that I can think of.