problem with mixed .class/.java in eclipse
Hi.
I have a problem with directories in eclipse.
I work on a java project, where there is a directory with mixed .class and .java files. I don't have sources of .class files and hierarchy must be preserved.
|-directories only .java
|-directory1
| |-directory2
| | |- class1.class
| | \_ class2.class
| |-directories only .class , using by class1 and class2
| \_ class3.java, using class1 et class2
\_other directories
If I use directory1 as source folder in eclipse,import directory1.directory2.*;
doesn't import class1 and class2 and .class aren't visible.
If I use directory1 as class folder, class3.java isn't visible.
I try to move class3.java in an other directory:
|-directories only .java
|-directory1 (as class folder)
| |-directory2
| | |- class1.class
| | \_ class2.class
| \_directories only .class , using by class1 and class2
|-directory3 (as source folder)
| \_ class3.java, using class1 et class2
\_other repertories
In class3.javaimport directory2.*;
works without problem, butpackage directory3;
cause The type directory1/directory2/class2 cannot be resolved. It is indirectly referenced from required .class files
Could somebody help me to solve this problem?
Thanks.
[1591 byte] By [
Aerisa] at [2007-11-27 1:48:37]

import is based on the fully class (not file) name.The directory structure must match the full name.So FIRST you must determine the full name of each class (not file.)
I always name my files with the name of the class I implement into.So, what I must write for the import?I try all I can, and even eclipse autocompletion doesn't find my class1 and 2...
> I always name my files with the name of the class I
> implement into.
As an example the fully qualified name of the java String class is the following.
java.lang.String.
The file that that class lives in is String.java (however that is irrelevant.)
The class file created from the above is String.class. That class file MUST live in a directory called .\java\lang\String.class
The java compiler doesn't care what you name your java files. It uses the names of the classes in the file to determine what class files to create.
> So, what I must write for the import?
I already told you that you must first determine what the full name of the classes are.
Using the same example above (String) you would see this in the source file for that class.
package java.lang;
class String
You put those two together to get "java.lang.String"
> I try all I can, and even eclipse autocompletion
> doesn't find my class1 and 2...
I can't help you with that.
My class files are in:
home/dev/project (eclipse workspace)
|- directory1
|\_directory2
| |- class1.class (implements class1)
| \- class2.class (implements class2)
\_ directory3
\_ class3.java (implements class3)
My import in class3.java are import directory2.class1;
import directory2.class2;[/color].
Any error with the imports.
But in class3.java, [code]package directory3;
makes an error "The type directoryUnknow.directory2.class2 cannot be resolved. It is indirectly referenced from required .class files".
directoryUnknow is nowhere on my hard disk, and nowhere on a class in the project....
You still aren't getting it.
Until you figure out what the names of the classes are you CAN"T figure out where to put them or how to use them.
Period.
The import is based ONLY on the name. The location is used to process the name, but it does NOT define the name.
If you have a file named "class1.class" then that means that part, and only part of the name, is "class1".
If and only if class1 was built with a package of "directory1.directory2" would it impact the name.
AGAIN, it doesn't matter where you put the class files. Until you figure out the names of the classes in the files you can't succeed.
Try this....
- Open a command window.
- Change to the directory where the class1.class file is.
- Type "java class1"
There will be one of three results
1. It tells you the command isn't recognized. That means "java" isn't in the execution path. You must fix this to proceed.
2. It tells you that you used the wrong name. This tells you the actual name.
3. It tells you that main isn't found. This means that the full name of the class is "class1".
But as I said to you, class1.class contains a class named class1 and class2.class one named class2 :pjava class1 and java class2 confirm that.
Um, it's abundantly clear that pulling teeth would be easier and less painful than helping you on a forum like this.Good luck with that.
> But as I said to you, class1.class contains a class
> named class1 and class2.class one named class2 :p
> java class1 and java class2 confirm that.
Presuming that you actually did what I asked you then the full name of class1 is in fact "class1".
Thus you can't use an import statement. Period.
In point of fact those classes belong to the "default" package.
Based on the above then the following is your situation.
1. You are using classes that have no package.
2. You are attempting to use them in a class that does have a package.
If so you must use one of the following solutions.
1. Acquire a 1.3 Sun compiler. Write wrapper classes that do have name spaces. You use those rather than the original classes.
2. Get the source for the code. Add packages.
3. Don't use them in a class with a package (and that class then can't be used in a class with a package.)
4. Use a custom class loader to load the classes and access them only via reflection. (This should work but not that unlike 1-3 I am not sure that it will.)
Those are your choices. There are no others.
If I had the sources of these classes, I don't annoy me with this problem?br>But there are "private" classes, and their owner doesn't want to give them...And customers' orders are simple: don't touch the hierarchy of directories!
I believe I already told you that the directories are irrelevant.
Given a class named "class1" which is located in C:\directory1\directory2\class1.class.
To correctly resolve this your class path must have the following on it
C:\directory1\directory2
So for example using a standard command line you could do the following...
java -cp ".;C:\directory1\directory2" MyTest
Classpath is already set to /home/dev/project/directory1/directory2 ...
> Classpath is already set to> /home/dev/project/directory1/directory2 ...And did you read the rest of my post about mixing the default package with explicit packages?
Yes, all classes are in a package (and not the default)
> Yes, all classes are in a package (and not the
> default)
Which makes it very clear to me that you didn't in fact do what I told you previously from which you stated in reply #6 that "class1.class contains a class named class1".
That would be because those two statements are contradictory.
Either the file class1.class contains a class name "class1" or it contains a class named something else like "directory1.class1".
And those two classes are NOT the same.
Get back to me when you have actually followed my suggestions.