Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Using javac and java commands in classpath  RSS feed

 
cle tan
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I always did was to put the additional jars in Java/jdk 1.70_04 /jre/ext, and Java/jre7/ext
and run in command prompt
javac Package1/*.java
and run using java Package1/MainClass

Now I want to use a different approach instead of running my class based on the jars in the ext folder, I want to put my jars in a separate lib folder

But I tried using
java -cp "lib/*" Package1.MainClass

But I received
Error: Could not find or load main class Package1.MainClass

May I know what is the correct way of running java class?
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the Package1.MainClass class in one of the jar files ? If not you also need to include the directory that contains the Package1 directory in your classpath.
The reason it worked previously is that if you don't specify a classpath on the command line then it uses the classpath specified in the CLASSPATH environment variable if it exists or the current directory if it doesn't.
 
cle tan
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for me, I put the main class in the lib

then I run this command

java -cp "Jar1.jar";"lib/*"; Package1.MainClass

and it worked

for javac I put all the required jars in ext as I felt it will be too troublesome to type

javac -cp "Jar1.jar,jar2.jar,jar3.jar..........

why there isn't something that I can put as

javac -cp "lib/*" ; Package1.MainClass
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should not be adding anything to the Java installation tree, except for certain specialized libraries (mainly related to crypto stuff, I think) that explicitly tell you they have to be placed there. All your own classes and third party libraries should go somewhere else.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!