2

How to set the classpath using a java program without setting it form command line?

2
  • 6 ways to set the classpath: javahowto.blogspot.com/2006/06/… Commented May 27, 2010 at 12:32
  • @MYYN - it's four to me, the first two are equivalent and the 'current directory' thing is too trivial and limited ;) Commented May 27, 2010 at 12:36

2 Answers 2

2

There are three common ways to set the classpath:

  • define the environment variable CLASSPATH
  • add -cp argument to the java call
  • declare the classpath in a jar manifest file.

I recommend the second option. Just write a shell script or batch file that executes java with the classpath and the class containing the main method.

Sign up to request clarification or add additional context in comments.

Comments

1

Simplest ways to set classpath

  • from the command line
  • from the environment ($CLASSPATH)
  • if your program is packed in a .jar, from the Class-Path: field in the MANIFEST.MF

Comments

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.