Reputation: 417
I know this is a noob question and maybe you can think that is a duplicate question, but none of the solutions it worked for me. Besides I have this problem since 2 days. The thing is, I am trying to add a .class file in java in Eclipse. This is the error:
I added the file from a class folder and it didn't work.
I also tried to import the .class file in a zip. It didn't work also. The curious thing is that, when I autocomplete the text of the import, Eclipse recognizes it. The file should be added in librerias.estructurasDeDatos.deDispersion . I am using Eclipse 2018-12 (4.10.0). And also, I saw a lot of solutions using Maven, but I am not using it. Also, I would like to know, why in the Package Explorer view I can see .java files and not .class files, because my TablaHash.class it is added in the project. Any help would be good. I am sure it could be a silly solution, but I can't see what I am doing wrong.
EDIT: I have changed lib
folder to this and it doesn`t work.
Upvotes: 0
Views: 128
Reputation: 29670
Let's suppose I have a project so.lib
where I have the Source for TablaHash.java
:
package librerias.estructurasDeDatos.deDispersion;
public class TablaHash {
public String test() {
return "OK, I'm here";
}
}
in another project so.test
I have a Main
class that uses previous class:
package so.test;
import librerias.estructurasDeDatos.deDispersion.TablaHash;
public class Main {
public static void main(String[] args) {
var tabla = new TablaHash();
System.out.println(tabla.test());
}
}
Add the first (library) project to the classpath of the Projects tab in the second porject settings.
Project structures and settings of so.test
:
Copy the class file(s) and directories in a lib
folder of second project. Add the lib
folder to the classpath in the Libraries
tab. (I used lib
, but the folder can be any (valid) name)
Project structures and settings of so.test
:
Note: the folder structure/hierarchie inside lib
is the same as from the project where the class file was located (same as the package hierarchie):
Upvotes: 1