简体   繁体   中英

Error when importing jar file in Eclipse (even after adding it to the build path)

In the 'lib' directory of my Eclipse project, I have a jar file, 'foo.jar' which contains a class file 'Foo.class' in the (default package) of 'foo.jar' , which I have added to my build path in Eclipse (using Project->Properties->Java Build Path->Libraries->Add JARs...). Now, 'foo.jar' appears under the 'Referenced Libraries' section in Eclipse's Package Explorer.

In the 'src' directory of my project I've got a file 'bar.java' whose first line is:

import foo.Foo;

In the body of 'bar.java', the code can use the contents of 'Foo.class' and all appears well, except I get exactly one error, on the import statement: "The import foo cannot be resolved", so the program won't run; it's the only error in 'bar.java'.

What's the proper way to take care of this?

(I have cleaned the project and refreshed it.)

import xxx.Foo; where xxx is the package name, not the name of the jar

If it's the default package, just try using Foo? You won't need the import in that case.

Thanks m8 ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM