Forums Register Login

Including multiple JARs in javac -classpath

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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...
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Hi,

Please try this:


it worked for me
+Pie Number of slices to send: Send
...and it worked for me too - thanks!

Time to start using ANT now
Something must be done about this. Let's start by reading this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 15762 times.
Similar Threads
Stuck on MVC BeeServlet Example
Problem running Struts Application
problem with class path
Compile problem not finding package javax.servlet.http
Issues Compiling With Javac
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:12:27.