aspose file tools*
The moose likes Beginning Java and the fly likes Including multiple JARs in javac -classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Including multiple JARs in javac -classpath" Watch "Including multiple JARs in javac -classpath" New topic
Author

Including multiple JARs in javac -classpath

Riley Thomas
Greenhorn

Joined: Aug 08, 2009
Posts: 13
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

Joined: Aug 03, 2008
Posts: 9313
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Riley Thomas
Greenhorn

Joined: Aug 08, 2009
Posts: 13
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

Joined: Aug 16, 2005
Posts: 14352
    
  22

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

Joined: Aug 08, 2009
Posts: 13
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

Joined: Jul 23, 2007
Posts: 203
Hi,

Please try this:


it worked for me


http://subodh-gupta.blogspot.com
Riley Thomas
Greenhorn

Joined: Aug 08, 2009
Posts: 13
...and it worked for me too - thanks!

Time to start using ANT now
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Including multiple JARs in javac -classpath