I tried to create a JavaFX application in IntelliJ Idea IDE but I got compile error that said:
java: package javafx.application does not exist.
I have changed the Project SDK and the Project Language Level to Java 8, reloaded the project but it didn't help. Then I checked if JavaFX plugin was enabled in the settings.
The search on Google and StackOverflow didn't give me more ideas of what is wrong.
Thank for any help in advance.
P.S. I am using IntelliJ Idea 14.0 with java8.1.0_25 on archlinux OS.
As indicated here, JavaFX is no longer included in openjdk.
So check, if you have <Java SDK root>/jre/lib/ext/jfxrt.jar on your classpath under Project Structure -> SDKs -> 1.x -> Classpath? If not, that could be why. Try adding it and see if that fixes your issue, e.g. on Ubuntu, install then openjfx package with sudo apt-get install openjfx.
This should be your perfect solution. Try and enjoy.
If some command does not work properly that means if you get any error, try to solve it yourself. I have given you the main thing you need. If your application is in a different location, or your system architecture is different, solve it yourself. It's very easy to do it. Just follow my given solution.
Step 0:
sudo apt-get install openjdk-8-jre
Step: 1
sudo apt-get install openjfx
Step 2:
sudo cp /usr/share/java/openjfx/jre/lib/ext/* /usr/lib/jvm/java-1.8.0-openjdk-amd64/lib
Step 3:
sudo cp /usr/share/java/openjfx/lib/* /usr/lib/jvm/java-1.8.0-openjdk-amd64/lib
Step 4:
sudo chmod 777 -R /usr/lib/jvm/java-1.8.0-openjdk-amd64
now open a new project or rebuild your project.
Good luck.
You can use the one that comes with IntelliJ: <intellij>/jre64/lib/ext/jfxrt.jar.
You need to download the java-openjfx package from the official Arch Linux repos. (Also, make sure you have the openjdk8-openjdk package). After doing that, open your project in Intellij and go to Project-Structure -> SDKs -> 1.8 -> Classpath and try removing the old JDK you had and clicking on the directory for the new JDK that will now contain jfxrt.jar.
Another way to resolve the problem :
Click the left mouse's button on the project folder in the project structure at the left, and click on "open module settings" in the list of actions
In the new windows, click on SDKs which is under the menu title "Platform settngs"
Then check on the "Classpath" list if you can find the jfxrt plugin path, if not, click on the + symbol on the right and select the repertory of the jfxrt plugin (C:\Program Files\Java\jdk1.8.0\jre\lib\ext\jfxrt.jar on my desktop)
Sample Java application:
I'm crossposting my answer from another question here since it is related
and also seems to solve the problem in the question.
Here is my example project with OpenJDK 12, JavaFX 12 and Gradle 5.4
Opens a JavaFX window with the title "Hello World!"
Able to build a working runnable distribution zip file (Windows to be tested)
Able to open and run in IntelliJ without additional configuration
Able to run from the command line
I hope somebody finds the Github project useful.
Instructions for the Scala case:
Additionally below are instructions that work with the Gradle Scala plugin, but don't seem work with Java. I'm leaving this here in case
somebody else is also using Scala, Gradle and JavaFX.
1) As mentioned in the question, the JavaFX Gradle plugin needs to be set up.
Open JavaFX has detailed documentation on this
2) Additionally you need the the JavaFX SDK for your platform unzipped somewhere.
NOTE: Be sure to scroll down to Latest releases section where JavaFX 12 is (LTS 11 is
first for some reason.)
3) Then, in IntelliJ you go to the File -> Project Structure -> Libraries, hit the ➕-button and add the lib folder from the unzipped JavaFX SDK.
For longer instructions with screenshots, check out the excellent Open JavaFX docs for IntelliJ I can't get a deep link working, so select JavaFX and IntelliJ and then Modular from IDE from the docs nav. Then scroll down to step 3. Create a library. Consider checking the other steps too if you are having trouble.
It is difficult to say if this is exactly the same situation as in the original question, but it looked similar enough that I landed here, so I'm adding my experience here to help others.
You might have a lower project language level than your JDK.
Check if:
"Projeckt structure/project/Project-> language level" is lower than your JDK.
I had the same problem with JDK 9 and the language level was per default set to 6.
I set the Project Language Level to 9 and everything worked fine after that.
You might have the same issue.
In IntelliJ Idea,
Check the following things are configured properly,
Step 1:
File -> Setting -> Plugins -> search javafx and make sure its enabled.
Step 2: Project Structure (Ctrl+Shift+Alt+s)
Platform Settings -> SDKs -> 1.8 -> Make sure Classpath should have "jre\lib\ext\jfxrt.jar"
Step 3:
Project Settings -> Project -> Project SDK - should be selected 1.8
Project Settings -> Project -> Project language level - configured as 8
Ubuntu: If not found jfxrt.jar in your SDKs then install sudo apt-get install openjfx
If you are working with IntelliJ and JDK 11
1. go to project structure ctrl + alt + shift + s.
2. add the mising
javafx libraries in the Global Libraries section.
3. add a module-info.java file with the required dependencies to your module.
module modulename {
requires javafx.fxml;
requires javafx.controls;
opens sample;
}
4. rebuild the project !
5. enjoy !
I had the same problem, in my case i resolved it by:
1) going to File-->Project Structure---->Global libraries
2) looking for jfxrt.jar included as default in the jdk1.8.0_241\lib (after installing it)
3)click on + on top left to add new global library and i specified the path of my jdk1.8.0_241 Ex :(C:\Program Files\Java\jdk1.8.0_241).
I hope this will help you
I am using apache maven with java 11 and I was able to remove all java fx problems by adding this dependency to my pom.xml file:
<!-- JAVA FX -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17.0.1</version>
</dependency>
For me the simplest solution was to use Amazon Corretto, it is pretty much same as Oracle java.
Follow the steps:
Go to Intellij, File -> Project Structure
Go to SDK
Download SDK
From the dropdown, choose 1.8 as Java 1.8 version comes bundled with JavaFX library.
And you are good to go.
I had a similar issue, my error message was slightly different though:
java: package javafx.event does not exist
I found one solution to fix this issue. Instead of adding dependencies, modifying CLASSPATH or trying different JDK / SDK versions, you can simply select:
File -> New Project -> JavaFX -> Location of the code
After restarting, the build is successful.
Related
I've been trying to set up a new Kotlin project in IntelliJ IDEA, using the default IntelliJ Build System (not Gradle) and JDK 15. Whenever it creates the default main.kt file, and I try to build and run the main function, which looks like this:
fun main(args: Array<String>) {
println("Hello World!")
}
the build fails after a short time with the following errors:
Kotlin: Cannot access built-in declaration 'kotlin.Array'. Ensure that you have a dependency on the Kotlin standard library
Kotlin: Cannot access built-in declaration 'kotlin.String'. Ensure that you have a dependency on the Kotlin standard library
and
Kotlin: Unresolved reference: println
I've tried changing the project SDK to the kotlin SDK, to Java 14 and to Java 1.8. I'm not sure exactly how to add the dependency it asks for. Any help is appreciated.
This is what the dependencies window shows within the project:
Right now the project is using JDK 15, and Kotlin 1.4.10. I've tried updating the plugin, uninstalling and reinstalling, deactivating and reactivating, all to no avail.
The project files can be found here on Google Drive
Try enabling KotlinJavaRuntime
Open Project Structure window (File > Project Structure)
Go into Modules
Go to Dependencies tab
Tick the Enable KotlinJavaRuntime checkbox
Removing the .idea/library file inside the project directory and then selecting "use library from plugin" when prompted to configure Kotlin files by the IDE solved the problem.
Please provide more information and check what Kotlin version do you have installed:
Tools > Kotlin > Configure Kotlin Plugin Updates: install the latest version of Kotlin
File > Project Structure > Project: what is your Project SDK there? Choose 15 (something line java version "15.0.1"). If you don't have 15 there, click "+" and add the newest version (unless you need an older version).
Probably you need to add KotlinJavaRuntime library in you project. Please see paragraph "Create Kotlin files in Java projects" in https://www.jetbrains.com/help/idea/mixing-java-and-kotlin-in-one-project.html
After configuration you should see needed jars in lib folder in your project. Rebuild you project. Make also File->Invalidate Cache/Restart.
I tried all of the above but eventually found out, that in one project, my SDKs were completely broken after the newest Intellij Update. If you go to Project Structure -> Platform Settings -> SDKs, I had an entry for Kotlin with a non existing path for an Intellij Version of last year. This was definitely not there before and it seems to have messed up the kotlin installation. After i deleted that entry and as described above the libraries as well, it worked again.
For me this helped:
Close the project
Delete idea. folder
Open project
I have a Ubuntu 16.04 with IntelliJ 2020.3 newly installed. I run to the same issue here.
To solve this issue, I made a new kotlin file in my project. Then when the system was trying to add this new Kotlin file, you can find a notification related to "Configure project" on the right bottom corner of screen, click the notification. I get the following dialog.
Then check the Use library from plugin, this solve the issue.
Use library from plugin
In this case, it was a misconfigured IntelliJ instance.
Project Structure -> SDKs -> kotlinSDK -> + -> ok
rebuild will be work fine
In my case the Kotlin Standard Library JDK extension was missing. https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib-jdk8
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>1.7.21</version>
</dependency>
I know there is already questions about it on stackoverflow, but none of them helped me answer my question. I just downloaded idea with the scala plugin and created a new scala project. I got the error no jdk for this project.
After looking on internet I understood that I need to give it the java sdk for it to run. readlink -f $(which java) gave me the java jdk location (/usr/lib/jvm/java-8-oracle/jre/bin/java) but adding it to the option like shown below didn't help.
How to configure the project sdk for an sbt project ?
To set the JDK, go to the Project Structure dialog in the "Project" tab. If you haven't set up a JDK yet, click "New..." and choose the home directory. Note that this needs to be a JDK (download from Oracle or install via apt), not the JVM you are using in your screenshot.
Go to Project Structure and do what I marked on the screen
When I run Gradle project via Eclipse I get below error.
system Cannot find System Java Compiler.
Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.
Could not execute build using Gradle installation 'C:\gradle-1.2-all\gradle-1.2'.
But I have installed JDK 1.7 and set the JAVA_HOME environment variable.
Go to File -> Other Settings -> Default Project Structure
Now Set your JDK location
In Preference of Eclipse (main menu: Window -> Preferences), select
Gradle -> Arguments -> Java Home, select "Workspace JRE".
Then select one of your jdk in your workspace.
On my laptop it's "jdk1.6.0_45". Yours should be the JDK 1.7 home folder, something like "/usr/lib/jvm/java-7-openjdk-amd64/".
You can face this problem even when all your system variables are set and correct. Usually this happens when you work with foreign code from Github etc.
So what you have to do is to check gradle version in your project level build.gradle file, and if it doesn't match to current installed version, update it.
buildscript {
//other setupps
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0' //update this to your current version
}
}
In Gradle Task View -> build -> right click->Open Gradle Configuration -> JAVA_HOME -> and put the current value of your enviroment, something like C:\Program Files\Java\jdk1.7.0_79
I hope this help you
I tried following, but in Eclipse (luna), Run as, "gradle build Gradle build", still failed.
change JAVA_HOME
Preference, Gradle -> Arguments -> Java Home, select "Workspace
JRE".
Solution: Go command line, run gradle build as answered by user3754672, then back to Eclipse, all working.
It's likely you haven't installed a JDK. Even though you have "jdk1.7", you may have only the runtime environment. You may need to install the "-devel" option for the package, for example, both these would be required:
java-1.7.0-openjdk
java-1.7.0-openjdk-devel
If you can't find the right package, tell us your distro and the exact name of the jdk1.7 package you have so we can help more.
Although you may have a full JDK installed somewhere, and pointed to by JAVA_HOME, I don't think the Eclipse Gradle plugin will use it by default. I ran into the same problem running the the "test" target for the Gradle "quickstart" app in Springsource Groovy/Grails Tool Suite 3.3.0(Gradle IDE 3.3.0.201307040643 plugin).
If you re-run the failed Gradle target from the "External Tools" menu (under the "arrow with a suitcase icon"), adding "--debug" in the "Program Args" under the Arguments tab, it will show you in the console what JVM/JDK it uses. I was able to get around the problem by deselecting "Use Gradle wrapper's default" in the Java Home section of the Arguments tab, and replacing it with an Execution Environment setting that pointed to my 1.7 JDK that I had installed. I'm sure there's a way to have it do this by default, so you don't have to configure each targets run configuration, but this method should fix the immediate problem.
I think the wrapped gradle uses the same java as eclipse. Since Eclipse seems to use jre by default you can get the issue mentioned in the question.
Try this: Go to your eclipse.ini and add -vm argument like this:
-vm
c:/java/jdk1.8/javaw.exe
Issue
Using the Eclipse -> gradle -> select task to execute and
error "...cannot find system java compiler."
Solution
Go to the path where your build.gradle path is... and using the cmd manually type
gradle build <- this will work.
Done.
Back to Eclipse and execute the gradle task. It will work again!
Change your gradle to min: classpath 'com.android.tools.build:gradle:2.0.0'and then Android Studio will ask you to update it. You will make and update of gradle and after that it will work.That is how I fixed it for me.
I deleted some old jdk's and encountered the same issue. None of the above outdated solutions worked. Gradle in its infinite wisdom stores the JDK location in C:\Users\User.gradle\gradle.properties. This property is not accessible via the IDE as far as I know.
My Eclipse version:
Eclipse Java EE IDE for Web Developers.
Version: Photon Release (4.8.0)
Right click 'gradle.build' and then choose 'run as' -> 'Run Configurations'. In the left, choose 'gradle.build' under 'Gradle Project'. In the right, you could see something like 'Gradle Tasks', 'Project Settings', 'Java Home' and so on. Choose 'Java Home', you will see there is an input box. Put your JDK path there. (something like: C:\Program Files\Java\jdk-10) And then run.
I reinstalled my eclipse. and then imported all the projects in the Eclipse, but every project has a common error:
Cannot find the class file for java.lang.Object. at Line 1.
I have checked my Java Path. But not able to sort it out.
Right click on Project--> Properties, Java Build Path.
Check whether you have JRE installed. If installed click on EDIT and check whether its pointing to correct location
Check this if it works:
There is a problem with your java repositories. I guess..:
goto Help>Install New Software> Click on Add Button .
on popup:
Name: ADT
Location:https://dl-ssl.google.com/android/eclipse
Install all the available softwares in the list. This may work.
Have a good day!!!
A quicker way will be
Right Click Project---> Properties--->Build Path--->Add External Jars--> Find your android-xx.Jar e.g android-17.jar
In my case I'm using the adt and it is here
E:\adt-bundle-windows-x86_64-20130219\adt-bundle-windows-x86_64-20130219\sdk\platforms\android-17
Hope it helps
This happened to me when I tried to merge two branches of an Android project using eGit. For some reason my build path basically disappeared (possibly one of the files was untracked).
To get the JRE and android libraries back, I just right-clicked on the project in the project explorer, and hit Android Tools -> Fix Project Properties (these options are only available if you have Android ADT installed).
Try this:
Go to Build Path -> Libraries -> Add Library -> JRE System Library -> Select JRE
I am not sure but you might be missing JRE System Library in your project, this does not happen often but it is possible.
I just had this problem and all I had to do was clean the entire workspace, i.e. all projects in the workspace. The error went away.
I've had this problem after installing a newer version of Google ADT.
The solution, at least running OS X, is to make a copy of your project to a safe location, delete it completely from Eclipse and then import it again using File->Import->General->Existing Projects into Workspace.
FYI
I am Using Google's on OS X Mavericks
Android Developer Tools
Build: v22.2.1-833290
but I am almost sure I have done in the past with previous OSX and ADT versions.
I had this issue too and in my case the issue was that the following line was missing from the .classpath file of the current project:
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
Adding it solved the problem for me.
This error is because one of "Android Private Libraries" is either corrupted or of wrong version.
In my case it was android-support-v4.jar.
I replaced it with one from a working project and it works.
I'm trying to setup JDK in IntelliJ IDEA and whatever I do, or whatever JDK version I select, nothing happens. The following situation remains:
So I told IDEA what JDK it should use, but it still asks me to setup a JDK. Is this a bug or am I missing something? Can I apply any workaround to make everything work as usual?
ADDITION
The steps which I go through setting up the JDK:
situation before setting up:
the first step:
the second step:
the third step:
the situation after setting up JDK:
SDKs:
module settings:
File | Invalidate Caches is the first thing you should try in case of such issues.
Select your modul in the "Project View" and press F4 in the "Project Setting"select "Module".
In the "Module Settings" overview you can add/remove the Modul SDK.
Following this worked for me :
Select your module in Project View
Press F4
Go to SDK
Select you SDK
Make sure you have various jars in there. Else, select proper directory.
In my case, even though correct directory was selected classpath,sourcepath etc were empty.
So I had to select jdk installation directory one more time, which loaded all the jars and solved the problem.
In my case just File | Invalidate Caches and Restart did not work. Upon Right clicking the project and going to Module Settings , I had no SDK selected under Project Settings->Project.
I followed below steps
Press F4
Select Modules in Project Settings
Set up Module SDK from the drop down or add the new one.
Apply & OK
For someone like me, looking for a way to setup an offline documentation in IDEA on UBUNTU Linux. You should install the openjdk-8-doc (or openjdk-X-doc in general case) package, then go to File|Project Structure|SDKs|1.8(still 1.X in general), then select tab Documentation Paths and add the path /usr/lib/jvm/java-1.8.0-openjdk-amd64/docs/api there.
Note, that path of Java docs installation may differ on your machine. You are able to check the path of Java docs installation executing dpkg-query -L openjdk-8-doc | less in a shell.
I was seeing this exception in the console:
NoClassDefFoundError: com/intellij/remote/RemoteSdkConnectionAcceptor
which was caused by the python community edition plugin on Intellij IDEA 2016.2.5.
After updateing/disableing the plugin, I was able to setup the SDK again.