0

I found the solution, and this question was in fact a duplicate, but of a completely different question. If you have a similar problem, check out - ant, jar files, and Class-Path oh my

First:

I have read other posts with the same title (i think all of them). I do know that i need to include mysql-connector-java in classpath, and i am sure i have done this.

Also, i am not asking about suggestions for other tools.

Now, I have the following within the code:

        System.out.println(System.getenv("CLASSPATH"));
        Class.forName("com.mysql.jdbc.Driver").newInstance();

The output is:

/home/volodya/OtherPeople/00insert/java/lib/mysql-connector-java-5.1.36-bin.jar
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

I can do:

$ ls -l $CLASSPATH
-rw-r--r-- 1 volodya volodya 972009 Jun 19 22:26 /home/volodya/OtherPeople/00insert/java/lib/mysql-connector-java-5.1.36-bin.jar

I can do:

$ java -cp lib/mysql-connector-java-5.1.36-bin.jar -jar dist/memorial.jar 

To answer the question about the location of the console:

$ ls -l lib/
total 952
-rw-r--r-- 1 volodya volodya 972009 Jun 19 22:26 mysql-connector-java-5.1.36-bin.jar

But it produces exactly the same output. I am very close to unzipping the jar and just putting all the .class files within my own.

Community
  • 1
  • 1
v010dya
  • 5,296
  • 7
  • 28
  • 48
  • @JarrodRoberson How is this question remotely similar to the one it now links to? Did you read it before you marked it? – v010dya Oct 09 '15 at 18:29
  • Did **you** read the **accepted answer**, if you did, you would know why what you are doing is incorrect. It is spelled out completely for you if you read for comprehension. –  Oct 09 '15 at 18:31
  • @JarrodRoberson "In your case you're using an IDE." Where did i even hint at that? – v010dya Oct 09 '15 at 18:33
  • every `java.lang.ClassNotFoundException` without exception is caused by the exact same thing, the class that is being searched for is not on the classpath. **Regardless of what you think you have done and its correctness, the fact renames the JVM can not find the specified class*** this is no mystery. –  Oct 09 '15 at 18:34
  • Read the very **first sentence** of the accepted answer **for comprehension**, that means read just that sentence and stop and try and comprehend what it says in its entirety without assuming you already think you know what it means. –  Oct 09 '15 at 18:34
  • @JarrodRoberson "The CLASSPATH environment variable is only used by the java.exe command and even then only when used without any of the -cp, -classpath, -jar arguments." So when i say that i ran `$ java -cp lib/mysql-connector-java-5.1.36-bin.jar -jar dist/memorial.jar` it clearly takes that out of any picture, since i'm providing it inside -cp. Like i have said, i have read existing answers – v010dya Oct 09 '15 at 18:38
  • @JarrodRoberson "every java.lang.ClassNotFoundException without exception is caused by the exact same thing". 99% of the posts here ask that same question "What have i done wrong" – v010dya Oct 09 '15 at 18:41
  • and they answer is you have not put the required class on the classpath because those 99% of the people do not read to understand what they are doing, they just want someone to spoon feed them a solution that is highly localized and most likely a PEBKAC, hence the flood of duplicates. That is what a duplicate is, the same question with the same solution/answer; asked in a different manner or slightly different details does not make it a **not** a duplicate. –  Oct 09 '15 at 18:42
  • 2
    @Volodya What is current location of console? Are you sure that it contains `lib/mysql-connector-java-5.1.36-bin.jar`? – Pshemo Oct 09 '15 at 18:44
  • `System.out.println(System.getenv("CLASSPATH"));` is an invalid test or proof of anything because it is **not** used when over ridden at the command line with `-cp/-classpath` or `-jar` so you are confused on what you are trying to prove or test to begin with. I doubt that the `.jar` is where you are telling it to look, and you are not including the existing classpath so it will be the **only** thing on the classpath if you finally get the location correct. All solutions from all the duplicates. –  Oct 09 '15 at 18:47
  • @Pshemo Please see the edit – v010dya Oct 09 '15 at 18:47
  • if you used a tool like Maven to manage dependencies automatically you would not have these types of **highly localized** human errors. –  Oct 09 '15 at 18:49
  • @JarrodRoberson Please see the edit – v010dya Oct 09 '15 at 18:52

0 Answers0