Java JDBC "JdbcOdbcDriver" restriction [duplicate] - java

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

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

Unable to import import javafx.geometry.Point2D [duplicate]

When trying to use javafx related classes in my new java 8 project I get an access restriction error from eclipse. So far the only 'solution' I've been able to find is to tell eclipse to ignore the access restriction, but I am not satisfied with that.
An example of the error:
Access restriction: The type Pane is not accessible due to
restriction on required library C:\Program Files\Java\jre8_0\lib\ext\jfxrt.jar
I'm using Eclipse Kepler with the Eclipse JDT patch for java 8.
This seems to be an issue related to the fact that JavaFX is not a part of the JavaSE execution environment.
I am now toughly confused as according to http://en.wikipedia.org/wiki/JavaFX javaFX is a part of the JavaSE. Is it possible that Eclipse is not recognizing that it is a part of the javaSE?
I'm going to add one more answer here, just to provide what I think is the most minimal approach. In my Eclipse setup, I have e(fx)clipse installed, which provides one fix for this, as well as providing many useful development features that you will almost certainly want if you are writing JavaFX applications. This is probably the most practical approach. If for some reason you don't want that plugin, the solution outlined in this answer will fix the problem with the least amount of other side effects.
As pointed out in other answers, Eclipse, by default, disallows access to classes in jar files in the jre/lib/ext directory, as these are not guaranteed to be present on all Java platforms. If you are writing a JavaFX 8 application, you are assuming you are on a platform where jfxrt.jar is available in the lib/ext location.
So the minimal fix for this is to allow access to the classes in this jar file (and only in this jar file). To do this, right-click on the project and bring up the project properties dialog. Select "Build Path" in the left pane, and select the "Libraries" tab. You will see a "JRE System Library" entry. Expand that entry, and you will see an "Access Rules" subentry:
Select the "Access Rules" entry and click "Edit". Click "Add".
Under "Resolution", choose "Accessible", and under "Rule Pattern", enter javafx/**:
Click OK to exit all the dialogs.
This setting will allow access to all the classes in any packages beginning javafx., but will preserve the rule on the ext folder for all other classes, and is "minimal" in that sense.
Again, what you probably really want to do is to install the e(fx)clipse plugin, but to my knowledge this is the solution with the least side effects on your Eclipse setup.
From the Eclipse Point of view the error is totally correct because JavaFX is coming from the extension classpath and is not available on ALL Java8 VMs (e.g. ibm!).
As outlined you can suppress those warnings by add access-rules or IMHO the best solution is to install e(fx)clipse which does this automatically for you and beside that even provides you tooling for JavaFX CSS and FXML.
You can grab an all in one package from http://efxclipse.bestsolution.at/install.html
I resolved the problem by removing and readding the JDK to the build path. Don't ask me why this works, though.
The easy way is to install e(fx)clipse - a plugin for Eclipse to support JavaFX:
Select Help -> Install New Software
Click Add button to add the following site:
Name: efxclipse
Location: http://download.eclipse.org/efxclipse/updates-released/1.2.0/site
Click OK
In the "Work with", select the recently added site "efxclipse"
Check the checkbox "e(fx)clipse - install" to install all components of this selection
Move to next steps to finish the installation
Restart your Eclipse. If it still doesn't recognize JavaFX library, restart it again.
Original information can be found here: https://www.eclipse.org/efxclipse/install.html#for-the-lazy
I've resolved this problem by some careful use of the Eclipse project's build path.
Bring up the properties of the you application project and select the 'Build Path' section.
Add the jre8_0\lib\ext\jfxrt.jar as an "External JAR file" in the
'Libraries' tab.
In the 'Order/Export' tab ensure that this jfxrt.jar is
first in the list.
What this doing is making Eclipse see the jfxrt.jar as just a regular 3rd party JAR file. The order is important so that this takes precedence over the entry in the JRE system library. It's the same actual JAR file, but Eclipse is seeing it differently.
You may wish to alter any run configurations so it doesn't use the 'Exported' version of the jfxrt.jar; however in practical terms this won't make a difference.
I've done this with Java8 and Eclipse Luna; but the principal would I am sure work with any combination of Java and Eclipse.
go to the build path of the current project
under Libraries
select the "JRE System Library [jdk1.8xxx]"
click edit
and select either "Workspace default JRE(jdk1.8xx)" OR Alternate JRE
Click finish
Click OK
Note: make sure that in Eclipse / Preferences (NOT the project) / Java / Installed JRE ,that the jdk points to the JDK folder not the JRE C:\Program Files\Java\jdk1.8.0_74
I know this has been answered already, but I find the proposed solutions clunky.
I don't want to install a plugin just to avoid what I consider to be an invalid error.
Adding jfxrt.jar as external jar will work, but is a bad idea if you plan on doing an export because jfxrt.jar will be exported as well. Probably not what you want.
Another option
In 'Mars' release (and possibly earlier versions) you can disable access restrictions errors. Under
Java->Compiler->Errors/Warnings view
and
"Deprecated and restricted API"
you can set "Forbidden reference (access rule)" to ignore.
Follow these steps:
Add the jfxrt.jar (from your installation folder) as an "External JAR file" in the 'Libraries' tab.
In the 'Order/Export' tab, ensure that this jfxrt.jar is first in the list.
This worked for me.
I had the same problem. I used James_D 's solution but his exact solution did not work for me. But using **/javafx/** instead of javafx/** solved the problem for me. Hope that helps.
PS: I would post this as a comment under James_D 's solution but I just registered and did not have enough "reputation" to do so.
As James_D already suggested I added access rules to my classpath file. I uninstalled the e(fx)clipse plugin for the time being because it has a css validation bug (see How to disable css warning "Unknown property" in Eclipse Mars?).
Here is my entry in the classpath file for the JRE container:
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.‌​launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
<accessrules>
<accessrule kind="accessible" pattern="javafx/**"/>
<accessrule kind="accessible" pattern="com/sun/javafx/**"/>
</accessrules>
</classpathentry>
Step-1: Navigate to your jfxrt.jar.
C:\Program Files\Java\jre1.8.0_111\lib\ext
Step-2 Copy the file jfxrt.jar
Step-3: Go to Eclipse,Create a new folder like this:
[Creating folder name lib to put our jfxrt.jar file][2]
[2]: https://i.stack.imgur.com/YsJ5S.png
Step-4: Select the lib folder and press CTRL+V to paste the jfxrt.jar
[Paste your jfxrt.jar][1]
[1]: https://i.stack.imgur.com/Ljogu.png
Step-5: Right click on jfxrt.jar and set as Build Path.

implicit super constructor object() is undefined. must explicitly invoke another constructor

Is this a new bug? I got a new mac computer and install eclipse on it. The checksum matches fine. But when I try to create a simple class, just for basic testing, I get the error mentioned in the title. Never before have I seen java complaining about object() constructor. Here is the class:
package com.my.ok;
public class First {
}
EDIT:
I am finding that the problem happens if I set execution environment to javaSE-1.7
This problem occurs if your JRE is not configured in project built path.
To configure JRE:
In Eclipse:
Right click on your project and select Build Path -> Configure Build Path
Go to Libraries tab click Add Library.
Select JRE System Library click Next
Then select JRE from options as per your requirement. Click Finish
In Netbeans:
Right Click on the Project and select Properties.
In the Library category select Java Platform as per your requirement.
Then go to Source category select Source/Binary Format and select JDK as per your requirement.
Explanation:
The error was because you did not include System libraries in your project and your class was not able to find Object() constructor which is called first in the hierarchy when you create an object.
Example:
package com.my.ok;
public class First {
}
what happens is compiler extends by default your First class to Object class
package com.my.ok;
public class First extends Object {
}
but Object class was not found in your case and you were getting this error.
This is a typical issue with JRE configuration in the java web project. Right-click on your project select "Build Path" and "Configure Build path". In the "Libraries" tab double click on "JRE System Libraries" and select workspace Default workspace. If you do not have one installed, please install it and follow the above process.
Go to buildPath and in libraries double click on JRE System Libraries and select workspace Default workspace.
if your project is a maven project try mvn clean install command. It worked for me.
I was facing the same issue then I change changed my installed JRE and point to jdk and it worked for me.
Eclipse -> Windows -> Preferences -> Java -> Installed JRE -> Add new (gave the path of installed java jdk)
I had this problem in IntelliJ. I was using JDK version 1.8.0_333, but my Maven runner version was 11.0.1. When I changed that to 1.8.0_333, the errors went away.
The Maven Runner version can be set under Preferences->Build, Execution, Deployment->Build Tools->Maven->Runner.
I'm still mystified by the error, because that Maven runner works fine with all my other projects.

Changing Java Version From Within Eclipse

I wrote a project in eclipse with an older version of java.
Now on a different computer but running the same codes I'm getting a whole lot of red.
This is due to Version incompatibility.
I've had my professor change the Java version from within the console window before. The code compiled just fine after he did so. I'm sure its the same case with this code.
After looking at other tutorials and google links I could only find command line approaches and #override methods. To be honest I still don't understand these.
What is the best way to change the version of a code originally written in an older code inside the eclipse console?
thanks!
In eclipse go to Window -> Preferences -> Java -> Compiler, there you can change the java versions. Hope it helps.
Ideally if we want to have two different versions of Java [say 1.6 and 1.7], then we should have two workspace defined accordingly to avoid any mixup. We can also change the Project Facets if our projects has facets that is.
In Eclipse Follow steps given below:
1) Windows -> Preferences -> Java -> Compiler and as per the image set the compliance compiler level as per your requirements.
2) Windows -> Preferences -> Java -> Installed JRE's and check if your required jre/jdk is available or not as given in image below:
3) Right Click on Your Project and go to Java Build Path and check if your required Library is available or not as per image given below:
4) Now you can edit the JRE System Library or add one by clicking on button's available on last image's right side, then a pop up as given below will open up. Here, you can change the execution environment [default values also can be set]
In myeclipse select the project -> properties -> java compiler -> there you can specify jdk version.
Easy
Download the jdk from Oracle's official website for the version you want to compile your project with.
JDK Oracle's official
create a new Java project
[
Once the project has been generated, If you select the part that says Configure JREs
By default eclipse will use the version you have installed on your system so if you don't change this configuration you will never be able to run the program with the build you need, in this case I will use jdk 1.8.
After pressing Add
5.1 And choose the option select the 3rd option in this case, called Standard VM and press Next
Now eclipse asks us to indicate the path where the libraries and other content is located in order to compile and run the program, we only have to indicate the directory where it is located.
As my goal is to run a program with the JRE 8 , I will look for the directory path where the download described in option 1 of this message is located.
As a quick example, since I just want my program to compile without worrying about anything else, I will add all the contents of my address.
Now we change by clicking on the JRE we want to compile our program, to be changed to the original default so that the new selection is executed ; and finally we press Apply and Close and Next
Press Finish to create the project
Now we have the whole project with all the necessary content to compile and run it.
Personally I think this is the quickest and cleanest way to do it ; the problem I encountered when I changed JDK is that when compiling I couldn't find the directory with the necessary components to run it, you had to download it and configure it together with the default parameters, which can cause a lot of headaches for less experienced users.
Finally, this is the version of eclipse that I am using
I hope you find this system useful, I use it to be able to run old examples that use applets , which are obsolete classes and jvm does not compile.

Access restriction: Is not accessible due to restriction on required library ..\jre\lib\rt.jar

I am trying to modify some legacy code from while back and getting the following kind of errors:
Access restriction: The method create(JAXBRIContext, Object) from the type Headers is not accessible due to restriction on required library ..\jre\lib\rt.jar
for these import statements:
import com.sun.xml.internal.bind.api.JAXBRIContext;
import com.sun.xml.internal.ws.api.message.Header;
import com.sun.xml.internal.ws.api.message.Headers;
import com.sun.xml.internal.ws.developer.WSBindingProvider;
Been searching what this might mean and how to fix it, however not been able to find a clear answer. Some posts seem to suggest that I have some JARs included that implement classes that are now available as part of the core java distribution, but as far as I can see none of the JARs I include contain different/older versions of the above classes.
Anyone able to tell me what this error is all about and how I might go about fixing this?
Thanks for your help already in advance,
Olli
I ran into something similar, I think that the cause of the warning is Eclipse trying to discourage you from using the internal com.sun packages that are installed as part of your workspace JRE but which are not part of the public Java API.
As Justin says in his answer, changing your compiler settings can hide the warning. A more fine-grained approach is to modify your build path to explicitly allow access to the package in question:
Open the Libraries tab of the Java Build Path project property window.
Expand the JRE System Library entry.
Select "Access rules" and hit the Edit button.
Click the Add button in the resulting dialog.
For the new access rule, set the resolution to Accessible and the pattern to "com/sun/xml/internal/**".
After adding this access rule, your project should build without these warning.
Excellent answer already provide onsite here.
See the summary below:
Go to the Build Path settings in the project properties.
Remove the JRE System Library
Add it back; Select "Add Library" and select the JRE System Library. The default worked for me.
Not a true solution, but everywhere I looked the solution suggested was to simply tell Eclipse that those aren't errors. You can change it by going to Properties --> Java Compiler --> Errors Warnings --> Deprecated and restrited APIs --> Forbidden reference (acess rule), Change it from Error to Warning or Ignore.
i've solved this issue with these steps: expand your project, right click "JRE System Library" > Properties > choose 3rd option "Workspace default JRE" > OK . Hope it help you too
In Eclipse:
Project -> properties -> java Build Path -> libraries
Remove existing JRE System Library, then Add Library -> JRE System library -> next -> ok
Error will be removed.
I had the same problem when my plugin was depending on another project, which exported some packages in its manifest file. Instead of changing access rules, I have managed to solve the problem by adding the required packages into its Export-Package section. This makes the packages legally visible. Eclipse actually provides this fix on the "Access restriction" error marker.
In the eclipse environment where you execute your java programs, take the following steps:
Click on Project just above the menu bar in eclipse.
Click on properties.
Select libraries, click on the existing library and click Remove on the right of the window.
Repeat the process and now click add library, then select JRE system library and click OK.
I'm responding to this question because I had a different way of fixing this problem than the other answers had. I had this problem when I refactored the name of the plugins that I was exporting. Eventually I had to make sure to fix/change the following.
The product file's dependencies,
The plugin.xml dependencies (and make sure it is not implicitly imported using the imported packages dialog).
The run configuration plug-ins tab. Run As..->Run Configurations->Plug-ins tab. Uncheck the old plugins and then click Add Required Plug-ins.
This worked for me, but your mileage may vary.
I just changed project facet to 1.7 and it worked.
Go to Buildpath
Remove Existing JRE and add new JRE library which contain Jdk1.6
and finish
Now clean all project and build again
I think this way you can resolved your error

Categories

Resources