aspose file tools*
The moose likes Java in General and the fly likes Adding a package statement makes jar not visible during runtime? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Adding a package statement makes jar not visible during runtime?" Watch "Adding a package statement makes jar not visible during runtime?" New topic
Author

Adding a package statement makes jar not visible during runtime?

JJ DILLON
Greenhorn

Joined: Apr 18, 2006
Posts: 8
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
JJ DILLON
Greenhorn

Joined: Apr 18, 2006
Posts: 8
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

Joined: Apr 18, 2006
Posts: 8
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

Joined: Apr 18, 2006
Posts: 8
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

Joined: Jan 17, 2006
Posts: 1296
What do you mean when you say:

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


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
JJ DILLON
Greenhorn

Joined: Apr 18, 2006
Posts: 8
It complies but does not fix the runtime problem. Thanks for asking.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding a package statement makes jar not visible during runtime?