Can't change the jre version in eclipse - java

I got an error "Syntax error, 'for each' statements are only available if source level is 1.5 or greater" in eclipse.
The jre system library being used is oracle-java-6 and I also enable project specific settings and set complier level to 1.6 but the error is still there.
Please help, thanks ahead.
4. ERROR in /home/johnny/Application/GWTPV/ParaViewWeb/WebServer/PWApp/src/org/paraview/server/AvailableDataFilter.java (at line 65)
ArrayList<FileBean> tmpfileNames = new ArrayList<FileBean>();
^^^^^^^^
Syntax error, parameterized types are only available if source level is 1.5

Look at the tab "Java compiler" in your project properties. If your default jdk compilance is less than 1.5 you should check "Enable project specific settings" and edit "Compiler compilance level" to 1.5, 1.6...

Check out the build path configuration (In the package viewer select the project root element and right mouse clic). Then check the Library setting. Often changing the JRE leaves the Library still set to 1.5.

Right click on the project -> Build Path -> Configure build path
or 1B. Right click on project -> properties -> Java build path
or 1C. Find the error in the Problems view, select it and click [ctrl]+[1] -> Configure build path
Open Libraries tab -> choose add library (or edit an exsting JRE on the list) -> JRE -> Alternate JRE -> click Installed JREs -> choose one
If you can't see the JRE you're looking for on the list (that is version 1.5 or greater):
Add -> standard JVM -> in JRE home field enter the location of your JRE on the disc.

Related

the type java.io.FilterOutputstream cannot be resolved. error

I'm new to coding. while creating a simple class, I got this error and somehow, many of my previous java projects on Eclipse that worked fine before got the same error (and some new errors). now most of my codes have red cross on them, how can I fixed it.
the type java.io.FilterOutputstream cannot be resolved. It is indirectly referenced from a required .class file; It says on the top of the driver classes
UPDATE:
-I tried Project> Clean... and it resolved the problem for most files, but not all of them.
-I have the jdk.14 and its library installed.
This looks like the JVM is missing.
Check Menu: Window -> Preferences -> Java -> Installed JREs
You should have some versions installed there.
If not, install a JDK for development, and optionally JREs.
Check the project's setting: Right-Click on Project -> Properties -> Java Build Path -> Libraries
If there is no Java entry, on the right side, click "Add Library" -> JRE System Library to have the default ones shown.
I removed the project from ellipse and then added it again...that resolved my error

Java JDBC "JdbcOdbcDriver" restriction [duplicate]

Here is the code:
package mscontroller;
import javax.swing.*;
import com.apple.eawt.Application;
public class Main {
public static void main(String[] args)
{
Application app = new Application();
app.setEnabledAboutMenu(true);
AMEListener listener = new AMEListener();
app.addApplicationListener(listener);
JFrame mainFrame = new JFrame("Application Menu Example");
mainFrame.setSize(500, 500);
mainFrame.setVisible(true);
}
}
here is the error:
Exception in thread "main" java.lang.Error: Unresolved compilation
problems: Access restriction: The type 'Application' is not API
(restriction on required library
'/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
Access restriction: The constructor 'Application()' is not API
(restriction on required library
'/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
Access restriction: The type 'Application' is not API (restriction on
required library
'/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
Access restriction: The method
'Application.setEnabledAboutMenu(boolean)' is not API (restriction on
required library
'/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
AMEListener cannot be resolved to a type AMEListener cannot be
resolved to a type
at mscontroller.Main.main(Main.java:9)
eclipse says this:
Access restriction: The type 'Application' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar')
This happened to me as well, and the answers given here already were not satisfying, so I did my own research.
Background: Eclipse access restrictions
Eclipse has a mechanism called access restrictions to prevent you from accidentally using classes which Eclipse thinks are not part of the public API. Usually, Eclipse is right about that, in both senses: We usually do not want to use something which is not part of the public API. And Eclipse is usually right about what is and what isn't part of the public API.
Problem
Now, there can be situations, where you want to use public Non-API, like sun.misc (you shouldn't, unless you know what you're doing). And there can be situations, where Eclipse is not really right (that's what happened to me, I just wanted to use javax.smartcardio). In that case, we get this error in Eclipse.
Solution
The solution is to change the access restrictions.
Go to the properties of your Java project,
i.e. by selecting "Properties" from the context menu of the project in the "Package Explorer".
Go to "Java Build Path", tab "Libraries".
Expand the library entry
select
"Access rules",
"Edit..." and
"Add..." a "Resolution: Accessible" with a corresponding rule pattern.
For me that was "javax/smartcardio/**", for you it might instead be "com/apple/eawt/**".
I was having the same problem. When I initially created the java project in Eclipse I specified JRE 8. When I went into the project's build path and edited the JRE System Library, the Java 8 execution environment was selected. When I chose to use an "Alernate JRE" (still java 8) it fixed the error for me.
Adding javafx accessible permission in eclipse oxygen
go to project> properties> java build path> libraries> then expand the libraries and double click on> Access rules there you set the permission
Resolution : Accessible
Rule Pattern : javafx/**
To begin with (and unrelated), instantiating the Application class by yourself does not seem to be its intended use. From what one can read from its source, you are rather expected to use the static instance returned by getApplication().
Now let's get to the error Eclipse reports. I've ran into a similar issue recently: Access restriction: The method ... is not API (restriction on required project). I called the method in question as a method of an object which inherited that method from a super class. All I had to do was to add the package the super class was in to the packages imported by my plugin.
However, there is a lot of different causes for errors based on "restriction on required project/library". Similar to the problem described above, the type you are using might have dependencies to packages that are not exported by the library or might not be exported itself. In that case you can try to track down the missing packages and export them my yourself, as suggested here, or try Access Rules. Other possible scenarios include:
Eclipse wants to keep you from using available packages that are not part of the public Java API (solution 1, 2)
Dependencies are satisfied by multiple sources, versions are conflicting etc. (solution 1, 2, 3)
Eclipse is using a JRE where a JDK is necessary (which might be the case here, from what your errors say; solution) or JRE/JDK version in project build path is not the right one
This ended up as more like a medley of restriction-related issues than an actual answer. But since restriction on required projects is such a versatile error to be reported, the perfect recipe is probably still to be found.
We had to change our application to build against the JDK 1.8 using Window->Preferences->Java->Installed JREs. However, after changing that, the JRE System Library specified in the Project Explorer was still incorrect. To fix this, right click on "JRE System Library [wrong-jre-here]" and change from Execution environment: to "Workspace Default (yer-default-here)"
I had this problem because the project facet associated with my project was the wrong java version.
To fix this is I did the following:
Right click on the project and select Properties
Select 'Project Facets' and change version of java to something greater than 1.4.
Click [Apply]
This will rebuild your project and hopefully the error will be resolved.
It worked: Project Properties -> ProjectFacets -> Runtimes -> jdk1.8.0_45 -> Apply
In the Eclipse top menu bar:
Windows -> Preferences -> Java -> Compiler -> Errors/Warnings ->
Deprecated and restricted API -> Forbidden reference (access rules): -> change to warning
If you're having this same issue using Spring Tool Suite:
The Spring Tool Suite's underlying IDE is, in fact, Eclipse. I've gotten this error just now trying to use some com.sun.net classes. To remove these errors and prevent them from popping up in the Eclipse Luna SR1 (4.4.2) platform of STS:
Navigate to Project > Properties
Expand the Java Compiler heading
Click on Errors/Warnings
Expand deprecated and restricted API
Next to "Forbidden reference (access rules)" select "ignore"
Next to "Discouraged reference (access rules)" select "ignore"
You're good to go.
Had the same problem. Here's how I solved it:
Go to Package Explorer. Right click on JRE System Library and go to Properties. In the Classpath Container > Select JRE for the project build path select the third option (Workspace default JRE).
Source : https://thenewboston.com/forum/topic.php?id=3917
We use IBM Rational Application Developer (RAD) and had the same problem.
ErrorMessage:
Access restriction: The type 'JAXWSProperties' is not API (restriction on required library 'C:\IBM\RAD95\jdk\jre\lib\rt.jar')
Solution:
go to java build path and under Library tab, remove JRE System Library. Then again Add Library --> JRE System Library
Go to the following setting:
Window -> Preferences -> Java-Compiler-Errors/Warnings-Deprecated and restricted API-Forbidden reference (access rules)
Set it to Warning or Ignore.
In Eclipse Mars.2 Release (4.5.2):
Project Explorer -> Context menu -> Properties -> JavaBuildPath -> Libraries
select JRE... and press Edit: Switch to Workspace JRE (jdk1.8.0_77)
Works for me.
Even if its old question, for me in Eclipse I just right click on Src folder and properties (Alt+Enter) and the check for the Ignore optional compile problems removed the error.
I have eclipse JRE 8.112 , not sure if that matters but what i did was this:
Right clicked on my projects folder
went down to properties and clicked
clicked on the java build path folder
once inside, I was in the order and export
I checked the JRE System Library [jre1.8.0_112]
then moved it up above the one other JRE system library there (not sure if this mattered)
then pressed ok
This solved my problem.
I simply just add e(fx)clipse in eclipse marketplace. Easy and simple
Remove Existing/Configured System Library:
Eclipse(IDE) -> Project Explorer -> Project Name-> (Option) Build Path -> Configure Build Path -> Java Build Path -> Libraries -> (Select) JRE System Library [(For me)jre1.8.0_231] -> Remove.
Currently you are at same location:
Eclipse(IDE) -> Project Explorer -> Project Name-> (Option) Build Path -> Configure Build Path -> Java Build Path -> Libraries
Now Add Same System Library Again:
Add Library -> JRE System Library -> Workspace default JRE ((For me)jre1.8.0_231) -> Finish -> Apply -> Close.
Now wait to finish it.
I'm using eclipse neon 3. I just wanted to use javafx.application.Application, so I followed Christian Hujer's answer above and it worked. Just some tips: the access rules are very similar to the import statement. For me, the access rules I added was "javafx/application/**". Just replace the dot in the import statement with forward slash and that's the rule. Hope that helps.
I had a little different problem. In Project - Properties - Libraries - JRE library, I had the wrong JRE lib version. Remove and set the actual one, and voila - all Access restriction... warnings are away.
If someone is having this issue only in your CI tool while running maven, what did the trick for me was to explicitly define the execution environment in your MANIFEST.MF.
In my case, I did this by inserting the following line in my OSGi bundle manifest file:
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
What worked for me was adding the access restricted package to the MANIFEST.MF file. In Eclipse, the "Access Restricted" errors showed up in the Problems tab for several files. I just right clicked on each error, clicked "Quick Fix", and chose "Add '[package]' to imported packages".
I had faced the same error on Eclipse 4.20.0 with JRE 1.8. To get rid of this compilation error, do the following:
Project --> Properties --> Java Compiler --> Errors/Warnings --> Deprecated and Restricted API --> Forbidden Reference (access rules) --> ignore

Eclipse: 'System' cannot be resolved

First i installed java 7.0 update 25 and then installed eclipse.
Later as per requirement, I uninstalled this java version and installed earlier version 5.0
Now in every eclipse program, it is showing error with word 'System'.
Solution is to add path of java.exe to eclipse.
Can anyone guide me to do it?
To resolve this problem perform below steps:
Go to Package Explorer -> Select your Project -> Right click on your project -> go to Properties-> Click on Java build path -> select your JRE file (mostly it will display error) and click on edit button which is on right side -> new dialog box will get displayed as “JRE System Library” in this window select radio button i.e"Workspace default JRE(jre6)" or whichever you have installed.
Then click on finish.
Errors will not come.
The solution to the above problem is, change the JRE system library by doing the following:
Right click on your project and select properties.
Select Libraries from the tab.
Select the current JRE system library and click on edit.
Select either Alternate JRE or Workspace default JRE (Latest version of JRE).
Click Finish and then OK.
On Eclipse Oxygen, follow steps from (1) to (6) shown below figure.
For those who make errors as I do, check whether the error is "'System' cannot be resolved" or "'system' cannot be resolved." In the latter case, capitalizing system will likely cure the problem. In the former case, follow directions above. Only wasted an hour figuring that one out.
I solved the problem a little bit different. That may be because on my computer "java" doesn't work at Windows/cmd.exe because it is not listed in the Windows-PATH variable.
My solution is this:
Project -> Properties -> Java Build Path -> Libraries
Add Library -> JRE System Library -> Alternate JRE -> Installed JREs…
Dialog “Installed JREs” open -> [Add…] -> “Standard VM”
Dialog “JRE Definition” opens -> JRE home: [Directory…]
Select the path to your JRE.
Use [Finish] or [Apply] several time. I hope it also works for you.

Android: rebuild now requires compiler compliance level 5.0 or 6.0. Found '1.7' instead. Why remove of #Override? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead. Please use Android Tools > Fix Project Properties
After rebuilding my PC I get this error on importing my projects.
Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead. Please use Android Tools > Fix Project Properties.
I have seen this raised on SO and I can fix my projects by doing the Fix Proj, and then removing all my #OVerrides.
this question is why do I now require to remove #Overrides? and will this alter my projects in anyway?
cheers
Edit to add walkthrough information.
I import a project, I get the error shown above. I then do the Android Tools > Fix Project Properties. This now sets Project>Properties Java Compile to Compiler Compliance Level 1.5
After this I am left with a series of errors within my java files. on this particular project my errors are on
#Override
public void run() {...
Error marker to left of error read...
Multiple markers at this line
- The method run() of type new Runnable(){} must override a superclass
method
- implements java.lang.Runnable.run
the error hover in eclipse suggests I remove the #Override to fix this issue, and if I do remove the #Override it does fix the issue and my project now compiles and runs.
Is this incorrect?
p.s. I just wrote all that up, changed the Java Compliance level to 1.6 and all the override errors went away! Could someone explain (and I totally appreciate this might be totally off topic) why?
Dont remove any #overide notation.
you must set project compatibility to Java 5.0 or Java 6.0.
To do that, 2 options:
1) right-click on your project and select "Android Tools -> Fix Project Properties" (if this din't work, try second option)
2) right-click on your project and select "Properties -> Java Compiler", check "Enable project specific settings" and select 1.5 or 1.6 from "Compiler compliance settings" select box.
refer this LINK for reference
FIRST UPDATE EVERYTHING....
Now right click on your project and select "Android Tools" then "Add Support library" it will update then try the stuff i copied from above....
1) right-click on your project and select "Android Tools -> Fix Project Properties" (if this din't work, try second option)
2) right-click on your project and select "Properties -> Java Compiler", check "Enable project specific settings" and select 1.5 or 1.6 from "Compiler compliance settings" select box.
Big Thanks to Agarwal Shankar for the start...

Eclipse->New Android Projects always compile java 1.4

Everytime I add/create or copy a Project inside my Eclipse-Workspace it will be recognized as a Java 1.4 Project, which leads to a sum of errors. I have to fix this myself under properties->java-compiler and check 1.6 there. So I have a few questions on that:
Is it possible to pre-define which compiler Eclipse has to choose?
Is there a config file telling eclipse which compiler to choose?
Check under Window -> Preferences -> Java -> Compiler. There is "Compiler compliance level", it should be set to your desired level. :)
If that does not work, go to the "New Java Project" dialog and pres "Configure JREs". Make sure your desired JRE is selected.
Window->Preferences->Java->Compiler

Categories

Resources