Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaFX application produce warning #120

Closed
kant2002 opened this issue Dec 17, 2016 · 37 comments
Closed

JavaFX application produce warning #120

kant2002 opened this issue Dec 17, 2016 · 37 comments

Comments

@kant2002
Copy link

A lot of warnings about restricted API

Environment
  • Operating System: Windows 10 64-bit
  • JDK version: jdk1.8.0_111
  • Visual Studio Code version: 1.8
  • Java extension version: 0.0.7
Steps To Reproduce
  1. Create JavaFX hello world
  2. Open project in VS Code
  3. Open HelloWorld.java
Current Result

All code has following hints:

[Java] Access restriction: The type 'Application' is not API (restriction on required library 'C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\jfxrt.jar')
Expected Result

No hints provided, or some configuration option needed to override restricted libraries.

@alexandrio
Copy link

same here add an image of warning.
virtualbox_xubu_09_01_2017_14_02_12

@gorkem
Copy link
Contributor

gorkem commented Jan 9, 2017

Technically the libraries from extension classpath are not guaranteed to exist on JVMs so they are restricted. I think we need to introduce a setting to suppress these warnings.

@kant2002
Copy link
Author

kant2002 commented Feb 3, 2017

@gorkem is there any specific location in code where I could look to implement this ? I treat any warning as errors and having that warnings don't allow me keep track of other warnings

@gorkem
Copy link
Contributor

gorkem commented Feb 7, 2017

You can have a workaround by adding access rules to the .classpath files. This has an example of how to add JavaFX entries and maintaining them.

@gorkem gorkem removed the need info label Feb 7, 2017
@fbricon
Copy link
Collaborator

fbricon commented Feb 7, 2017

@gorkem we should probably provide a quick fix that performs that change in the access rules automagically

@dawidcxx
Copy link

dawidcxx commented Mar 4, 2017

any update on this ?

javafx.scene.layout.VBox vb = new javafx.scene.layout.VBox();

produces a red underline with the following error message

[Java] Access restriction: The type 'VBox' is not API (restriction on required library 'C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jfxrt.jar')

autocomplete does seem to still work tho. i just would really need a setting to simply ignore this error.

@tomsontom
Copy link

As the author of e(fx)clipse I had to fix the same problems you see for the Eclipse IDE. There are in fact 2 things to consider for JavaFX

  • it's a library from the ext-folder
  • it's source is not part of rt-src.zip

What we do in e(fx)clipse is that we use a JDT-Extension-Point to configure the VMInstall to:

  • contain the correct accessibility rules
  • add the source-path for javafx-rt.zip

You can see our code at

@rogeriomq
Copy link

# Access restriction: The type 'Platform' is not API (restriction on required library '/usr/lib/jvm/java-8-oracle/jre/lib/ext/jfxrt.jar')
...
Solution?

@FutureProg
Copy link

Bumping this again to see if a solution has been found. Sure it compiles fine but the errors in the IDE are a little annoying.

@joewood
Copy link

joewood commented Jun 13, 2017

Seeing this too for jdk.nashorn. No idea why it's restricted. Really need a setting on the plugin to suppress these errors.

@fbricon
Copy link
Collaborator

fbricon commented Jun 13, 2017

As a workaround, to get rid of theses warnings, you can add org.eclipse.jdt.core.compiler.problem.forbiddenReference=ignore to your <project>/.settings/org.eclipse.jdt.core.prefs. You'll need to install the latest CI build for this modification to reach the java language server (#239).

@joewood see @gorkem's explanation about the restriction.

@jpitchardu
Copy link

jpitchardu commented Mar 21, 2018

Any updates on this thread? I'm working with the workaround but it would be nice to have an official fix.

@StephenOTT
Copy link

+1

@markoczy
Copy link

#276 gets closed because of this, this gets closed because of #276.. doesn't seem like a solution will come up.. +1

@dresch86
Copy link

dresch86 commented Sep 2, 2018

Any updates the status of this? I am running the latest Oracle Java 8, latest VS Code, and downloaded the CI build of the plugin yet still have this problem. I tried the 'workaround' (org.eclipse.jdt.core.compiler.problem.forbiddenReference=ignore) but that didn't work for me either. Here is what I have as far as build is concerned.

/.settings/org.eclipse.buildship.core.prefs

auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
offline.mode=false
override.workspace.settings=true
org.eclipse.jdt.core.compiler.problem.forbiddenReference=ignore

/.classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="src" output="bin/main" path="src">
		<attributes>
			<attribute name="gradle_scope" value="main"/>
			<attribute name="gradle_used_by_scope" value="main,test"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="src" output="bin/main" path="resources">
		<attributes>
			<attribute name="gradle_scope" value="main"/>
			<attribute name="gradle_used_by_scope" value="main,test"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
	<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
	<classpathentry kind="output" path="bin/default"/>
</classpath>

/.project

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>MyProject</name>
	<comment>Project MyProject created by Buildship.</comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>org.eclipse.jdt.core.javabuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
	</buildSpec>
	<natures>
		<nature>org.eclipse.jdt.core.javanature</nature>
		<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
	</natures>
</projectDescription>

/build.gradle

/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java project to get you started.
 * For more details take a look at the Java Quickstart chapter in the Gradle
 * user guide available at https://docs.gradle.org/4.10/userguide/tutorial_java_projects.html
 */

plugins {
    // Apply the java plugin to add support for Java
    id 'java'

    // Apply the application plugin to add support for building an application
    id 'application'
}

compileJava {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

// Define the main class for the application
mainClassName = 'MyClass'

dependencies {
    // This dependency is found on compile classpath of this component and consumers.
    compile 'com.google.guava:guava:23.0'

    // Use JUnit test framework
    testCompile 'junit:junit:4.12'
}

// In this section you declare where to find the dependencies of your project
repositories {
    // Use jcenter for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

sourceSets {
    main {
        java {
            srcDir 'src'
        }
        resources {
            srcDir 'resources'
        }
    }
}

/.vscode/settings.json

{
    "java.configuration.updateBuildConfiguration": "automatic"
}

I'm building a basic JavaFX example from Oracle's samples.

@snjeza
Copy link
Contributor

snjeza commented Sep 2, 2018

I tried the 'workaround' (org.eclipse.jdt.core.compiler.problem.forbiddenReference=ignore) but that didn't work for me either. Here is what I have as far as build is concerned.

/.settings/org.eclipse.buildship.core.prefs

.settings/org.eclipse.jdt.core.prefs

...
org.eclipse.jdt.core.compiler.problem.forbiddenReference=ignore
...

@dresch86
Copy link

dresch86 commented Sep 3, 2018

@snjeza Oh wow, I totally missed the paths in between. I didn't see that file in .settings, so I created it but I am still seeing the error. Is that file automatically read or do I have to point a var to it?

@snjeza
Copy link
Contributor

snjeza commented Sep 3, 2018

@primesoftware try to restart VS Code

@dresch86
Copy link

dresch86 commented Sep 3, 2018

@snjeza Still doing the same thing after restart. This is really puzzling. Are there any cache files that may be prioritized over the files in .settings?

@snjeza
Copy link
Contributor

snjeza commented Sep 3, 2018

Are there any cache files that may be prioritized over the files in .settings?

@primesoftware No, there aren't any files.
You can try to clean your workspace - https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#clean-the-workspace-directory

@dresch86
Copy link

dresch86 commented Sep 3, 2018

@snjeza That did it!!! No more nasty red underlines! Any thoughts as to why the workspace needed to be cleared?

@ESLHemantSangle
Copy link

ESLHemantSangle commented Sep 7, 2018

@primesoftware
are you able to use code completion for Javafx
I was creating Button object of javafx control but the VSCode is not giving the suggestion for Javafx control instead it gives suggestion of AWT Button

@dresch86
Copy link

dresch86 commented Sep 8, 2018

@ESLHemantSangle I had it working, but I'm having .classpath issues now since I switched to using Gradle's new .kts build scripts.

@fwcd
Copy link
Contributor

fwcd commented Oct 7, 2018

Any progress on this issue?

Editing .settings/org.eclipse.jdt.core.prefs disables the error messages, but does not provide code completion for JavaFX types.

Adding access rules to .classpath works temporarily (even with code completion), but resets every time the configuration is synchronized:

image

It would be really useful to have official JavaFX support for this in the extension, considering that it's the standard GUI toolkit.

@tomsontom
Copy link

Starting with Java-11 - It is an ordinary library you add simply as a maven dependency so the problem solves itself

@fwcd
Copy link
Contributor

fwcd commented Nov 1, 2018

@tomsontom That's a good solution, but unfortunately there are projects that rely on JDK 8 and won't update anytime soon.

Having to re-add

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/">
	<accessrules>
		<accessrule kind="accessible" pattern="javafx/**"/>
		<accessrule kind="accessible" pattern="com/sun/javafx/**"/>
	</accessrules>
</classpathentry>

every time the project changes structurally is tedious and should be fixed.

@fwcd
Copy link
Contributor

fwcd commented Dec 30, 2018

A better solution for using JavaFX with JDK 8, is to integrate the access rule directly into build.gradle using the eclipse plugin:

import org.gradle.plugins.ide.eclipse.model.AccessRule

apply plugin: 'java'
apply plugin: 'eclipse'

eclipse {
    classpath {
        file {
            whenMerged {
                def jre = entries.find { it.path.contains 'org.eclipse.jdt.launching.JRE_CONTAINER' }
                jre.accessRules.add(new AccessRule('0', 'javafx/**'))
                jre.accessRules.add(new AccessRule('0', 'com/sun/javafx/**'))
            }
        }
    }
}

That way the .classpath is not "fragile" anymore and the project configuration updates correctly automatically.

@shrey150
Copy link

shrey150 commented Aug 9, 2020

Any update on this issue? I'm still running into @fwcd 's problem: it's very annoying to manually add access rules to the pom.xml of Java 8 projects. Is there any plan to allow some form of configuration so that JavaFX in Oracle's JDK 8 plays nicely with this extension?

@fbricon
Copy link
Collaborator

fbricon commented Sep 2, 2020

So I tried @tomsontom's solution of automatically relaxing the access rules when javafx is detected in the JDK, by copying a bunch of e(fx)clipse classes to JDT.LS.
It works for Oracle JDK 1.8 and Liberica 8.0.265.FX. Other JDK 8 distros that don't ship Java FX obviously can't compile the project.

So, what next? Anything else I'd need to do to ensure JavaFX support is acceptable? (I have zero interest in Java FX myself so please enlighten me).

@tomsontom
Copy link

Well the question is could efxclipse restructure its codebase and deliver an extension one can optionally install into jdt.ls

@fbricon
Copy link
Collaborator

fbricon commented Sep 2, 2020

Anyone willing to test my changes can manually install this vsix file in vscode: https://dl.bintray.com/fbricon/vscode-extensions/vscode-java/redhat.java-0.66.999.vsix

@tomsontom if you can provide an eclipse plugin containing just those files: eclipse-jdtls/eclipse.jdt.ls#1536, then I can remove them from jdt.ls and use it directly. I don't think it's worth having another 3rd party vscode extension just for this basic JavaFX support.

@shrey150
Copy link

shrey150 commented Sep 2, 2020

@fbricon your custom vscode-java plugin fixed the issue for me, thanks! (I'm running on Oracle JDK 8u191).

@tomsontom
Copy link

@fbricon I guess the problem is that efxclipse dropped from the release train hence adopting would not be so simple for you and given the JDK-8 will be used less and less I guess it is not worth the effort

@shrey150
Copy link

Since RedHat is pushing out new updates without adding JavaFX support, I made a quick extension for Java 8 users that automatically adds the <accessrule> necessary to suppress API warnings whenever .classpath is updated in the project configuration. It's available here if anyone would like to use it:

https://marketplace.visualstudio.com/items?itemName=shrey150.javafx-support

@fbricon
Copy link
Collaborator

fbricon commented Sep 29, 2020

Fixed with eclipse-jdtls/eclipse.jdt.ls#1536. Will be released tomorrow.

@shrey150
Copy link

Thank you for fixing this!

@BenHunt-io
Copy link

I also had this issue for the com.sun.management package.

The gradle fix described by @fwcd worked. I made an example here:
https://github.com/BenHunt-io/access-restriction-vscode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests