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..??
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)
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.
Did you type this in? Then the build path in incorrect. If not no sure what is going on.
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.
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
Related
I have problem importing import "javafx.util.Pair" into my program.
after searching the net I've found this answer cannot resolve symbol javafx.application in IntelliJ Idea IDE and I've installed desired jar file but still I've problem to import.
this is what I face to when open java jdk.
I don't know the why the "jfxrt.jar" is different.
note the black arrow on the folder icon
open the File | Project Structure dialog, there under Platform Settings select SDKs and then your JDK 1.8. On the right you then see all the jars that make up the classpath to your SDK. Make sure that your jfxrt.jar is in that list, if not, you can add it by clicking the '+' button at the bottom.
Update May 2020
JavaFX is no longer part of the Oracle or OpenJDK default distributions. Instead it is available as a seperate library or module set.
For instructions on using JavaFX in your application, see the documentation at:
https://openjfx.io
For instructions on working with a modern JavaFX installation and Idea, also see the related question:
IntelliJ can't recognize JavaFX 11 with OpenJDK 11
You don't need to "install the desired jar" (whatever that means).
You don't need to do that for JavaFX. You should not do anything explicitly with jfxrt.jar either in the filesystem or by adding it to a project classpath. If doing something on the filesystem, that is especially bad as jfxrt.jar is not made to be standalone and requires related native libraries shipped with the JDK in order to work.
The JavaFX code should be part of the JDK installation you are using. Perhaps you are using a Java version below 8 or an OpenJDK implementation that does not include JavaFX. If so, then install the Oracle JDK 8+ and set idea to use it. Everything should just work then and all of related JavaFX imports will resolve.
Out of pure curiosity, I want to browse Java sources in Eclipse in order to benefit the ease of navigation and search.
When I import sources into a newly created project, I encounter thousands of errors, how do I correct these errors ?
The sources of the JDK are located in JDK_HOME/src.zip
Unzip this archive in the folder of your choice.
Create a new Java Project under Eclipse
Import the content of src.zip into your new project. The compiler will raise several errors.
First, you need to add JDK_HOME/lib/tools.jar to your build path. Into project properties, go to Build Path, libraries and add external Jar.
Second, you need to give access to normally restricted classes from the JDK. From the libraries pane, click the JRE system library and select Access rules. Set the resolution to accessible for the rule pattern */**. This gives access to all the classes in the JRE jars.
Finally, there are two classes that have been reported missing since JDK7 that you have to import manually. There are various solutions , the fastest for me is to download from OpenJDK repositories :
sun.awt.UNIXToolkit.java
sun.font.FontConfigManager.java
Enjoy browsing Java sources !
There is no reason to import the JDK sources as a project in Eclipse or try to compile them. If you have Eclipse pointed to a JDK (as opposed to a JRE), it will automatically pick up the src.zip that it finds there and show source when you browse to JDK classes.
Package Explorer, Project Explorer, Java Browsing, and other Java-oriented views show the packages and classes just as they were any other library/JAR. In Package Explorer they show up under JRE System Library.
In Java Browsing perspective, it looks like any other packages:
Right now I'm trying to get Java3D to work with JDK 1.8.0 in Eclipse on OS X. I've tried following this tutorial (among many others) and am finding varying levels of no success. I believe part of the problem is that there are currently 3 separate locations with the Java3D .jars are ending up on the build path:
/Library/Java/Extensions/ as a part of the JRE system library
/System/Library/Java/Extensions/ as a part of the JRE system library
My personal libraries folder as external included .jar files
Earlier in project development, I hadn't updated the files in the Library folders (they were whatever came with the Mac), and in that case there were no Eclipse errors, but the project could not be run (UnsatisfiedLinkError: no j3dcore-ogl in java.library.path)
Now that I've updated both of the JRE system library .jar files, the code has errors: Access restriction: The type '...' is not API (restriction on required library '/Library/Java/Extensions/j3dcore.jar')
What's the proper way to clean up all these locations so that the project only references one set of these .jars, and where should these .jar's be?
There is only one way to clean up: uninstall all those obsolete versions of Java3D provided by Apple ("whatever came with the Mac") and follow my instructions.
The extension mechanism has been removed from Java 1.9, relying on it is a very bad idea. Only use a carefully chosen "personal libraries folder" whose scope affects only your application and not the rest of the operating system.
If you need some help on Java3D, rather use its official forum.
We are using Eclipse for our projects and we would like to revision control the JDK we use. (Different projects need to use different JDKs). Instead of configuring everyone's system to have the same JDK with the same names in Eclipse, we would like to include the JDK as part of our project in our source control tool and have the project point to the JDK that is part of the project.
We can't figure out how to tell Eclipse to use the JDK that is found in the project. It keeps wanting an absolute path to the JDK. Is it possible to use the JDK that is part of a project and use a path that is relative to the project?
Is it possible to use the JDK that is part of a project and use a path
that is relative to the project?
Straight answer: NO
You're asking to go around the basic abstraction that Eclipse provides between installed runtime environments (which are defined at the workspace level) and the project's compiler configuration (which is defined at the project level). If you want to use all the JDT features in Eclipse, you just have to live with configuring the installed JREs on each workspace of each of your developers.
However, I can think of a probably not-so-standard-way (I see the -1's coming for saying this, which is crazy!) to achieve what you want: to distribute the .metadata folder of a pre-configured workspace you've already set up with all your JRE's so you don't have to go on each machine and do the installation. This would also include committing the .settings folder and the .project .classpath files of each project. Want to include the JDKs? Well, you could put each of them in the SCM as individual projects and ask each developer to import and configure them. If you did this on your template workspace before distributing it, then it will have not only the JDK's but also the .metadata pointing to them.
What could go wrong with this? probably everything.
How do the pro's do it? Maven and the maven-compiler-plugin (and not committing any IDE specific files). This leaves developers free to choose any IDE they want, and most of them support automatic project configuration from POM files: target JDK, dependencies, etc.
This may not be the approach you are looking for, but one option is to use a drive letter using SUBST for the root directory of your project.
Having the same path to project on all development machines has many advantages. This strategy is most useful for developers working on a single codeline but I have successfully used it even with multiple codelines on my machine, changing the subst as necessary.
You can configure the JDK version in Eclipse. Right click your project, select properties, goto Java Compiler and there you can select a project specific version of Java for your project.
One approach would be to install all the JDKs on all the machines and use JAVA_HOME/PATH variables to point the appropriate JDK installation as required. You can write a simple batch file to take care of environment variable setting by just a simple double click.
No, that is not possible.
Either use Maven to just declare all your dependencies, including the SDK to be used. Or use Yoxos or Secure Delivery Center to centrally define Eclipse configurations, which are then deployed to your developers desk on starting Eclipse.
You're checking in the entire JDK? That seems likely to slow down your SCM quite a bit as it has to try and track a lot of large binaries, which won't diff well. Why not use a tool like Maven that declaratively states what JRE version to use?
I wanted to start learning java but Eclipse is giving me some trouble.
First of all I'm a beginner with Java with little to no knowledge about it. I want to use 'JavaSe-1.7'. I have no clear reason to use it besides using the latest version. After downloading Eclipse (Eclipse IDE for Java Developers) I created a new Java project and selected 'use an execution eviorment JRE : JavaSE-1.7'. This directly popped the notification saying 'The default compiler compliance level for the current workspace is 1.6. The new project will use a project specific compiler compliance level of 1.7.'. I finished creating the project and started following some tutorials.
However I noticed directly I have 2 errors which dont explain anything or have a source. I ignored it and started typing and tried to import 'java.io.console' however it said 'The import java.io cannot be resolved' and I have no idea what is the cause of it neither how to fix this.
Would like some instructions into the right direction.
Thanks in advance
Check your Eclipse preferences: Java -> Installed JREs. The one that you're using should be marked and it should be a JDK not just a JRE.
Also check your project's build path: Right click on the project -> Properties -> Java Build Path
Check in the "libraries" folder whether the JRE System Library is present and if not add it using "Add library"->"JRE System Library" and then select the correct one (from an installed JDK).
You may not have your JDK/JRE set up correctly.
Check the following:
Did you install a JDK or just the JSE? The JDK is needed to compile .java files to .class files. Without it, you can only run java programs, not develop them. If not, download and install it from Oracle website.
Check in Eclipse, if you have the JRE installed there as well. You just need to specify the path to the installation. You can reach this screen via the "Window->Prefrences" menu. see this screenshot:
The message you receive about project specific compiler compliance level is not a problem, it just means that your workspace is set up to comply to java 1.6 but your project will comply to java 1.7 standards. Also, Java 7 in general is no problem whatsoever.
Paths may differ, especially if you're not running a *nix OS. Just point the location to where you installed your JDK.