views:

229

answers:

5

I have a code written in java. when i load it in eclipse it shows an error in the java code import line " The import com.sun.java.browser.plugin2 cannot be resolved"

import com.sun.java.browser.plugin2.*;

How can i fix this error..??

A: 

You have to add the plugin to the MANIFEST.MF dependency entry

  • Open MANIFEST.MF
  • Got to tab Dependencies
  • Add the plugin your referenced class is placed

You also have to be sure, that the package, the called class is lying, is added in the "Runtime" tab of the MANIFEST file.

EDIT:

The MANIFEST file you can find in the /META-INF directory

Markus Lausberg
where can i fin this manifest file??
Jasim
i have updated the answer
Markus Lausberg
A: 

Did you type this in? Then the build path in incorrect. If not no sure what is going on.

fastcodejava
A: 

Are you sure you are using the right JRE for your project? Like Java6?
See also JRE settings, and then make sure your project uses a Java6 JRE.

VonC
+2  A: 

As far as I know, packages com.sun.* are implementation details of certain jvm and must not be used by application developers. They can be slightly different even between minor versions of jvm. Difference between major versions or jvms of different vendors can be sufficient. So IBM's and Sun's jvms have different structure of those packages. Only packages java.* and javax.* and org.* should be used. To fix this error correctly you must not use this package. To hack it around, you can try configure eclipse to use appropriate jvm though I don't know how to do it.

Update: There's a FAQ entry about those packages. Thanks to R. Bemrose.

Rorick
+1: The Java language reference even tells you not to use sun.* packages (which are now com.sun.* packages): http://java.sun.com/products/jdk/faq/faq-sun-packages.html
R. Bemrose
+1  A: 

It's possible that it's to do with the version of Java you're building your project with, since the new applet class files were only introduced in Java 1.6 / 6.0. So, right click on your project on the left, go to Properties, Java Build Path, Libraries tab, and scroll down the list until you see JRE System Library. Note the version. If it reads less than 6.0 / 1.6, you're using an old version.

Click on JRE System Library, click Remove (make sure you have at least Java 1.6 installed!) then click Add Library. Select JRE System Library and select your Java version. If this isn't listed, go to Window > Preferences, Java > Installed JREs, click Add, and locate your JRE. Then repeat the same process and it should work.

(Edit: ignore what I said, the com.sun.* classes are hidden from the user. I don't think you can use it)

Chris Dennett