1

Yesterday I solved a problem with an answer here on stackoverflow. But I ended up with another problem, I will try to be clear:

I have a project folder in the /home/demo/Desktop/xlsToCsv/ directory where inside of it is the java file "xlsToCsv.java" and another directory with the external jars that I need in /home/demo/Desktop/xlsToCsv/jars.

Now I need to compile and run my program. Yesterday I ran a command that assumed that I was already inside of /home/demo/Desktop/xlsToCsv/, and the commands were:

javac -cp ".:./jars/*" xlsToCsv.java

java -cp ".:./jars/*" xlsToCsv

The problem was solved and I was able to run my program without any problems. But, my program was supposed to run from the root directory, ie, the directory where it is when I open the linux terminal without the need to make a "cd" command.

So, when I open the terminal the path to the .java file is:

/home/demo/Desktop/xlsToCsv/

And the path to jars folder is:

/home/demo/Desktop/xlsToCsv/jars/*

Can someone explain to me what I have to do, and the reason so? Because more that run the program, I want to know the reasons and understand the classpath mechanism in java.

1 Answer 1

1

Avoid using relative classpath. and instread of "./jars/" use the absolute path "/home/demo/Desktop/xlsToCsv/jars/"

EDIT:

javac -cp "/home/demo/Desktop/xlsToCsv/jars/*" /home/demo/Desktop/xlsToCsv/xlsToCsv.java

java -cp "/home/demo/Desktop/xlsToCsv/:/home/demo/Desktop/xlsToCsv/jars/*" xlsToCsv
Sign up to request clarification or add additional context in comments.

6 Comments

So, for you, what has to be the full commands? For compile and run. Understanding that the path to the file is at /home/demo/Desktop/xlsToCsv/xlsToCsv.java
It's working now, I will put in two comments the command that I used to compile and run the file.
Compile --> javac -cp "/home/demo/Desktop/xls_to_csv/jars/*" /home/demo/Desktop/xls_to_csv/xlsToCsv.java
Run --> java -cp "/home/demo/Desktop/xls_to_csv/:/home/demo/Desktop/xls_to_csv/jars/*" xlsToCsv
yes I forgot to include the classpath for the directory
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.