I've been trying to make use of the SQLite jdbc class from Xerial. Every time I try to run what I have, it fails, giving me the following error:
java.lang.ClassNotFoundException: org.sqlite.Driver
I'm using Ivy, and have the following in my ivy.xml file.
<dependency org="org.xerial" name="sqlite-jdbc" rev="3.7.2"/>
This includes the sqlite-jdbc-3.7.2.jar file in my class path. I've also tried manually adding it, to no avail.
The command that runs this also contains the jar on the command line:
java -cp ... sqlite-jdbc-3.7.2.jar ...
I still get the class not found exception on the following line:
Class.forName("org.sqlite.Driver");
I've tried searching around for this particular issue, but it seems most of the time it's resolved simply by including the jar in the class path, which shouldn't be the issue here, as Eclipse lists the jar in the class path.
Can you confirm that the jar version sqlite-jdbc-3.7.2 has class org.sqlite.Driver?
You can check it by unzipping the jar file and check if unzippied folder has directory structure org\sqlite\Driver.class?
I think the sqlLite Driver name is org.sqlite.JDBC and not org.sqlite.Driver . Source.
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.
I am making a 2d game, which I have compiled into a .jar to test if it works.
When in run the jar file with java -jar command I get the following error:
Error: Could not find or load main class com.grizeldi.splatoon.Main
I know that there are many solutions here on StackOveflow, but I have tried updating java, messing with -cp... Nothing worked so far.
Code: github repo
Help anyone?
EDIT1: I have my code on a USB stick, but I have tried moving it to C: and D: but nothing worked.
EDIT2: I have added the .jar on the github.
One way is to update the Manifest with the classpath to the other jars:
Class-Path: lib.jar
An alternative is to add the contents of the jars your main jar depends on to your main jar, so you have only one jar file. Make sure you don't add the jars themselves to the main jar, as nested jars won't work.
When dealing with native libraries (.so, .dll), simply place these in the same directory as the jar. The downside of this is that you have multiple files.
In that case, it might be easiest to just add a startup script (.sh, .bat), specifying the classpath and the classname of Main, aswell as a -Djava.library.path.
There is also another way: extract the native library from the jar at runtime, save it to a temporary location, and load it explicitly. See here for more info on that.
I need an auto-incrementing integer column in Hive and stumbled across UDFRowSequence.
I created a Maven project in IntelliJ, added the .java file, and let the IDE import the dependencies. I then ran mvn package, copied the resulting .jar to a cluster node, and added the .jar resource in Hive:
hive> add file udf-row-sequence-1.0-SNAPSHOT.jar;
Added resources: [udf-row-sequence-1.0-SNAPSHOT.jar]
Unfortunately, I'm unable to create the temporary function:
hive> create temporary function row_sequence as 'com.alexwoolford.hive.udf.UDFRowSequence';
FAILED: Class com.alexwoolford.hive.udf.UDFRowSequence not found
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.FunctionTask
And yet, if I look at the contents of the .jar file I can see that the class exists:
jar tf udf-row-sequence-1.0-SNAPSHOT.jar
[...]
com/alexwoolford/hive/udf/UDFRowSequence.class
[...]
Can you see what I'm doing wrong?
The issue was caused by using add file instead of add jar, i.e.
add jar udf-row-sequence-1.0-SNAPSHOT.jar;
Even though you do "ADD JAR", sometimes even order of adding the JARS do matter, I faced this issue while adding ESRI Hive UDF jars.
add jar esri-geometry-api-1.2.jar;
add jar spatial-sdk-hive-1.0.3-SNAPSHOT.jar;
works
add jar spatial-sdk-hive-1.0.3-SNAPSHOT.jar;
add jar esri-geometry-api-1.2.jar;
Doesn't work
I have been following this tutorial accordingly.
Up to running the FirstExample class in the command prompt is when it starts to freak out for some reason. After attempting to run the following command:
java FirstExample
I get the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: FirstExample
I understand that it can't find the FirstExample class due to the classpath (for some reason) so I executed the following command:
java -cp . FirstExample
And now it returns a new exception:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Now it can't find the JDBC Driver. This confuses me because for starters, I ran the exact same coding through Eclipse and it works as expected, and secondly, I went as far as to ensure that I execute the same class file that Eclipse is executing, and the command prompt still returns exceptions. I also went as far as to put the FirstExample file in a separate folder, just for the purpose of copying and pasting the MySQL Connector into the same folder, and I still get exceptions.
I just don't understand whats going on, can someone help me please?
Many thanks.
The file path to the connector is as followed:
C:\Program Files\MySQL\mysql-connector-java-3.1.14\mysql-connector-java-3.1.14-bin.jar
Hope this helps.
For testing purposes, I have placed the FirstExample class under the following path:
C:\java
This confuses me because for starters, I ran the exact same coding through Eclipse and it works as expected
This is because in Eclipse you add the libraries to the Build Path, and it will use all the libraries specified there in the classpath automatically when running your project. This can be noted here:
In order for you to execute your project using third party libraries from command line tools, you should specify the libraries manually in your classpath explicitly:
java -cp <path/to/mysql_jar/goes/here>:. FirstExample
By your comment:
the path to the MySQL file is: C:\Program Files\MySQL\mysql-connector-java-3.1.14\mysql-connector-java-3.1.14-bin.jar (...) I have placed the FirstExample class under C:\java
This should be the command line to use:
java -cp "C:\Program Files\MySQL\mysql-connector-java-3.1.14\mysql-connector-java-3.1.14-bin.jar; ." FirstExample
Note that it is better to store all the third party libraries in a single folder within your project, usually called lib, and put a reference to there. Assuming your current folder has a lib folder and all the third party libraries are copied there, the command line would be:
java -cp "lib\*; ." FirstExample
Use the next example to add your jars to the classpath:
java -cp "jdbc.jar;lib/*" my.package.FirstExample
You need to have the class com.mysql.jdbc.Driver (and all the imported classes) in the classpath too.
You should download the jar (http://dev.mysql.com/downloads/connector/j/5.0.html) and add it to the classpath.
The ClassNotFound Exception rises when there is an issue with the class name that you have written in Class.forName() or if the package is not set to the classpath variable. Make sure that you have added the jar file to the classpath ( C:............\jarfilename.jar;).
This is applicable for any JDBC Driver and jar files. The .jar files that are added to the classpath will not be visible to IDEs, in this case, you need to add the jar files to buildpath (in eclipse) or you can also copy the jar files to ext folder available in the Java installation folder.
Also note that the jar files of the DB Softwares may vary based on the DB software version that you are using for example if you are using the Oracle 11g, you need ojdbc6.jar file, in other versions of Oracle the number changes like ojdbc14.jar etc.
I have added a piece of sharepoint code to the existing java file which was compiling and working fine. The sharepoint code that is written uses some of the external libraries. Now I need to add the external library to the existing project through ANT.
I have done a few modifications in the build.xml file and hence resolved all the compilation errors. However when the code is getting executed, I get an Error message saying "java.lang.NoClassDefFoundError: net/entropysoft/eci/spi/IContentProviderFactory". Please help me resolving this error.
Also please let me know what needs to be added in the build.xml file to resolve the error.
All the jar files is present in the directory "externallibs"
Thanks,
Rajath
You need to have all the jars in the classpath when running the application:
java -cp externallibs/* com.foo.bar.Main
If it's a Java EE web application, the build process should copy all these jars to the WEB-INF/lib folder of the generated web app structure.
java.lang.NoClassDefFoundError: net/entropysoft/eci/spi/IContentProviderFactory does not mean the class net.entropysoft.eci.spi.IContentProviderFactory is not found. It means the class that is used within this class are not found anywhere in the classpath. This error is thrown when the class loader is trying to load the class but it cannot properly initialize the class definition.
To solve this problem, you will need to look at the source code of the class net.entropysoft.eci.spi.IContentProviderFactory, usually at the import section, and determine what is the missing Java class and which library the missing class is in. Once you know you can add that library to your classpath using the answer by JB Nizet. If you run it from IDE, then you will need to add that library to you build.xml.