• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why Doesn't my Code Work with this Jar File?  RSS feed

 
Kevin Simonson
Ranch Hand
Posts: 223
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having a nasty time figuring out how to use JAR files. I have a directory "Jrs" that includes an "abc" directory and a "def" directory. In directory "abc" I have a single file called "AbcCl.java" coded:

and in directory "def" I have a single file called "DefCl.java" coded:

Back in "Jrs" I have a file "UseEm.java" coded:

Then I executed "javac UseEm.java", which created three class files, an "abc\AbcCl.class", a "def\DefCl.class", and a "UseEm.java". Finally I created two jar files with commands "jar -cf abc.jar abc" and "jar -cf def.jar def".

Then I created a "Jrs2" directory, a sibiling to "Jrs", and copied to it "UseEm.java" and the two JAR files. In that "Jrs2" directory I typed in the command "javac -cp abc.jar:def.jar", and as a result got a whole bunch of error messages. I was kind of expecting that.

At that point I typed in "jar -xf abc.jar" which extracted the "abc" directory, and I thought that therefore I should be able to compile "UseEm.java" with the command "javac -cp .:def.jar UseEm.java". But when I tried it I got error messages:

UseEm.java:1: package abc does not exist
import abc.AbcCl;
^
UseEm.java:2: package def does not exist
import def.DefCl;
^
UseEm.java:8: cannot find symbol
symbol : class AbcCl
location: class UseEm
AbcCl ac = new AbcCl();
^
UseEm.java:8: cannot find symbol
symbol : class AbcCl
location: class UseEm

AbcCl ac = new AbcCl();
^
UseEm.java:9: cannot find symbol
symbol : class DefCl
location: class UseEm
DefCl dc = new DefCl();
^
UseEm.java:9: cannot find symbol
symbol : class DefCl
location: class UseEm
DefCl dc = new DefCl();
^
6 errors

Does anybody have any idea what I'm doing wrong? Why can't I get the code I need to compile out of this JAR file? And why in the world can't my compiler see the <AbcCl> class? The "abc" directory is right there, with an "AbcCl.class" and an "AbcCl.java" right in it?

Kevin Simonson
 
Campbell Ritchie
Marshal
Posts: 56540
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How did you add that .jar to your classpath?
 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm confused. You put those backslashes into your class file names, which suggests you're using Windows. But then you used colons to separate entries in your classpath, which suggests you're using some Unix variety. So which is it?
 
Kevin Simonson
Ranch Hand
Posts: 223
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I'm confused. You put those backslashes into your class file names, which suggests you're using Windows. But then you used colons to separate entries in your classpath, which suggests you're using some Unix variety. So which is it?

That was the problem! I'm working on a Windows 7 machine. I changed my colons to semicolons and everything worked just fine. Thanks!

Kevin Simonson
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!