I'm developing this Java app, everything works fine in eclipse
but this program will not run with Apache Tomcat 7.0 because it cannot find the sqlserver driver.
This app is suppose to connect to a sqlserver 2005 database, but it will not get past the Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"), on the server side.
I know it's that line because I found:
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
in my log file. I placed the sqljdbc.jar in every catalinaHome/lib, catalinaHome/shared/lib, and web-inf/lib.
I also edited the catalina.properties so it reads from the shared/lib folder.
I'm out of ideas, any help will be awesome!
UPDATE #1 - problem solved
I manually included the .class files into the war file and now it works.
CATALINA_HOME/lib should work. Have you restarted Tomcat after that though?
And SQL driver needs some DLLs, it seems. Do you have them setup correctly? The visible error may still be ClassNotFound because if class fails to initialize statically, it is viewed as class not found at all.
Before deploying the driver to Tomcat, make a small local test - a standalone Java class that loads the driver and tries to connect. May point you to the issue more clearly.
The correct place for it is application/WEB-INF/lib/. Note the upper-case WEB-INF.
Related
I am writing my code in Intellij and created a Sqlite Database for some data. I connected it with the sqlite-jdbc-3.23.1.jar driver inside of intellij and can run it successfully there.
When I create a JAR (or multiple Jars because of the Modules) and start the programm, I get this error message:
java -jar ServerAbschalteHotline.jar java.sql.SQLException: No
suitable driver found for jdbc:sqlite:src/Resources/credentials.db at
java.sql.DriverManager.getConnection(DriverManager.java:689) at
java.sql.DriverManager.getConnection(DriverManager.java:270) at
com.company.SQLiteHandler.connect(SQLiteHandler.java:20) at
com.company.SQLiteHandler.getCredentials(SQLiteHandler.java:30) at
com.company.HttpsServer.makeServer(HttpsServer.java:64) at
com.company.Main.main(Main.java:21)
So for me it looks like the programm couldnt find the driver after it get exported. I checked that the .jar file is there (with all the other .jar files) and tried to include it as a libary too.
I guess I missed one place where I have to add the jar, so where is it?
In the end a clean jar (downloaded the same version of the jar from the same page) and a recompiling solved the problem. I dont know where the real problem was, maybe the jar contains error(s)
I don't know if this will help, but when creating the jar I make sure that the JDBC driver is included.
There is a VERY similar question to mine but in my case I don't have any duplicate jars in my build path, so the solution does not work for me. I've searched google for a couple of hours now, but none of the solutions I've found there actually resolve my issue. I'm creating a web site with some database connectivity for a homework. I'm using a MySQL database, developing in Eclipse and running on Windows.
I keep getting java.lang.ClassNotFoundException: com.mysql.jdbc.Driver with the following code:
import java.sql.*;
//...
public void someMethodInMyServlet(PrintWriter out)
{
Connection connection = null;
PreparedStatement query = null;
try {
out.println("Create the driver instance.<br>");
Class.forName("com.mysql.jdbc.Driver").newInstance();
out.println("Get the connection.<br>");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "secret");
query = connection.prepareStatement( "SELECT * FROM customers");
//...
} catch (Exception e)
{
out.println(e.toString()+"<br>");
}
}
//...
When I run the above code I get the following output:
Create the driver instance.
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
It doesn't get past the Class.forName... line and I can't figure out why! Here is what I did:
Download mysql-connector.
Put it in my MySQL folder C:\Program Files\MySQL\mysql-connector-java-5.1.12\mysql-connector-java-5.1.12-bin.jar.
Opened the project properties in Eclipse.
Add External Jar to my Build Path and I selected mysql-connector-java-5.1.12-bin.jar.
Every time I attempt to use the servlet I get the same error regardless if I have the jar in there or if I don't. Could you help me figure this out?
As for every "3rd-party" library in flavor of a JAR file which is to be used by the webapp, just copy/drop the physical JAR file in webapp's /WEB-INF/lib. It will then be available in webapp's default classpath. Also, Eclipse is smart enough to notice that. No need to hassle with buildpath. However, make sure to remove all unnecessary references you added before, else it might collide.
An alternative is to install it in the server itself by dropping the physical JAR file in server's own /lib folder. This is required when you're using server-provided JDBC connection pool data source which in turn needs the MySQL JDBC driver.
See also:
How to add JAR libraries to WAR project without facing java.lang.ClassNotFoundException? Classpath vs Build Path vs /WEB-INF/lib
How should I connect to JDBC database / datasource in a servlet based application?
Where do I have to place the JDBC driver for Tomcat's connection pool?
JDBC CLASSPATH Not Working
Since you are running it in servlet, you need to have the jar accessible by the servlet container. You either include the connector as part of your application war or put it as part of the servlet container's extended library and datasource management stuff, if it has one. The second part is totally depend on the container that you have.
The others are right about making the driver JAR available to your servlet container. My comment was meant to suggest that you verify from the command line whether the driver itself is intact.
Rather than an empty main(), try something like this, adapted from the included documentation:
public class LoadDriver {
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver");
}
}
On my platform, I'd do this:
$ ls mysql-connector-java-5.1.12-bin.jar
mysql-connector-java-5.1.12-bin.jar
$ javac LoadDriver.java
$ java -cp mysql-connector-java-5.1.12-bin.jar:. LoadDriver
On your platform, you need to use ; as the path separator, as discussed here and here.
Place mysql-connector-java-5.1.6-bin.jar to the \Apache Tomcat 6.0.18\lib folder. Your problem will be solved.
What you should not do do (especially when working on a shared project)
Ok, after had the same issue and after reading some answers here and other places. it seems that putting external lib into WEB-INF/lib is not that good idea as it pollute webapp/JRE libs with server-specific libraries - for more information check this answer"
Another solution that i do NOT recommend is: to copy it into tomcat/lib folder. although this may work, it will be hard to manage dependency for a shared(git for example) project.
Good solution 1
Create vendor folder. put there all your external lib. then, map this folder as dependency to your project. in eclipse you need to
add your folder to the build path
Project Properties -> Java build path
Libraries -> add external lib or any other solution to add your files/folder
add your build path to deployment Assembly (reference)
Project Properties -> Deployment Assembly
Add -> Java Build Path Entries
You should now see the list of libraries on your build path that you can specify for inclusion into your finished WAR.
Select the ones you want and hit Finish.
Good solution 2
Use maven (or any alternative) to manage project dependency
Just follow these steps:
1) Install eclipse
2) Import Apache to eclipse
3) Install mysql
4) Download mysqlconnector/J
5) Unzip the zipped file navigate through it until you get the bin file in it. Then place all files that are present in the folder containing bin to C:\Program Files\mysql\mysql server5.1/
then give the same path as the address while defining the driver in eclipse.
That's all very easy guys.
If the problem still persists,
Put the-
mysql-connector-java-5.0.8-bin jar in a place inside your Tomcat->lib->folder (No matter where you've installed your Tomcat). And change your environmental variable (Done by clicking Properties of Mycomputer -Advanced system settings- Environmental variables-And set a new variable name & variable values as the place where your lib file resides.Dont forget to enter a ; at the end of the path)
If still problem persists
Try downloading commons-collections-2.0.jar (http://www.docjar.com/jar_detail/commons-collections-2.0.jar.html) and paste the jar in the same place where your mysql jar resides (ie) inside Tomcat-lib.
Clean your project-Stop your server- Finally try to run.
Many times I have been facing this problem, I have experienced ClassNotFoundException.
if jar is not at physical location.
So make sure .jar file(mysql connector) in the physical location of WEB-INF lib folder. and
make sure restarting Tomcat by using shutdown command in cmd.
it should work.
The only solution worked for me is putting the .jar file under WEB-INF/lib . Hope this will help.
assuming your project is maven based, add it to your POM:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
</dependency>
Save > Build > and test connection again. It works! Your actual mysql java connector version may vary.
Put mysql-connector-java-5.1.38-bin.jar to the C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib folder.by doing this program with execute
My issue was a little different. Instead of jdbc:oracle:thin:#server:port/service i had it as server:port/service.
Missing was jdbc:oracle:thin:# in url attribute in GlobalNamingResources.Resource. But I overlooked tomcat exception's
java.sql.SQLException: Cannot create JDBC driver of class 'oracle.jdbc.driver.OracleDriver' for connect URL 'server:port/service'
for this error:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
you need to:
Import java.sql.*;
Import com.mysql.jdbc.Driver;
even if its not used till app running.
I created a java GUI application using java.awt. The basic idea off the app is to query a mongo database using the mongo-java driver.
When running the code from the command prompt, the GUI opens up and it can interact with the initialized mongod server just fine with no problem. However, when I create a jar executable with the same class, the GUI opens up fine, yet none of the server interactions seem to occur.
For instance, when running the non-jar version, the mongod server running in the background displays something along the lines of: Sat Dec 14 09:14:20.347 [initandlisten] connection accepted from 127.0.0.1:XXXX #5 (1 connection now open), yet when running the jar version (without making any changes to the source code at all, literally the same exact .java and .class files), I don't see any of the conection statuses on the server.
I doubt you need me to insert all my code into this post, but here are the details that I think are most relevant to my issue. Let me know if you need any other details.
when creating my jar I used the command:
jar cvfm MongoDBGUI.jar manifest.txt *.class
manifest.txt has the line:
Main-Class: MongoDBGUI
*MongoDBGUI being the class with the main function
My crystal ball says that you've been swallowing exceptions in your code, so when something goes wrong, you have no logging to tell you what the error was.
My tarot cards tell me that you don't have the driver packaged inside your jar, so the driver isn't found. But my ouija board claims that you do have the driver inside the jar, it's just not configured properly in the classpath in MANIFEST.MF.
I've just downloaded Grails 2.0.4 and extracted it to /opt/grails/grails-2.0.4/ and made sure that the GRAILS_HOME environment variable is correct. But whenever I try run the "grails" command, I get the following error:
Error opening zip file or JAR manifest missing : /opt/grails/grails-2.0.4/lib/com.springsource.springloaded/springloaded-core/jars/springloaded-core-1.0.2.jar
Error occurred during initialization of VM
agent library failed to init: instrument
I don't understand what the problem could be. I've been using Grails-2.0.1 for months successfully in exactly the same way on exactly the same machine. I've tried re-downloading the grails-2.0.4.zip file in the hopes that it was a problem with the archive, but that didn't help. I also copied springloaded-core-1.0.2.jar from the grails-2.0.1/ directory, but that just caused another set of errors.
Any idea what could be going wrong?
I experienced this error too. The problem is spaces in the grails home path.
If it's this:
c:/grails 2.1.0/grails2.1.0
Then it will give an error, as there's a space between "grails" and "2.1.0". I just removed the spaces and it started working.
It looks like your PATH has not been updated correctly. In other words, you are running the 2.0.1 grails script with GRAILS_HOME set to 2.0.4. You can tell because the version of spring loaded reported in the error message - 1.0.2 - is not the one required by Grails 2.0.4 (to help others diagnose this issue).
Have you cleared out the .grails folder in your home directory?
Grails caches a bunch of files in there, it could be that that is tripping you up.
I have had similar problems in the past when my internet connection wasn't a 100% reliable, it seems that the Grails downloader does not do thorough checking of downloaded files, so files in cache can become corrupt.
It's the folder hierarchy problem!
I have faced the same issue : when i set Grails_home make sure the path you are giving is e.g c:/grails2.1.0 and not c:/grails2.1.0/grails2.1.0
it often happens when you unzip the folder 2 folder with same name are created one inside another.
hope this will resolve!!!
I had the same problem. Here is how I solved it:
Previously:
I had grails in: C:\Program Files\grails-2.5.5
and in the system's environmental variables I had
GRAILS_HOME: C:\Program Files\grails-2.5.5 and also
C:\Program Files\grails-2.5.5\bin in PATH.
Then I tried:
To put grails in C:\Grails_2.5.5\grails-2.5.5
and updated GRAILS_HOME to C:\Grails_2.5.5\grails-2.5.5 and the text in PATH to C:\Grails_2.5.5\grails-2.5.5\bin
BUT, I still got the same error.
What fixed it:
Put grails in C: C:\grails_2.5.5
Update Environmental variables to the correct grails path:
-GRAILS_HOME: C:\grails-2.5.5
-In PATH: C:\grails-2.5.5\bin
Restart pc
Wish you luck!
I am following the tutorial here:
http://nutch.sourceforge.net/docs/en/tutorial.html
Crawling works fine, as does the test search from the command line.
When I try to fire up tomcat after moving ROOT.war into place(and it unarchiving and creating a new ROOT folder during startup), I get a page with the 500 error and some errors in the Tomcat logs.
HTTP Status 500 - No Context configured to process this request
2009-02-19 15:55:46 WebappLoader[]: Deploy JAR /WEB-INF/lib/xerces-2_6_2.jar to C:\Program Files\Apache Software Foundation\Tomcat 4.1\webapps\ROOT\WEB-INF\lib\xerces-2_6_2.jar
2009-02-19 15:55:47 ContextConfig[] Parse error in default web.xml
org.apache.commons.logging.LogConfigurationException: User-specified log class 'org.apache.commons.logging.impl.Log4JLogger' cannot be found or is not useable.
at org.apache.commons.digester.Digester.createSAXException(Digester.java:3181)
at org.apache.commons.digester.Digester.createSAXException(Digester.java:3207)
at org.apache.commons.digester.Digester.endElement(Digester.java:1225) ............ etc.
So it looks like the root of the error is default web.xml, not in the Log4JLogger - although I know very little about Java. I did not edit the web.xml in the tomcat dir.
Anyone know what is going on here?
versions/info:
nutch 0.9
Tomcat 4.1
jre1.5.0_08
jdk1.6.0_12
NUTCH_JAVA_HOME=C:\Program Files\Java\jdk1.6.0_12
JAVA_HOME=C:\Program Files\Java\jdk1.6.0_12
In Java, applications sometimes rely on third party libraries. In this case, it appears that your Tomcat installation does not include one such library. Judging by the error you received, it appears that you are missing the Apache Commons Logging library (a commonly used library in the Java world that just so happens to not come bundled with Tomcat).
The typical way to distribute a library in Java is via a JAR (Java Archive) file. Simply put, a JAR file is simply a bunch of Java classes that have been zipped into a file that has been renamed from *.zip to *.jar.
To obtain the Commons Logging JAR file, you can download it from the Apache Commons download site. You will want the binary version, not the source version. Should you happen to download version 1.1.1 (for example), you should unzip the commons-logging-1.1.1-bin.zip file. Inside, you will find a file named commons-logging-1.1.1.jar. Copy this JAR file to the lib directory wherever your Tomcat software is installed. You may be required to restart Tomcat before it notices this new file.
Hopefully, the next time you try to use the application, you may or may not receive yet another error indicating that yet another class cannot be found. In that case, I welcome you to the wonderful world of JAR hunting! :) Hopefully the application will not require too many libraries above and beyond Commons Logging, but we will see (considering you're trying to run Nutch, I can foresee it requiring Lucene, so be prepared for that).
Have fun with Nutch!
For me that tells that it can't find the logger which is reported as a parse error itself. A bit odd or disinformant way to express it, I guess. Anyway, I think you need to add the Commons Logging .jar to your libraries (WEB-INF/lib) and restart Tomcat and then it should work.
Also your Tomcat seems to be ancient, if possible I'd recommend getting 5.5.x or 6.x.
if you found to have required .jar existing in application, than solution to your problem might be to:
Stop Tomcat
go to %TOMCAT_HOME%/work an erase everything inside
this 'work' folder, as its name says, contains classes used for work, sometimes access to some of these files can be blocked for any reason. When I get such message this is first thing to do. Most of the time it works...