Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #9407
| Date | 2011-11-02 20:00 -0400 |
|---|---|
| From | Arne Vajhøj <arne@vajhoej.dk> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Why Doesn't my Code Work with this Jar File? |
| References | <ae31e352-678a-47ae-ae12-86bd4be88413@v33g2000prm.googlegroups.com> <7a%rq.6927$jK1.3592@newsfe17.iad> <942354.5.1320191986805.JavaMail.geo-discussion-forums@prln21> <4eb0a7a0$0$294$14726298@news.sunsite.dk> <OI8sq.10800$rF5.4366@newsfe19.iad> |
| Message-ID | <4eb1d98a$0$287$14726298@news.sunsite.dk> (permalink) |
| Organization | SunSITE.dk - Supporting Open source |
On 11/2/2011 6:13 AM, Arved Sandstrom wrote:
> On 11-11-01 11:14 PM, Arne Vajhøj wrote:
>> On 11/1/2011 7:59 PM, Lew wrote:
>>> 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<AbcCl> 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.
>>
>> When one is ready to build jar files, then it may be time to drop
>> default package completely.
>>
> That's good advice for the OP.
:-)
> I don't use the default package either.
I would have fallen down my chair if you had said you did.
> In this case, though, with the imported classes being in named packages,
> various quirks of the default package do not interfere with compiling
> and running the OP's example. Hence it would be interesting to find out
> what is causing the OP's problem.
It was all side notes.
Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why Doesn't my Code Work with this Jar File? KevinSimonson <kvnsmnsn@hotmail.com> - 2011-11-01 10:39 -0700
Re: Why Doesn't my Code Work with this Jar File? markspace <-@.> - 2011-11-01 11:23 -0700
Re: Why Doesn't my Code Work with this Jar File? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-11-01 20:21 -0300
Re: Why Doesn't my Code Work with this Jar File? Lew <lewbloch@gmail.com> - 2011-11-01 16:59 -0700
Re: Why Doesn't my Code Work with this Jar File? Arne Vajhøj <arne@vajhoej.dk> - 2011-11-01 22:14 -0400
Re: Why Doesn't my Code Work with this Jar File? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-11-02 07:13 -0300
Re: Why Doesn't my Code Work with this Jar File? KevinSimonson <kvnsmnsn@hotmail.com> - 2011-11-02 16:44 -0700
Re: Why Doesn't my Code Work with this Jar File? markspace <-@.> - 2011-11-02 18:16 -0700
Re: Why Doesn't my Code Work with this Jar File? Arne Vajhøj <arne@vajhoej.dk> - 2011-11-02 20:00 -0400
Re: Why Doesn't my Code Work with this Jar File? Roedy Green <see_website@mindprod.com.invalid> - 2011-11-03 00:47 -0700
Re: Why Doesn't my Code Work with this Jar File? Roedy Green <see_website@mindprod.com.invalid> - 2011-11-03 00:50 -0700
csiph-web