액세스 제한 : 'Application'유형이 API가 아님 (필수 라이브러리 rt.jar에 대한 제한)
코드는 다음과 같습니다.
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);
}
}
여기 오류가 있습니다 :
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)
이클립스는 다음과 같이 말합니다.
액세스 제한 : 'Application'유형이 API가 아닙니다 (필수 라이브러리 '/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar'에 대한 제한)
이것은 나에게도 일어 났고 여기에 주어진 대답은 이미 만족스럽지 않았기 때문에 나 자신의 연구를했습니다.
배경 : Eclipse 액세스 제한
Eclipse에는 실수로 Eclipse가 공용 API의 일부가 아니라고 생각하는 클래스를 사용하지 못하도록하는 액세스 제한 이라는 메커니즘이 있습니다 . 일반적으로 Eclipse는 두 가지 측면에서 모두 옳습니다. 우리는 일반적으로 공개 API의 일부가 아닌 것을 사용하고 싶지 않습니다. 그리고 Eclipse는 일반적으로 무엇이 공개 API의 일부인지 아닌지에 대해 옳습니다.
문제
이제, 공개 비 API를 사용하려는 상황이있을 수 있습니다 sun.misc
(무엇을하고 있는지 알지 못한다면 안됩니다). 그리고 Eclipse가 실제로 옳지 않은 상황이있을 수 있습니다 (저에게 일어난 일 javax.smartcardio
입니다.). 이 경우 Eclipse에서이 오류가 발생합니다.
해결책
해결책은 액세스 제한을 변경하는 것입니다.
- Java 프로젝트의 특성으로 이동하십시오.
- 즉, "패키지 탐색기"의 프로젝트 컨텍스트 메뉴에서 "속성"을 선택합니다.
- "자바 빌드 경로", "라이브러리"탭으로 이동하십시오.
- 라이브러리 항목을 확장하십시오
- 고르다
- "액세스 규칙",
- "편집 ..."및
- 해당 규칙 패턴으로 "추가 ..." "해결 방법 : 액세스 가능" 저에게 "
javax/smartcardio/**
" 이 (가) 있었을 수도 있습니다. 대신 "com/apple/eawt/**
" 일 수도 있습니다 .
나는 같은 문제를 겪고 있었다. Eclipse에서 Java 프로젝트를 처음 작성할 때 JRE 8을 지정했습니다. 프로젝트의 빌드 경로로 이동하여 JRE 시스템 라이브러리를 편집 할 때 Java 8 실행 환경이 선택되었습니다. "Alernate JRE"(여전히 Java 8)를 사용하기로 선택했을 때 오류가 수정되었습니다.
일식 산소에 javafx 액세스 권한을 추가하면 프로젝트> 속성> java 빌드 경로> 라이브러리>로 이동 한 다음 라이브러리를 확장하고 액세스 규칙을 두 번 클릭하십시오. 여기에서 액세스 규칙을 설정하십시오.
( 와 관련이없는 ) 시작으로 , Application
스스로 클래스를 인스턴스화하는 것은 의도 된 용도가 아닌 것 같습니다. 소스 에서 읽을 수있는 것에서 반환 된 정적 인스턴스를 사용해야합니다 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.
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
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)"
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
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.
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.
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
I simply just add e(fx)clipse in eclipse marketplace. Easy and simple
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.
누군가 maven을 실행하는 동안 CI 도구에서만이 문제가 발생하면 트릭은 실행 환경을 명시 적으로 정의하는 것이 었습니다 MANIFEST.MF
.
필자의 경우 OSGi 번들 매니페스트 파일에 다음 줄을 삽입하여이 작업을 수행했습니다.
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
'Programing' 카테고리의 다른 글
Stroustrup의 예에서 콜론은“return 1 : 2”에서 무엇을 의미합니까? (0) | 2020.06.01 |
---|---|
Android Studio의 IML 파일이란 무엇입니까? (0) | 2020.06.01 |
Objective-C에서 nil과 NULL을 언제 사용해야합니까? (0) | 2020.05.31 |
macOS에서 my.cnf 파일의 위치 (0) | 2020.05.31 |
밀리 초를“hh : mm : ss”형식으로 변환하는 방법은 무엇입니까? (0) | 2020.05.31 |