lollercoaster
lollercoaster

Reputation: 16523

eclipse, java & running a project from terminal

I'm used to writing java in eclipse and using it to import JARs, set up workspace, etc. however, when I want to deploy a project to my server and call it from a bash script like java Main arg1 arg2 something isn't write I get:

java.lang.ClassNotFoundException

is my classpath set wrong? what is eclipse doing behind the scenes? when I do

echo $CLASSPATH

I always get a blank line. The below (executed from bin folder) doesn't work either:

java -cp "~/Code/Java/SQL/MySQLAccess/bin;/usr/bin/java;/Users/Me/Code/Java/SQL/MySQLTest/mysql-connector-java-5.1.18-bin.jar" Main arg1 arg2 ... arg7

this gives me a java.lang.ClassNotFoundException: Main error

Upvotes: 1

Views: 3697

Answers (2)

Thomas
Thomas

Reputation: 5094

If you plan to be moving this around and deploying to potentially different servers, look into exporting your project as a jar. You can include the sql jars inside your jar and your invocation from the script will look like

java -jar Main.jar

From Eclipse, you can go to File->Export, then pick 'jar' from the menu and follow the steps.

Your manifest will be something like

Main-Class: Main
Class-Path: mysql-connector-java-5.1.18-bin.jar

Upvotes: 2

codemaster
codemaster

Reputation: 572

your class path is not set correct, you can use command java -classpath path_for_java javafile argumnets

As far as eclipse is concerned you can go to project->properties->java build path->libraries and you will get to know from where eclipse is referring to java libraries.

Upvotes: 3

Related Questions