Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Including multiple JARs in javac -classpath

 
Riley Thomas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm trying to use the Str class from the jr.jar library when working with a servlet - but the second jar file listed in the command below doesn't seem to get picked up.

$ javac -cp ~/tomcat/apache-tomcat-6.0.20/lib/servlet-api.jar:~/tomcat/apache-tomcat-6.0.20/lib/jr.jar -d classes src/filename.java

Any thoughts? Thanks much.
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you re-check if the jar is in the folder that you specified. Also can you show us the code in which you are trying to access a class from that jar. Maybe you've made a mistake in capitalization or something else...
 
Riley Thomas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The jr.jar file is definitely located in the /lib directory.

Here is what I'm trying to compile:



The error is: src/NowServlet.java:4: package com.javaranch.common does not exist
import com.javaranch.common.*;
^
1 error
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15282
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Riley Thomas wrote:The jr.jar file is definitely located in the /lib directory.

I guess you mean the ~/tomcat/apache-tomcat-6.0.20/lib directory, as that's what you're putting in the classpath?

It looks like you're using a Unix-like operating system (maybe Linux or Mac OS X). Check if the jr.jar file contains what you expect. Try this command to list what's inside the jar:

jar tvf ~/tomcat/apache-tomcat-6.0.20/lib/jr.jar

It should show you a list of the files and directories in the jar file. Does it contain a directory com/javaranch/common?
 
Riley Thomas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I double-checked the file and it does contain the com/javaranch/common directory.

Correct, I am using OS X with Java 1.5.

I've found that if I reverse the order of the jar files - typing:
$ javac -cp ~/tomcat/apache-tomcat-6.0.20/lib/jr.jar:~/tomcat/apache-tomcat-6.0.20/lib/servlet-api.jar -d classes src/***.java - it returns errors regarding the javax.servlet classes; so whatever comes second in that classpath list doesn't work.
 
subodh gupta
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Please try this:


it worked for me
 
Riley Thomas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and it worked for me too - thanks!

Time to start using ANT now
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic