V
voger
Hello everyone
Tonight i ran into this
http://devcentral.iticentral.com/articles/Java/default.php (it requires
login). It has one tutorial about using custom class loaders.
My environment is Eclipse ide 3.1 which runs with java1.5 configured to
use j2sdk1.4.2_09.
As tutorial suggests i create the file structure as below (with a little
modification)
FileClassLoader
|-bin
|-src
|- FileClassLoader.java
|- MainApp.java
|- ITest.java
|- classes (sub-directory)
|- ITest.java
|- Test.java
This works fine. The .class files are compiled in the bin/ directory and
the application runs. But i can't see any files in the classes/
subdirectory. So why is this subdirectory there anyway?
I tried to move files ITest.java and Test.java into classes/
subdirectory and updating the appropriate imports and package
statements. Now the files are compiled ok under the correct subdirectory
but i get an output like
Class: Test
Loading...
Path: classes/Test.class
Exception: classes/Test.class (No such file or directory) not found.
null
Exception: null
No matter what i tried the error message is almost the same.
If i try to run it outside the Ide i get
Class: Test
Loading...
Path: classes/Test.class
Exception in thread "main" java.lang.NoClassDefFoundError: Test (wrong
name: classes/Test)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.lang.ClassLoader.defineClass(ClassLoader.java:448)
at FileClassLoader.loadClass(FileClassLoader.java:98)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at MainApp.main(MainApp.java:33)
If I create a copy of these files under the src/ (with appropriate
modification in package statements) it works ok again. But when i double
click the class file under the classes/ subdirectory it displays the
copy without
"package classes;" statement even if the path in the directory tree is
correct (Eclipse pops up a bubble with the
path of the file).
Can someone please explain why this is happening? And how can i group
all the classes that i want to load with
the custom class loader in one separate package (sub folder or folder
somewhere else)?
Tonight i ran into this
http://devcentral.iticentral.com/articles/Java/default.php (it requires
login). It has one tutorial about using custom class loaders.
My environment is Eclipse ide 3.1 which runs with java1.5 configured to
use j2sdk1.4.2_09.
As tutorial suggests i create the file structure as below (with a little
modification)
FileClassLoader
|-bin
|-src
|- FileClassLoader.java
|- MainApp.java
|- ITest.java
|- classes (sub-directory)
|- ITest.java
|- Test.java
This works fine. The .class files are compiled in the bin/ directory and
the application runs. But i can't see any files in the classes/
subdirectory. So why is this subdirectory there anyway?
I tried to move files ITest.java and Test.java into classes/
subdirectory and updating the appropriate imports and package
statements. Now the files are compiled ok under the correct subdirectory
but i get an output like
Class: Test
Loading...
Path: classes/Test.class
Exception: classes/Test.class (No such file or directory) not found.
null
Exception: null
No matter what i tried the error message is almost the same.
If i try to run it outside the Ide i get
Class: Test
Loading...
Path: classes/Test.class
Exception in thread "main" java.lang.NoClassDefFoundError: Test (wrong
name: classes/Test)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.lang.ClassLoader.defineClass(ClassLoader.java:448)
at FileClassLoader.loadClass(FileClassLoader.java:98)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at MainApp.main(MainApp.java:33)
If I create a copy of these files under the src/ (with appropriate
modification in package statements) it works ok again. But when i double
click the class file under the classes/ subdirectory it displays the
copy without
"package classes;" statement even if the path in the directory tree is
correct (Eclipse pops up a bubble with the
path of the file).
Can someone please explain why this is happening? And how can i group
all the classes that i want to load with
the custom class loader in one separate package (sub folder or folder
somewhere else)?