Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAR Files and Class Path

 
munna next
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am compiling the JAVA File which has to have classpath reference for the file servlet-api.jar.
I have this file in c:\program files\tomcat\lib\servlet-api.jar So I am compiling like

C:\javaexample> javac -classpath c:\program files\tomcat\lib\servlet-api.jar myJavaSource.java

When I execute the above statement I am getting any error "ClassNotFoundException"

But when I put the jar file in a folder which is not having space (Pl see "Program files" has space in between)
Like,

C:\javaservletsource\servlet-api.jar and compile like below

C:\javaexample> javac -classpath C:\javaservletsource\servlet-api.jar myJavaSource.java

It is getting compiled. So my question is that "Is that the referenced class or jar files should not be in a folder which is having space (like Program Files)?

Thanks for clarification on this.
 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a batch file that will execute the java command for you.

In that batch file, set your CLASSPATH variable.

Something like this:


That way you can add to the class path easily enough in the future.
 
Jayesh Lalwani
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this
javac -classpath "c:\program files\tomcat\lib\servlet-api.jar" myJavaSource.java
 
munna next
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's working. Thanks for the tip.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic