File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Compiling using a JAR file in the classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Compiling using a JAR file in the classpath" Watch "Compiling using a JAR file in the classpath" New topic
Author

Compiling using a JAR file in the classpath

richard rehl
Ranch Hand

Joined: May 21, 2007
Posts: 36
Trying to get a class to compile here, need some help. This is from SB SCJP5, Ch. 10, question 12. Given two files:

and the following sub-directory structure:
test
|--UseKit.class
|
com
|--KitJar.jar

I've compiled Kit.class and made KitJar.jar, confirmed by
jar -tf KitJar.jar
META-INF/
META-INF/MANIFEST.MF
pkg/
pkg/Kit.class

Now, here's the problem... trying to compile UseKit.java. If I'm in directory test, I thought that i would compile with
javac -cp com/KitJar.jar UseKit.java

but get the error
UseKit.java:1: '.' expected
import pkg;
^
1 error

Trying to decipher the error, it looks like the compiler can't search the current directory... so I also tried
javac -cp com/KitJar.jar:. UseKit.java

and get the same error. What am I doing wrong?
Larry Olson
Ranch Hand

Joined: Feb 03, 2009
Posts: 142
Your import statement seems to be wrong to me.

Are you sure "import pkg;" is correct?

Shouldn't it be

"import pkg.*" or "import pkg.Kit"; or something like that?

That seems to be the error to me.
richard rehl
Ranch Hand

Joined: May 21, 2007
Posts: 36
Absolutely right! Thank you!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compiling using a JAR file in the classpath