JavaFX 11 development in both IntelliJ and Visual Studio Code - maven

I'm setting up a Maven project based on Java/JavaFX 11 which should be both editable in IntelliJ and Visual Studio Code.
My JDK is 11.0.3 (Windows x64) from https://adoptopenjdk.net/.
The pom.xml has a dependency for
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
My app can be compiled and run with "compiler:compile" and "exec:java" in IntelliJ. So step one succeeded.
Now when opening the same project in Visual Studio compiling and running does not succeed with a lot of similar error message
The package javafx.scene.chart is accessible from more than one module: <unnamed>, javafx.controls
I added a settings.json file in .vscode to point to the correct JDK directory.
{
"java.dependency.packagePresentation": "hierarchical",
"java.home": "C:/Program Files/Java/jdk-11.0.3+7",
"java.configuration.updateBuildConfiguration": "automatic"
}
But it still seems VSC has issues with two JavaFX versions, or isn't using the correct JDK. In the "Java Dependencies" view I can see references from both "JRE System Library" and "Maven" to JavaFX. Is there a way I can exclude them from the JRE view?
Screenshots as how JavaFX references are shown in VSC:

Based on the last screenshot posted, it seems that you are using a JDK 11 that does include JavaFX.
While most of JDK distributions don't include JavaFX (OpenJDK, Oracle, AdoptOpenJDK among others), some vendors are bundling JavaFX with the JDK, like Liberica.
If you check Liberica's release notes for JDK 11.0.2:
Windows x86_64, Mac, Linux x86_64 and Linux ARMv7 distributions contain OpenJFX 11.0.2.
While this option simplifies the use of JavaFX (no need to add it to the module-path, as it is already part of it), it can be confusing if you use Maven or Gradle build tools and include the JavaFX dependencies, or if you have other JDKs installed without it.
So the fix is easy: either use JDK without JavaFX and provide it via Maven/Gradle dependencies, or use JDK with JavaFX and don't include them.
I guess the latter is the preferred option, in case you need to export/share your project, since others might not have the same setup. Also it makes it more flexible to new releases of JavaFX.
As an aside, note that you can produce your own JDK that bundles JavaFX, following the instructions at https://openjfx.io/openjfx-docs/#modular, section Custom JDK+JavaFX image.

Related

How to fix `#USE_PROJECT_JDK` when opening gradle project in IDEA?

Everytime I open a gradle project, if I use default settings, it has an invalid gradle JVM:
I have to fix it by selecting another valid JDK every time, since the configuration here is just "for current project":
I can't find a way to setup a global or default option for all projects.
Do I missing anything?
I finally found the problem.
In my system, openjdk 11.0.1 is installed by mistake and be my default jdk (which means I run java -version in terminal will print 11.0.1). When I open an existing gradle project, I used to go to the dir from command line and type idea .. IDEA detects openjdk 11.0.1 and uses it as the project jdk. Since I don't really want to use this version of JDK, I deleted its configuration from IDEA(not from the OS).
In order to make IDEA uses JDK 1.8 by default, my solution is to delete openjdk 11.0.1 from system completed and make sure JDK 1.8 is the default. Now everything is OK.
PS: I still think it's be great to have a way to setup default JDK version for all new projects, currently we can also set for individual projects.

Spring STS - Maven build error - No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? Spring

Installed JRE pointing to JDK & Libraries pointing to jre[Please note- there solutions out there Eclipse, but I'm using Sprint STS]
Spring Tool Suite Version: 3.9.3.RELEASE
Apache Maven 3.2.5
Java- 10.0.1
OS - Windows 10
Tomcat 8.5
I have already verified Installed JRE has a JDK entry. Have verified JAVA_HOME and Path environment variables.
Maven Clean & Validate works. Maven Compile does not work.
Gives me error - "No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? "
Can someone please help?
Your workspace needs to be configured with a JDK.
Goto Preferences->Java->Installed JREs and Add your JRE there. Point at a JRE (with a JDK).
Then right-click on your project and select Build Path->Configure Build Path->Libraries->Add Library to make sure that JRE is associated with your project.
I faced same error while using spring tool suite 4 IDE.
To resolve these issues, follow these steps:
Right click on project
Select Build path option
Click on configure Build path
Go to libraries tab
Click on Add Library option
Select JRE System Library
Select Alternate JRE option
Click on installed JRE's button
Click on ADD
Select Standard VM
Click on directory
Select the path to JDK
Click Apply & Close.
That's it, issue was resolved and maven build was successful.
I hope this works for eclipse too. It worked for me.

On Eclipse Mars, I can't see 1.8 in the compiler compliance level menu

I'm using Eclipse Mars and I can't see 1.8 in the compiler compliance level menu.
Prehaps, it is because I used this option to import all my plugins from my Eclipse Kepler installation. Maybe it also import preferences that causes this problem.
I added the jdk 1.8 in the Installed JREs.
I tried to delete the .preferences folder and restart my eclipse but I still have the problem.
Any ideas?
EDIT : I tried to check for updates but no updates were found
You need to select the appropriate java version in the project's/ build path first
If you want to apply it globally you not only have to add a 1.8 JRE but also select it as default.
I had the same problem. Probably it was because I originally installed Eclipse Kepler (which doesn't support java 1.8. compiler) and then updated it to Luna first and then to Mars. I had to completely uninstall Eclipse and reinstall newest version.
If you have a shortcut to start eclipse, edit it and add -vm [path-to-jdk-1.8]/jre/Javaw.exe after the path to eclipse.exe .
You can also add the code to your eclipse.ini but make sure it is the very first line. Afterwards you might be able to chose 1.8 in the global compliance level

Gradle using terminal with Android Studio install on Ubuntu 12.04

Can not get the terminal commands to work with gradle. I am trying to get Gradle to work outside of Android Studio as a prelude to scripting up various flavors of my app. I got the flavors to build within Android Studio but I find the interface confusing.
Gradle was installed either with ADT or Android Studio at: /home/mark/.gradle
Would like to use the install of Gradle at /home/mark/.gradle. Would like to avoid the Gradle in the repo since Android Studio updates frequently and their a possibility that I could wind up with two different versions of Gradle that could cause more headaches.
So far I have tried setting the PATH various ways in .bashrc bash.bashrc environment
files. Nothing worked.
Not sure if I put the wrong terms/commands in those files or the files are wrong ones. Tried the gradle term with and with out the dot as well. I would appreciate explicit instructions on terms/commands and in what files.
The gradle executable is usually installed here (when installed by by android-studio):
<user_home>/.gradle/wrapper/dists/gradle-<version>-bin/<some_key>/gradle-<version>/bin/
So be sure that your PATH variable include this path.
Alternativelly, you can download the gradle distribution, unzipping it in a more convenient location and use that location in your PATH.
Wathever your choice is (i.e. using the gradle installed by Android-Studio or download and install a distribution of gradle yourself) : you have to take care to maintain your PATH variable up-to-date when you install a newer version of Android-Studio.

How to harmonize Eclipse projects between Windows and Ubuntu?

I have a laptop that can dual boot into Windows 7 or Ubuntu. Whenever I use Eclipse on Windows and then boot into Ubuntu or vice versa, Eclipse can't find some of the jar files I'm using for my project. Specifically, jfxrt.jar, for JavaFX.
For example, when I use Eclipse on Windows, under Referenced Libraries, it says that the jar file is in C:\Program Flies\Java\jdk1.7.0_25\jre\lib. When I boot into Ubuntu, it still says that the the jar is in C:\Program Flies\Java\jdk1.7.0_25\jre\lib, and surprise surprise, it can't find it. So I change it to the correct location for Ubuntu. It's all well and good until I boot back into Windows, where I have the same problem.
Is there any way to avoid this?
Did you add the jar to the library as an external jar? That would be the path it stores, then. Use a variable instead if you have to add it manually: http://help.eclipse.org/juno/topic/org.eclipse.jdt.doc.user/reference/preferences/java/buildpath/ref-preferences-classpath-variables.htm?cp=1_4_2_0_1_0 . It's possible, though, that if this is part of Java 7, you just need the latest version of Eclipse--it supports Java 7 explicitly.

Resources