Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.news-service.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: Why Doesn't my Code Work with this Jar File? Date: Tue, 1 Nov 2011 16:59:46 -0700 (PDT) Organization: http://groups.google.com Lines: 83 Message-ID: <942354.5.1320191986805.JavaMail.geo-discussion-forums@prln21> References: <7a%rq.6927$jK1.3592@newsfe17.iad> Reply-To: comp.lang.java.programmer@googlegroups.com NNTP-Posting-Host: 2620:0:1000:2404:224:d7ff:fe69:5838 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1320192312 29982 127.0.0.1 (2 Nov 2011 00:05:12 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 2 Nov 2011 00:05:12 +0000 (UTC) In-Reply-To: <7a%rq.6927$jK1.3592@newsfe17.iad> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2620:0:1000:2404:224:d7ff:fe69:5838; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 X-Google-Web-Client: true Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9349 Arved Sandstrom wrote: > KevinSimonson wrote: >> 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: >> >> package abc; >> public class AbcCl >> { >> public String toString () >> { >> return "[AbcCl Object]"; >> } >> } >> >> and in directory "def" I have a single file called "DefCl.java" coded: >> >> package def; >> public class DefCl >> { >> public String toString () >> { >> return "[DefCl Object]"; >> } >> } >> >> Back in "Jrs" I have a file "UseEm.java" coded: >> >> import abc.AbcCl; >> import def.DefCl; >> >> public class UseEm >> { >> public static void main ( Strin[] arguments) >> { >> AbcCl ac = new AbcCl(); >> DefCl dc = new DefCl(); >> System.out.println( "ac == " + ac + ", dc == " + dc + '.'); >> } >> } >> >> 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: >[ SNIP ] > >> 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 class? The "abc" directory is >> _right there_, with an "AbcCl.class" and an "AbcCl.java" file right in >> it? > > With the exception of the manual typo in UseEm.java, the only thing > wrong with your procedure is that you should also have supplied '.' as > part of the classpath on your first javac attempt with the JARs > (otherwise javac doesn't know where UseEm.java is). But that absolutely > should have worked. > > I know it should have because I just now did it. I always do just to > make sure there's nothing catching me out in a question. The only > difference is that I don't include *.java files in JARs. > > Side note: 'jar' does not need a hyphen in front of its arguments, and > never has. As another side note, do not mix classes that are in packages with classes that are not. -- Lew