• Post Reply Bookmark Topic Watch Topic
  • New Topic

add jar file to classpath programmatically  RSS feed

 
naveen yadav
Ranch Hand
Posts: 384
Java MyEclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ranchers ,

i am developing a application in which i have to log the various events of the application. So i want the "log4j-1.2.16.jar" in classpath.
Obviously i can do that manually(setting the environment variable ).But that might not work in some other machine.

how can i add a jar file in classparh through a program ?

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't modify "the classpath" after startup. You can create a new URLClassLoader and specify where it should look for its classes, but you don't need to do that.

you should never really rely on the CLASSPATH environment variable. A better way to do it--and the approach you should adopt--it to specify the classpath at startup using the -cp or -classpath command-line arg. As part of the installation process, you should create a startup script that includes the appropriate -cp element in the command line.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or package your application into a jar file and specify the classpath in the manifest file. Then either use the java -jar option or double click the jar file to start it.
 
naveen yadav
Ranch Hand
Posts: 384
Java MyEclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

once the application is complete , it would be packaged in a jar file.so it will be easy to provide classpath in the MANIFEST file.
thank you guys.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!