0

I'm using Eclipse Java EE IDE for Web Developers.

In Eclipse I have a folder that contains two classes I'm using for a web project: I tried to import them in my .java file in my package, but they are not recognized by Eclipse and an error appears. "The import CookieUtilities cannot be resolved" and "The import LongLivedCookie cannot be resolved"

Importing by:

import CookieUtilities.*;
import LongLivedCookie.*;

How can I import these classes to my .java file in my package? BTW: These classes have an icon with a J010 on them, which I'm not sure what that means. If you click on the file it states: "Source not found" There is no source file attached to the class file LongLivedCookie.class.

ConfusedDeer
  • 3,335
  • 8
  • 44
  • 72

2 Answers2

0

You do it one of two ways:

import static com.package.CookieUtilities.*;
import static com.package.LongLivedCookie.*;

OR

import com.package.CookieUtilities;
import com.package.LongLivedCookie;

Research on Google to decide for yourself which one you want to use.

djangofan
  • 28,471
  • 61
  • 196
  • 289
0

It sounds like your question is actually "How can I add a couple of binary .class files to my build path, so I can compile ... even if I don't have the Java source?"

Easy:

1) Copy the .class files to some folder on your filesystem

2) In Eclipse, right click your project

 Properties > Java build path > Libraries > Add Class Folder

3) Voila! Done.

The problem isn't the "import" in your source code. It's simply that Eclipse doesn't know where to find the .class (to satisfy the import).

Add the class folder to your build path, and things should be good.

FoggyDay
  • 11,962
  • 4
  • 34
  • 48
  • I did as you instructed and now it appears under libraries and I tried to add an import statement import cookiesClass; with the name of the folder, but still getting the error: "the import cookiesClass cannot be resolved;" – ConfusedDeer Apr 18 '14 at 04:18