• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding a package statement makes jar not visible during runtime?

 
JJ DILLON
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I have been using java for a while now but not using the package
statement. (Gasp) I know. Well I am trying to purge myself of this
nasty habit but any program that imports something from a non-system
jar (ie xercies,jt400) etc. gives me a java.lang.NoClassDefFoundError:
at runtime. If I take out the package statement and run it, all is
well. Without any changes to the classpath. Any thoughts. This is on
an AS400 or ISeries or whatever the marketers have come up with lately.

The Java version is 1.4.2 OS V5R1.

-- JJ
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to include those jar files on your runtime classpath, of course, but you also need to build the jars properly. Java will look for a class foo.bar.ClassName in a file named ClassName.class in a directory "bar" in a directory "foo" -- i.e., it will look for foo/bar/ClassName.class. You need to build your jars this way -- i.e., don't just put ClassName.class into the jar, but the "foo" and "bar" directories, too.
 
JJ DILLON
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The jar files I am including are built (presumably) by people who know what their doing (ie not like me) for example jt400.jar is written by the JTOPEN project. So I do not think this is it.

Someone else suggested that I had to compile it the same way as I will run it. So for example if the package name is companyname.utils then I would need to be in the parent directory of companyname and use javac companyname.utils.Test and then run it using java companyname.utils.Test

normally I would make /companyname/utils/ my current directory and then do a javac Test.java to compile, but run it from / using java companyname.utils.Test This does work but only if I do not access any object from the jt400.jar

Again if I use the default package and run it from the utils directory everything works fine.

Any further thoughts?

p.s. I can not compile as suggest above I get

javac companyname.utils.Test
javac: invalid flag: companyname.utils.Test

or
javac companyname.utils.Test.java
error: cannot read: companyname.utils.Test.java

or
javac companyname/utils/Test.java
which works but does no fix the problem.

I am thinking this may be an AS400 specific problem, I do not have this problem on the pc.
 
JJ DILLON
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my Test Session:

$
echo $CLASSPATH
.:/QIBM/ProdData/Java400/:/QIBM/ProdData/Java400/jtopen_5_0/lib/jt400.jar
$
pwd
/QIBM/ProdData/Java400
$
cat ./companyname/utils/Test.java
/*
* Test.java Without Package.
*/
import com.ibm.as400.access.AS400;
public class Test{
public static void main(String[] args)
{
AS400 iseries = new AS400();
System.out.println(iseries.toString());
}
}
$
cat ./companyname/utils/Testp.java
/*
* Testp.java WITH Package
*/
package companyname.utils;
import com.ibm.as400.access.AS400;
public class Testp{
public static void main(String[] args)
{
AS400 iseries = new AS400();
System.out.println(iseries.toString());
}
}$
javac companyname/utils/Test.java
$
javac companyname/utils/Testp.java
$
cd companyname/utils
$

Without package It works!

java Test
AS400 (system name: '' user ID: ''):com.ibm.as400.access.AS400@378ef555
$
cd ..
$
cd ..
$

With package It Doesn't

java companyname.utils.Testp
java.lang.NoClassDefFoundError: com/ibm/as400/access/AS400
at java.lang.Throwable.<init>(Throwable.java:195)
at java.lang.LinkageError.<init>(LinkageError.java:36)
at java.lang.NoClassDefFoundError.<init>(NoClassDefFoundError.java:40)
at companyname.utils.Testp.main(Testp.java:12)
$

Any suggestions would be greatly appreciated.
 
JJ DILLON
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since no one appears to be jumping at the bit here as to what might be going on here perhaps someone could give me some advise as to what to try next? Are there any AS/400-Iseries gurus out there? It looks like this might be a platform dependent problem. Any help would be appreciated. Thanks.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean when you say:

javac companyname/utils/Test.java
which works but does no fix the problem.
 
JJ DILLON
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It complies but does not fix the runtime problem. Thanks for asking.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic