2

I downloaded example.jar and I can type java -jar example.jar from within the directory where it is located and it works.

The problem is that I need to be able to call it from elsewhere without typing the full path. Is it possible?

I tried adding it to $CLASSPATH like this: export CLASSPATH=$CLASSPATH:/Path/to/Directory:/Path/to/Directory/example.jar with no success.

1
  • 1
    Write a shell script, put that somewhere accessible from within the PATH element; use the full path to the Jar from within the script instead Commented Mar 26, 2018 at 21:44

1 Answer 1

1

Yes. Option 1. Using the CLASSPATH you have set, however you would have to specify the fully qualified main-class from the jar

java com.mypackage.MyMain 

As long as com.mypackage.MyMain is on the CLASSPATH and contains a valid main method, that will run it.

Option 2. Create a bash shell script to run it (note that this is really providing the full path to the java command)

#!/usr/bin/env bash export JARFILE="/Path/to/Directory/example.jar" java -jar $JARFILE 
Sign up to request clarification or add additional context in comments.

5 Comments

Yes, I thought about creating another script for calling it, but I was getting mad about the CLASSPATH thing. I am not sure I understood your explanation. How should I know the name of the main class file?
@FrancescoPegoraro Check the Main-Class in the manifest
Ok, I now know the main: com.vftlite.main.Menu what now?
@FrancescoPegoraro Put that jar file in your CLASSPATH. Then java com.vftlite.main.Menu
I tried it yesterday and didn't work, now is working. Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.