Search code examples
javajarjavac

Running a java program through command line


I am running a Java program with the following command:

java -cp .:./* com.bot.fix.botclient

All the jar files are in the same directory. It works FINE! But what if I want to run it from a different folder?

The full location of the java program is: FIX/fixprog/src/com/fix/botclient

But if I try to run:

java -cp FIX/fixprog/src/* FIX/fixprog/src/com.bot.fix.botclient

I get:

Error: Could not find or load main class FIX.fixprog.src.com.bot.fix.botclient

What am I doing wrong? How can I run the same Java program but not in the same directory?


Solution

  • If you have only jar files try:

    java -cp FIX/fixprog/src/* com.bot.fix.botclient
    

    If you have also classes you should try:

    java -cp FIX/fixprog/src/*:FIX/fixprog/src/ com.bot.fix.botclient
    

    If both did not work perhaps you shoud use absolut path with disk unit if you are using windows.