Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #9342 > unrolled thread
| Started by | KevinSimonson <kvnsmnsn@hotmail.com> |
|---|---|
| First post | 2011-11-01 10:39 -0700 |
| Last post | 2011-11-03 00:50 -0700 |
| Articles | 11 — 6 participants |
Back to article view | Back to comp.lang.java.programmer
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
| From | KevinSimonson <kvnsmnsn@hotmail.com> |
|---|---|
| Date | 2011-11-01 10:39 -0700 |
| Subject | Why Doesn't my Code Work with this Jar File? |
| Message-ID | <ae31e352-678a-47ae-ae12-86bd4be88413@v33g2000prm.googlegroups.com> |
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:
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" file right in
it?
Kevin Simonson
[toc] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2011-11-01 11:23 -0700 |
| Message-ID | <j8pdf1$pfc$1@dont-email.me> |
| In reply to | #9342 |
On 11/1/2011 10:39 AM, KevinSimonson wrote: > 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? Kevin Simonson Dunno, your examples looked ok to me, at first glance anyway. The javac man page has an example how to do what you are attempting. Take look at the very end and try to follow their example. I think it would be easier to get help if you could point out the difference in output from that example. <http://download.oracle.com/javase/7/docs/technotes/tools/solaris/javac.html>
[toc] | [prev] | [next] | [standalone]
| From | Arved Sandstrom <asandstrom3minus1@eastlink.ca> |
|---|---|
| Date | 2011-11-01 20:21 -0300 |
| Message-ID | <7a%rq.6927$jK1.3592@newsfe17.iad> |
| In reply to | #9342 |
On 11-11-01 02:39 PM, 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?
>
> Kevin Simonson
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.
AHS
--
You should know the problem before you try to solve it.
Example: When my son was three he cried about a problem with his hand. I
kissed it several times and asked him about the problem. He peed on his
hand.
-- Radia Perlman, inventor of spanning tree protocol
[toc] | [prev] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2011-11-01 16:59 -0700 |
| Message-ID | <942354.5.1320191986805.JavaMail.geo-discussion-forums@prln21> |
| In reply to | #9348 |
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.
--
Lew
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2011-11-01 22:14 -0400 |
| Message-ID | <4eb0a7a0$0$294$14726298@news.sunsite.dk> |
| In reply to | #9349 |
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.
Arne
[toc] | [prev] | [next] | [standalone]
| From | Arved Sandstrom <asandstrom3minus1@eastlink.ca> |
|---|---|
| Date | 2011-11-02 07:13 -0300 |
| Message-ID | <OI8sq.10800$rF5.4366@newsfe19.iad> |
| In reply to | #9354 |
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.
>
> Arne
>
That's good advice for the OP. I don't use the default package either.
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.
AHS
--
You should know the problem before you try to solve it.
Example: When my son was three he cried about a problem with his hand. I
kissed it several times and asked him about the problem. He peed on his
hand.
-- Radia Perlman, inventor of spanning tree protocol
[toc] | [prev] | [next] | [standalone]
| From | KevinSimonson <kvnsmnsn@hotmail.com> |
|---|---|
| Date | 2011-11-02 16:44 -0700 |
| Message-ID | <a503ccff-5294-4d02-b3ca-2519df2ccdb7@s32g2000prj.googlegroups.com> |
| In reply to | #9369 |
On Nov 2, 4:13 am, Arved Sandstrom <asandstrom3min...@eastlink.ca>
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.
>
> > Arne
>
> That's good advice for the OP. I don't use the default package either.
>
> 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.
>
> AHS
> --
> You should know the problem before you try to solve it.
> Example: When my son was three he cried about a problem with his hand. I
> kissed it several times and asked him about the problem. He peed on his
> hand.
> -- Radia Perlman, inventor of spanning tree protocol- Hide quoted text -
>
> - Show quoted text -
Somebody on another forum helped me see the problem. I'm working on a
Windows 7 machine, so I should have been delimiting my classpath with
semicolons, not colons! I replaced the colons with semicolons and
everything worked just fine.
Kevin Simonson
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2011-11-02 18:16 -0700 |
| Message-ID | <j8sq2a$hhg$1@dont-email.me> |
| In reply to | #9405 |
On 11/2/2011 4:44 PM, KevinSimonson wrote: > Somebody on another forum helped me see the problem. I'm working on a > Windows 7 machine, so I should have been delimiting my classpath with > semicolons, not colons! I replaced the colons with semicolons and > everything worked just fine. *Smacks forehead* The Solaris man page I linked to wasn't a clue? You couldn't say "I'm running Windows not Solaris?" OK, if you're new, it's easy to not understand there's a difference, but jeeze folks, give us something to work with here. Anytime you're running from the command line, please provide the *exact* output (and input) so we can see it, including directory listings and command prompts. You're just shorting yourself if you don't. It's even easier to do that retyping everything, like you did. Just ... wow. Please, make it easy on you and us, show us the whole thing, not some carefully elided example that removes the actual information we need.
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2011-11-02 20:00 -0400 |
| Message-ID | <4eb1d98a$0$287$14726298@news.sunsite.dk> |
| In reply to | #9369 |
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
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2011-11-03 00:47 -0700 |
| Message-ID | <fkh4b7po1dhrsim5cdkru536v8sl05mto5@4ax.com> |
| In reply to | #9342 |
On Tue, 1 Nov 2011 10:39:25 -0700 (PDT), KevinSimonson <kvnsmnsn@hotmail.com> wrote, quoted or indirectly quoted someone who said : >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: for a primer, see: http://mindprod.com/jgloss/jar.html http://mindprod.com/jgloss/jarexe.html http://mindprod.com/jgloss/jarsignerexe.html It is a lot easier to let ant/genjar build jars for you despite the initial hurdle. After you get your first script working, everything just works. You never have to think about it again. see http://mindprod.com/jgloss/ant.html http://mindprod.com/jgloss/genjar.html -- Roedy Green Canadian Mind Products http://mindprod.com Capitalism has spurred the competition that makes CPUs faster and faster each year, but the focus on money makes software manufacturers do some peculiar things like deliberately leaving bugs and deficiencies in the software so they can soak the customers for upgrades later. Whether software is easy to use, or never loses data, when the company has a near monopoly, is almost irrelevant to profits, and therefore ignored. The manufacturer focuses on cheap gimicks like dancing paper clips to dazzle naive first-time buyers. The needs of existing experienced users are almost irrelevant. I see software rental as the best remedy.
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2011-11-03 00:50 -0700 |
| Message-ID | <gqh4b7dko1ct9acjmg6enrabeb7j3l0mg8@4ax.com> |
| In reply to | #9342 |
On Tue, 1 Nov 2011 10:39:25 -0700 (PDT), KevinSimonson <kvnsmnsn@hotmail.com> wrote, quoted or indirectly quoted someone who said : >Does anybody have any idea what I'm doing wrong? See http://mindprod.com/jgloss/classpath.html Many people have written saying this essay made it all clear. I found it made no sense until I started speculating about how Javac.exe and Java.exe go about finding class files. With a rough idea of the algorithm in mind, suddenly all fell into place. -- Roedy Green Canadian Mind Products http://mindprod.com Capitalism has spurred the competition that makes CPUs faster and faster each year, but the focus on money makes software manufacturers do some peculiar things like deliberately leaving bugs and deficiencies in the software so they can soak the customers for upgrades later. Whether software is easy to use, or never loses data, when the company has a near monopoly, is almost irrelevant to profits, and therefore ignored. The manufacturer focuses on cheap gimicks like dancing paper clips to dazzle naive first-time buyers. The needs of existing experienced users are almost irrelevant. I see software rental as the best remedy.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web