How to create a JavaFX Maven project in IntelliJ IDEA? - java

How can I open a JavaFX Maven project from scratch in IntelliJ IDEA? As there is no difference between a Java project and a JavaFx project, I want to open a dedicated JavaFX project (Selection JavaFX from create project Wizard) with Maven module included.

Although dated I'm answering this because I had the same question recently and too many people told me to write my own pom file etc. While that is technically true, it can create more headaches if you aren't careful.
I recommend you:
Create a JavaFX project as you normally would.
Make sure that project view (dropdown in project structure side tool window) is set to 'Project' or 'Packages' (otherwise option in 4th step will not be visible)
Then once it is opened and ready right click on the project folder
Go to "Add Framework Support...".
Check the box for Maven and click "OK".
Let IntelliJ do the work for you at this point.
As for editing FXML files link the IDEA to SceneBuilder. Here is the official documentation. But basically:
Install Scene Builder.
File -> Settings -> Languages & Frameworks -> JavaFX
Point to the exe file.
To Use: Right click on the FXML file and select "Open In SceneBuilder" (way down at the bottom)

And after all, a program doesn't compiled. So this video helped me: Configuring Maven For Java FX
in words:
we need to move sample.fxml to /resources folder. And in Main.java write:
FXMLLoader loader=new FXMLLoader(getClass().getResource("/sample.fxml"));

This steps worked for me (Is a different process):
1. Create a maven project.
2. In the generated pom.xml add the following:
`<build>
<plugins>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.7.0</version>
<configuration>
<mainClass>your.package.with.mainclass</mainClass>
</configuration>
</plugin>
</plugins>
</build>`
This adds a maven plugin for javafx (more info: https://github.com/javafx-maven-plugin/javafx-maven-plugin)
Create in your resources folder your sample.fxml
Create your controller class for sample.fxml and link
Enjoy!

It takes me a couple of hours to find the right solution.
Many thanks to this video and the author:
https://www.youtube.com/watch?v=qn2tbftFjno
So, following the above video, I would like to recommend:
Download JavaFX SDK from https://gluonhq.com/products/javafx/
Extract the zip file
From the starting page of Intellij IDEA, select Configure/Structure for New Projects
Select Platform Settings/Global Libraries
Select the plus ("+") button/Java
Find the "lib" folder inside your extracted zip file and select all of ".jar" files (except "src.zip"), and then OK
Set a new name for the library, let's say "javafx-whatever-version", then
Apply/OK
Create a JavaFX project as normally.
Select File/Project Structure...
From Project Settings/Project, remember to select the suitable Project SDK and Project language level
From Platform Settings/Global Libraries, right click on the library "javafx-whatever-version" (which you have already added),
choose Add to modules.../OK
Switch to Project Settings/Modules, choose Apply/OK
Back to your project manager, right click on "src"/New/module-info.java
Add new lines to the body of module-info.java:
requires javafx.fxml;
requires javafx.controls;
opens sample;
Run the project and enjoy!

For anyone coming here. I think the best answer lies on the openjfx docs. It contains a separate section for JavaFX & InteliJ, select the Non modular with Maven section.
Ill describe the steps in breif.
Create new Maven project.
Select create from archtype.
Add new archtype ( groupid : org.openjfx , artifactId : javafx-maven-archetypes , version 0.0.1 )
Select the created archtype and Next.
Provide group id org.openjfx ArtifactId hellojavafx and Next.
Change the property archtypeArtifactId value to javafx-archetype-fxml.
Add new property for javafx version : property javafx-version and value : 14.
Finally give a name to project like HelloJavaFX.
Now click finish and wait for inteliJ to build the project.
Once InteliJ finish its work the pom should look like this sample.
PS :
Two more additional tips you need to follow if you follow this approach to get things going smoothly.
JavaFX 14 needs java 11 or newer.
Change the javax maven plugin version to 0.0.1 to 0.0.4 to avoid errors like invalid flag --module-path.
Also to work better Download and install the

If you have already installed Maven, here is the exact user guide below to create a javafx project:
Open intellij
Create javafx project in folder with other maven projects.
Click on folder (project at the top) in intellij and choose run maven and package.
Then if you need plugins for javafx click again on project folder, run maven, plugins and you choose. I needed: javafx: jlink.

Related

Eclipse Open declaration in Java project

In an Eclipse SVN project I have a problem; when I tried to open a declaration of one class, I got this error:
Problems opening an editor Reason : projectname does not exist.
Also refactoring does not work.
I have searched the web and tried all found solutions but nothing helped.
I have downloaded different Eclipse and Java versions and switched to a clean workspace but I still have the problem.
How can I solve my problem or which solution can I try?
Right Click on the project -> Properties -> Project Facets -> Click on the Configuration Link -> Click on Apply Button -> Click on OK button.
The above steps should set your project as a Java project.
If the project is a multi-module Maven project, then you need to import the child/module projects in addition to the parent/pom project. Then ensure that you only open source files via the child project. Java files opened this way will have the Refactor right-click menu item, and F3 Open Declaration etc. work properly. However if the Java file is opened from the parent project, these Eclipse functions will be missing.
It's quite frustrating when opening a file via a Search result, as the file will be found and listed in both the parent and child project. You need to ensure you only work with the file accessed via the child project.
I can't explain precisely what's going on with Eclipse, but it appears that Eclipse does not recognize the parent project as being Java projects, although it will correctly syntax-highlight the Java files whether they are accessed via the parent or child project.
You needed to to check it out as a Java Project, or preferably, its creator should have committed the .project and .classpath files for it.
I had this problem, too.
It looks like after a search-in-workspace Eclipse opened a wrong file.
I pressed Ctrl + Shift + H (Open Type in Hierarchy), typed in the class name, and opened it. The file opened in a new tab, and everything was navigable again.
The difference in icons is:
you can solve the problem by create a new java project.
when you check out the project,you should select the default option,
[Check out as a project configured using the new project wizard].
It might lack a builder. Check your PROJ_HOME/.project that should be like:
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>the-one-user</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Ref:
FAQ How do I add a builder to a given project?
Are you importing a maven project? If you importing a maven project, a file will be viewed in few perspective, especially if you open the file via "Open Resource (Ctrl + Shift + R)".
Let's look at the example above, "servlet-filter" (mark as 1) imported as maven project, and maven perspective project created in 2. If you open a file in 1, your "Open Declaration F3" will no work, because it is not a valid maven project. It will work if you open the same file in 2.
Hope this helps.
You need to import it as a Java/Maven project. Once you are done importing the project do the following steps
Go to Project -> Select Properties -> Select Project References -> Select/Check all the
dependent/Child projects which you reference in the code base -> Apply
and Close
Once you are done, try to clean the whole project. This should solve the issue.
There is a bug in Eclipse (in Luna at least) for a very specific workflow, which might not be the answer to this specific question, but might be helpful for others.
If you perform an import into the src (meaning src folder has focus before performing import) folder from an extracted jar (as source code), and you place breakpoints in the nested *.java files in the nested packages, it won't hit those breakpoints. In order to get things to work, you must keep hitting F3 instead of using "Open Declaration" to get to the *.java file you want to set a breakpoint in, then add the breakpoint by double clicking in the far left margin. Then Run > Debug As > Java Application.
If the format of the project you checked out is of type Maven, you need to convert it to a Maven project first. It may be because the required classes haven't been generated yet. To do this, right-click on the project, click Configure, and then click Convert to Maven Project.
I had the same in Eclipse Luna on Debian 8.
I was missing the .classpath file when checking out from SVN.
I manually copied it and changed some path names, refreshed the project and it was working again.
It happens, when libraries are not available on class path of the project where F3 does not work.
Select any other project and try to use f3 for navigation. It will work.
The solution is to add JAR files in your libraries or add libraries in your project.
Try to use MAVEN project so that the problem can never occur.
I am using Eclipse Oxygen.2 (4.7.2). I don't see Project Facets after clicking project -> Properties. My solution is right click the project and click Configure, then select configure and detect nested projects, Eclipse will automatically generate the nested projects for you. May get some build errors in the new created projects, that should be easy to fix.
Go to Project properties,Select Project Facets then convert to project facets then click Ok then you will able to open editor.

Netbeans there is a way to create an empty project?

I 'am a Visual Studio (VB.net / C#) programmer and I have installed Netbeans.
When I open a new project 'Java application' don't create a new EMPTY project but add the project to the other previous projects.
In Visual Studio (and all other IDEs) if I choose 'new project' after I see ONLY my new project and not all projects.
How can I do to create only a new empty project with Netbeans ?
P.S.
I don't want use Eclipse becouse I need a Visual Ide (form in particual) and Netbeans see better for this point.
Thank you !
In Tools-Plugins install Freeform project Extras.
Create
Java Free-form project or
empty Ant-based project or
Skeletal Ant-based project
Right click on the other projects and choose "Close Project"
Use:
File->Project Group->New Group...
There's no explicit form for doing that.
As a workaround you can create a project of any type according what you will want to do (Java, C++, PHP, HTML, etc), and then delete the resources created automatically except "nbproject" folder.
With this approach you have something similar to an empty project.
I recently used this trick for group some modules created for PrestaShop and then push them to Git VCS as if it were a single project, when actually each module is an independent project folder.

How to organize jar files in a libraries folder in Eclipse?

I have a Java Project in Eclipse, and a Java Dynamic Web Project in Eclipse. In the former, all the jar files are shown individually under the top-level project folder. In the latter, the jar files are under a Libraries folder and the navigation is more convenient.
Is it possible to organize them in the same way in the Java Project also? If so, how?
Update: It is the Project Explorer View. For the Java Project, I see: "my_project_name" with the arrow expanded to point downwards, then I see: "package_icon src/main/java" and below that "package_icon src/main/resources" and then 20 jar files one below the other: "jar_icon activation-1.1.jar", ...
For the Java Dynamic Web Project I see: "my_project_name" as above, then I see: "JAX-WS Web Services" (unexpanded), then "Deployment Descriptor" (unexpanded), then "Java Resources" which I have expandeded, so I see the components of it below, of which the first is: "package_icon src/main/java", then below it, "package_icon src/main/resources", then below it "libraries_icon Libraries" instead of 20 jars! I have the option of expanding Libraries if I really need to see the 20 jars.
The only option I found to make things prettier in Eclipse Kepler is to:
In the Project Explorer window there is a down arrow in the upper right corner. Select that and then Customize View.
Select 'Libraries from external' and then OK.
Kind of cheesy...
EDIT: Of course I had to go and do some more digging...and it looks like I'll have to try this and see how it works.
Similar to M Miller's answer (but for Juno), click Show 'Referenced Libraries' Node in the dropdown of the Package Explorer window:
I'm using:
Eclipse IDE for Java Developers
Version: Juno Release
Build id: 20120614-1722
I noticed this "feature" on Eclipse Juno (latest version), when you have a jar file added to the build path it is not shown as a single file on the project.
Try removing one of the jars from the build path to see if it shows up again.
I couldn't find how to turn it off though.
BTW... the project layout for your "Java Project" is more akin to a "Maven Project", which is a bit more powerful.
You should change into the Package Explorer by Window > show View. It will display all the referenced libraries in a Referenced Libraries folder.

Import source java project in Android project

Is it possible to import an existing Java project which is in my workspace, in an Android project which is also in my workspace? The Java project doesn't use stuff that is incompatible with Android. I could do it using a .JAR, but since I'm modifying the Java project a lot, I would like to import the whole source code and change it once in a while. Is it possible? Thanks
This is somewhat of a hack, but worked for my project:
Add both Android project and plain Java project to workspace
Go to properties for Android project -> Java Build Path -> Source
Click Link Source, in "Folder name", make sure to select the root directory of the plain Java project's src tree
Use a descriptive name for "Linked folder location", like "java_project_src".
Press Finish and compile
This setup will compile the plain-java code as Dalvik bytecode. In my case, I had pure java code with very limited dependencies, but wanted to share the pure java code with non-Android projects, instead of separately maintaining these files in every project.
I think you are talking about referencing other projects into the current project, if this is the case then you can do this by Right click on project, properties->Project Reference.
You can link another projects to your current project. Right click on your main project, choose Build Path -> Configure Build Path... In the dialog choose the Projects tab, then click Add.. button. Now choose the project you want to link and click OK. You'll now be able to use this project's sources inside your main project. Hope this helps.

How to change an Eclipse default project into a Java project

I checked out a project from SVN and did not specify the project type, so it checked out as a "default" project. What is the easiest way to quickly convert this into a "Java" project?
I'm using Eclipse version 3.3.2.
Open the .project file and add java nature and builders.
<projectDescription>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
And in .classpath, reference the Java libs:
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
</classpath>
Manually changing XML and/or settings is very dangerous in eclipse unless you know exactly what you're doing. In the other case you might end up finding your complete project is screwed. Taking a backup is very recommended!
How to do it just using Eclipse?
Select project.
Open the project properties through Project -> Properties.
Go to "Targetted Runtimes" and add the proper runtime. Click APPLY.
Go to "Project Facets" and select the JAVA facet which has appeared due to step 4. Click APPLY
Set your build path.
If it's a Maven project, you might want to select the project, click Maven -> Update Project configuration...
That did it for me. And Eclipse is configured correctly. Hope it'll work for you too.
In recent versions of eclipse the fix is slightly different...
Right click and select Project Properties
Select Project Facets
If necessary, click "Convert to faceted form"
Select "Java" facet
Click OK
I deleted the project without removing content. I then created a new Java project from an existing resource. Pointing at my SVN checkout root folder. This worked for me. Although, Chris' way would have been much quicker. That's good to note for future. Thanks!
Using project Project facets we can configure characteristics and requirements for projects.
To find Project facets on eclipse:
Step 1: Right click on the project and choose properties from the menu.
Step 2:Select project facets option. Click on Convert to faceted form...
Step 3: We can find all available facets you can select and change their settings.
In newer versions of eclipse (I'm using 4.9.0) there is another, possibly easier, methods. As well as Project Facets, there are now Project Natures. Here the process is simple get the Project Natures property page up, and then click the Add... button. This will come up with possible natures included Java Nature and Eclipse Faceted Project Properties. Just add the Java Nature and ignore the various warning messages and your done.
This method might be better as you don't have to convert to Faceted form first. Furthermore Java was not offered in the add Facet menu.
Joe's approach is actually the most effective means that I have found for doing this conversation. To elaborate a little bit more on it, you should right click on the project in the package explorer in eclipse and then select to delete it without removing directory or its contents. Next, you select to create a Java project (File -> New -> Java Project) and in the Contents part of the New Java Project dialog box, select 'Create project from existing source'.
The advantage this approach is that source folders will be properly identified. I found that mucking around with the .project file can lead to the entire directory being considered a source folder which is not what you want.
You can do it directly from eclipse using the Navigator view (Window -> Show View -> Navigator). In the Navigator view select the project and open it so that you can see the file .project. Right click -> Open. You will get a XML editor view. Edit the content of the node natures and insert a new child nature with org.eclipse.jdt.core.javanature as content. Save.
Now create a file .classpath, it will open in the XML editor. Add a node named classpath, add a child named classpathentry with the attributes kind with content con and another one named path and content org.eclipse.jdt.launching.JRE_CONTAINER. Save-
Much easier: copy the files .project and .classpath from an existing Java project and edit the node result name to the name of this project. Maybe you have to refresh the project (F5).
You'll get the same result as with the solution of Chris Marasti-Georg.
Edit
Another possible way is to delete the project from Eclipse (but don't delete the project contents from disk!) and then use the New Java Project wizard to create a project in-place. That wizard will detect the Java code and set up build paths automatically.
Right click on project
Configure -> 'Convert to Faceted Form'
You will get a popup, Select 'Java' in 'Project Facet' column.
Press Apply and Ok.
Depending on the Eclipse in question the required WTP packages may be found with different names. For example in Eclipse Luna I found it easiest to search with "Tools" and choose one that mentioned Tools for Java EE development. That added the project facet functionality. Searching with "WTP" wasn't of much help.

Categories

Resources