-
Problem accessing a class in a jar file
I created a public class with 2 static methods (string utilities) which work
fine when this class file is in the same directory as the class file which
is using an import statement to access it.
So the next step seemed to be to put my string utility class in a myutils.jar
file and store it in the jre\lib\ext directory so that I would be able to
reference it in an import statement from other class files.
A new class file that imports from and references the class in myutils.jar
compiles fine, but running it at the command line gives a "NoClassDefFoundError".
(This is using jdk1.3)
Any thoughts, ideas, suggestions?
Thanks in advance
dm
-
Re: Problem accessing a class in a jar file
When you say running "it" at the command line, I assume you are talking
about the class file that referenced your string utilities, and I assume
that this class was the one referred to in the NoClassDefFoundError,
although you didn't mention that. If my assumptions are correct, then you
need to fix your classpath so that java can find the class you are trying to
run; this would have nothing to do with any classes that class might happen
to refer to.
PC2
"dm" <dmottolo@synap.com> wrote in message news:3b1ee2ba$1@news.devx.com...
>
>
> I created a public class with 2 static methods (string utilities) which
work
> fine when this class file is in the same directory as the class file which
> is using an import statement to access it.
>
> So the next step seemed to be to put my string utility class in a
myutils.jar
> file and store it in the jre\lib\ext directory so that I would be able to
> reference it in an import statement from other class files.
>
> A new class file that imports from and references the class in myutils.jar
> compiles fine, but running it at the command line gives a
"NoClassDefFoundError".
>
> (This is using jdk1.3)
>
> Any thoughts, ideas, suggestions?
> Thanks in advance
> dm
-
Re: Problem accessing a class in a jar file
Thanks for your reply. The class which is being run from the command line
is SortTest.class (>java SortTest) and it references a method from the class
in my jar file. The NoClassDefFoundError occurs at SortTest.main(SortTest.java:16)
-- so it is finding the main class and getting to line 16 where it attempts
to use a static method that is in the jar file.
dm
"Paul Clapham" <pclapham@core-mark.com> wrote:
>When you say running "it" at the command line, I assume you are talking
>about the class file that referenced your string utilities, and I assume
>that this class was the one referred to in the NoClassDefFoundError,
>although you didn't mention that. If my assumptions are correct, then you
>need to fix your classpath so that java can find the class you are trying
to
>run; this would have nothing to do with any classes that class might happen
>to refer to.
>
>PC2
>
>"dm" <dmottolo@synap.com> wrote in message news:3b1ee2ba$1@news.devx.com...
>>
>>
>> I created a public class with 2 static methods (string utilities) which
>work
>> fine when this class file is in the same directory as the class file which
>> is using an import statement to access it.
>>
>> So the next step seemed to be to put my string utility class in a
>myutils.jar
>> file and store it in the jre\lib\ext directory so that I would be able
to
>> reference it in an import statement from other class files.
>>
>> A new class file that imports from and references the class in myutils.jar
>> compiles fine, but running it at the command line gives a
>"NoClassDefFoundError".
>>
>> (This is using jdk1.3)
>>
>> Any thoughts, ideas, suggestions?
>> Thanks in advance
>> dm
>
>
-
Re: Problem accessing a class in a jar file
That means your jar file isn't in your classpath. From what you've said it
should be, so run this program:
import java.util.*;
public class PropertiesTest extends Object
{
static public void main(String args[]){
System.getProperties().list(System.out);
System.exit(0);
}
}
It will display all of your system properties. Look for the ones called
"java.class.path" and "java.ext.dirs" and see if they are what you think
they should be.
PC2
"dm" <dmottolo@synap.com> wrote in message news:3b1ff059$1@news.devx.com...
>
> Thanks for your reply. The class which is being run from the command line
> is SortTest.class (>java SortTest) and it references a method from the
class
> in my jar file. The NoClassDefFoundError occurs at
SortTest.main(SortTest.java:16)
> -- so it is finding the main class and getting to line 16 where it
attempts
> to use a static method that is in the jar file.
>
> dm
-
Re: Problem accessing a class in a jar file
Thanks very much for the code - that identified the problem. The java.ext.dirs
points to a different directory when PropertiesTest is run at the command
line vs. run from my editor TextPad. Moving the jar file into the correct
ext dir worked.
Various Java-related software installs (JDK, TextPad, and VisualAge for Java)
seem to have confused the machine a bit (and its owner). Naturally, I'd
prefer everything to use the same ext dir. How/where do you set java.ext.dirs
for JDK1.3 on WinNT? (and if you know for TextPad or VAJ?)
dm
"Paul Clapham" <pclapham@core-mark.com> wrote:
>That means your jar file isn't in your classpath. From what you've said
it
>should be, so run this program:
>
>import java.util.*;
>
>public class PropertiesTest extends Object
>{
> static public void main(String args[]){
>
> System.getProperties().list(System.out);
> System.exit(0);
> }
>}
>
>It will display all of your system properties. Look for the ones called
>"java.class.path" and "java.ext.dirs" and see if they are what you think
>they should be.
>
>PC2
>
>"dm" <dmottolo@synap.com> wrote in message news:3b1ff059$1@news.devx.com...
>>
>> Thanks for your reply. The class which is being run from the command
line
>> is SortTest.class (>java SortTest) and it references a method from the
>class
>> in my jar file. The NoClassDefFoundError occurs at
>SortTest.main(SortTest.java:16)
>> -- so it is finding the main class and getting to line 16 where it
>attempts
>> to use a static method that is in the jar file.
>>
>> dm
>
>
>
-
Re: Problem accessing a class in a jar file
You set java.ext.dirs for JDK 1.3 by installing it (last). VAJ doesn't
exactly have the "extensions directory" concept, unless you consider your
workspace to be analogous. (I may be wrong about this, I've only been using
it for a month or so and the online help can only be described as
appallingly shockingly astoundingly bad.) No idea about TextPad, sorry.
PC2
"dm" <dmottolo@synap.com> wrote in message news:3b20fa5a$1@news.devx.com...
>
> Thanks very much for the code - that identified the problem. The
java.ext.dirs
> points to a different directory when PropertiesTest is run at the command
> line vs. run from my editor TextPad. Moving the jar file into the correct
> ext dir worked.
>
> Various Java-related software installs (JDK, TextPad, and VisualAge for
Java)
> seem to have confused the machine a bit (and its owner). Naturally, I'd
> prefer everything to use the same ext dir. How/where do you set
java.ext.dirs
> for JDK1.3 on WinNT? (and if you know for TextPad or VAJ?)
>
> dm
-
Re: Problem accessing a class in a jar file
Thanks again for the help. Much appreciated!
dm
"Paul Clapham" <pclapham@core-mark.com> wrote:
>You set java.ext.dirs for JDK 1.3 by installing it (last). VAJ doesn't
>exactly have the "extensions directory" concept, unless you consider your
>workspace to be analogous. (I may be wrong about this, I've only been using
>it for a month or so and the online help can only be described as
>appallingly shockingly astoundingly bad.) No idea about TextPad, sorry.
>
>PC2
>
>"dm" <dmottolo@synap.com> wrote in message news:3b20fa5a$1@news.devx.com...
>>
>> Thanks very much for the code - that identified the problem. The
>java.ext.dirs
>> points to a different directory when PropertiesTest is run at the command
>> line vs. run from my editor TextPad. Moving the jar file into the correct
>> ext dir worked.
>>
>> Various Java-related software installs (JDK, TextPad, and VisualAge for
>Java)
>> seem to have confused the machine a bit (and its owner). Naturally, I'd
>> prefer everything to use the same ext dir. How/where do you set
>java.ext.dirs
>> for JDK1.3 on WinNT? (and if you know for TextPad or VAJ?)
>>
>> dm
>
>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|