-1

I can successfully execute from Eclipse IDE, but when trying to execute a java .class file from Terminal I'm having some issues.

Pertinent files reside as:

~/dropbox/workspace/mysqltut/src/zetcode/Version.java ~/dropbox/workspace/mysqltut/src/zetcode/Version.class ~/dropbox/workspace/mysqltut/lib/mysql-connector-java-5.1.30-bin.jar

After navigating to ~/dropbox/workspace/mysqltut/src/ in Terminal, I run the following:

java -cp .:lib/mysql-connector-java-5.1.30-bin.jar zetcode/Version

May 02, 2014 10:54:31 PM zetcode.Version main
SEVERE: No suitable driver found for jdbc:mysql://localhost:3306/
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/
    at java.sql.DriverManager.getConnection(DriverManager.java:596)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at zetcode.Version.main(Version.java:24)

Is something wrong with my syntax/file structure or is something not installed properly?

dbconfession
  • 1,147
  • 2
  • 23
  • 36

1 Answers1

0

I think you should navigate to ~/dropbox/workspace/mysqltut/ and start your commands from it. Use semicolon as the delimiter between the jar files or class folders

java -cp lib/mysql-connector-java-5.1.30-bin.jar;src zetcode.Version

The delimiter is OS dependent. It is discussed here Classpath does not work under linux

Community
  • 1
  • 1
ka3ak
  • 2,435
  • 2
  • 30
  • 57
  • that's not proper syntax though. The syntax is `java [options] [source class]` If I use what you suggested, it comes back with `-bash: src: command not found.` `java -cp lib/mysql-connector-java-5.1.30-bin.jar ; src/zetcode/Version` comes back with `-bash: src/zetcode/Version: No such file or directory` And if I remove the semicolon altogether and use `java -cp lib/mysql-connector-java-5.1.30-bin.jar src/zetcode/Version` I get Error: Could not find or load main class src.zetcode.Version` I believe u have to start in the package folder. Any ideas? – dbconfession May 03 '14 at 05:12
  • @Stuart Kuredjian If Version.class is in src/zetcode and fully qualified name of this class is zetcode.Version my suggestion should work. – ka3ak May 03 '14 at 08:03
  • Right. Which is why I posted the results of I got when I did what you recommended. Obv. I'm missing something. It executes fine in Eclipse, just not from the terminal. Can you put a folder on your desktop, run it from command line and if it works, zip it as is and put it on dropbox so I can try in the same exact environment as you? – dbconfession May 03 '14 at 16:04
  • ka4ak can you just recheck the part after the semicolon in your suggestion? Because when I do it your way it says "-bash: src: command not found. So it's reading "src" as a command and not as you intended. thanks. – dbconfession May 03 '14 at 16:11
  • @Stuart Kuredjian Sorry, I've forgotten that the delimiter is OS dependent. Answer has been edited. – ka3ak May 03 '14 at 16:58