How to create an empty JavaFX project in IntelliJ - intellij-idea

Every time I create a new JavaFX project in IntelliJ it loads a simple HelloWorld project in it. How can I make it empty instead (without the need to delete those .java files every time)? Also how can I choose to create the project without a building system (as you can see in the picture, I'm always forced to create the project with Maven or Gradle)

When creating the new project, choose "Java" instead of "JavaFX".
A JavaFX application is just a Java application, so if you don't want the additional things which IntelliJ is doing when you choose to create a JavaFX project (e.g. supplying example code and associating with a build system like Maven or Gradle), you can just choose a basic Java application project from the wizard and it won't do those other things.
See the section in openjfx.io documentation titled "JavaFX and IntelliJ IDEA" for other steps you need to take:
Set the project JDK
File -> Project Structure -> Project
Create a JavaFX library in Idea
File -> Project Structure -> Libraries
Point to the lib folder of the JavaFX SDK.
Add VM options for the module path
Run -> Edit Configurations...
--module-path /path/to/javafx-sdk-15.0.1/lib --add-modules javafx.controls,javafx.fxml
For windows use quotes around the path and \ rather than /.
Run the project
Run -> Run...
You might also need to take the actions identified in the accepted answer to:
How to convert a normal java project in intellij into a JavaFx project
But that answer was written a while back and setting the resource copy configuration to include JavaFX fxml and css files might not be needed anymore.
Now, you might think that is annoying amount of things to do, and I might agree with you.

Related

HelloWorld in Kotlin gives error "Could not find or load main class"

I spent the last 1,5 hour trying to make this simple tutorial work in IntelliJ IDEA, as you can see in this video.
When trying to run the code, I get the error:
/[...] -Dfile.encoding=UTF-8 src.HelloKt
Error: Could not find or load main class src.HelloKt
Caused by: java.lang.ClassNotFoundException: src.HelloKt
I have tried setting up SDK, invalidating cache, removing .idea and .gradle, rebuilding project, deleting the profile and adding it again. I tried those actions in different orders.
Here's a screenshot of the project:
It also complains Kotlin is not configured, but I have already configured it.
Here's the run configuration:
Here are the project settings:
Your Hello.kt file needs to be somewhere inside the src/main folder, probably in src/main/kotlin. This is different from the tutorial, because your project is using Gradle, and the one in the tutorial isn't. I think this is because newer versions of IntelliJ use Gradle by default for new projects, which wasn't the case when the tutorial was written.
The use of src/main/kotlin and src/test/kotlin as source code directories is a convention in Gradle (and Maven). When importing a Gradle project into IntelliJ, main becomes a module, and kotlin becomes a source folder within that module. The same goes for test. In your screenshots, the bold text and blue icons on main and test confirm that's how your project is set up. Files outside of those folders aren't treated as source files, which explains why your Hello.kt file isn't being compiled or recognised correctly.
It's likely that the default behaviour of IntelliJ when creating a new project has changed since this tutorial was written. In the tutorial, they select "Kotlin" as the project type and this creates a project that doesn't use Gradle. As a result, the project doesn't use the src/main/kotlin directory structure.
I can see from your video that you selected the same option, but on the next screen, IntelliJ still automatically selected Gradle as the build system for the new project. To match the project structure used in the tutorial, I think you would need to select "IntelliJ" as the build system.

Command line generation of IntelliJ IDEA project files?

I prefer having one IDEA project per task I'm working on. If it's a Gradle project, I can run gradlew idea to generate the project files then rename them to be indicative of the task I'm working on (so that when re-opening from IDEA a project, it's obvious what the task is and IDEA is able to list several tasks for the same Gradle project). This works well enough if it's a Gradle project, but if it's not, I'm left with using the IDEA GUI to open the project by pointing to the working directory. Is there a command-line way to generate the IDEA project files so I can rename them prior to using the GUI? Being able to do this would also obviate the need for using gradlew idea for this purpose.
Using the GUI, create the project by pointing it to the build.gradle file or project root directory. Once the project is created:
click the File menu
click the Project Structure menu item
change the Project name text value

Is it possible to configure file types mapping in Idea via gradle 'idea' plugin

A little intro:
I work on a project with legacy codebase witch uses internal xml based descriptors with specific file extensions (about may be 10 extensions).
Let it be *.desc, *.check etc.
To have code highlighting for such a files I can configure Idea to consider these types of files as XML.
It's available through:
Preferences / Editor / File types
And then add all custom extensions to 'Recognized file types': 'XML'
Our project uses gradle as build tool
and my question is:
Is it possible to make same configuration via dsl of gadle 'idea' plugin?
The short answer is: No.
One could create a custom Gradle task that will modify IDE file type preferences XML file in the config directory. While it's possible to run such task automatically on the project refresh in IntelliJ IDEA, it will most likely not work since you can't modify IDE configuration when IDE is running (the changes will be reverted). So, you will have to run it from the command line, outside of IntelliJ IDEA when IDE is not running.
It's probably not what you want, but if documented, can be used by the team as the manual step to make this configuration change easier.
Using gradle idea is not recommended anyway.
A better way might be to provide your own IDE plug-in that will associate these file extensions with XML file type and instruct the team to install this plug-in.

When deploying Xtext, how to integrate with Eclipse via plugin?

I have finished a beta of my Xtext and Xtend project. Now I want to integrate it with an Eclipse. Using this new Eclipse I want to be able to choose "New 'mydsl' project", then in this new project I want to have a .jar referenced by default. Also an empty file of mydsl. If it is possible, get rid of adding Xtext nature to project .
There are several non-trivial processes for this question:
To be able to choose "New 'yourDSL' project", you will have to implement your own project wizard. That is, in your plugin.xml file you have to contribute to the extension point "org.eclipse.ui.newWizards" and create a class that must implement the INewWizard interface, you can do so by extending the Wizard class.
That wizard, in the performFinish() task, should create a IJavaProject programatically where you can specify the Natures that you want. You also will have to specify the source and output folders, and configure the classpath (adding the classpath entries) as well. This link goes on more detail on how to create the project. http://www.pushing-pixels.org/2008/11/18/extending-eclipse-creating-a-java-project-without-displaying-a-wizard.html
In the previous step (#2), when creating your custom project, you can add packages, folders, files, so you can add your empty .mydsl files.
Now the trickiest part. To have the .jar file referenced by default there are several approaches. The easiest one is if you know the .jar path beforehand, you can add the reference by adding (in step #2) a classpath entry of type CPE_LIBRARY that point to that .jar file, but again you need to know the path somehow. In my case I didn't know the path because my .jar file was a library exported as plugin, so I ended up by implementing an IClasspathContainer that looks up for my plugin-library (.jar file) among the installed plugins. You can look up for your a plugin by doing:
Bundle bundle = Platform.getBundle("com.my.libraryPlugin");
File bundleFile = FileLocator.getBundleFile(bundle);
... and then, in step #2 what I add is a classpath entry of type CPE_CONTAINER:
JavaCore.newContainerEntry("MY_CONTAINER");
You can read more about IClasspathContainer here: http://www.ibm.com/developerworks/opensource/tutorials/os-eclipse-classpath/section2.html
5- You probably know how to do this already. The last step is to export your DSL plugins and copy them in the "plugins" folder in the Eclipse installation. To export the plugins: Select the projects -> Right-click -> Export -> Plug-in Development -> Deployable plug-ins and fragments...

How to configure IntelliJ IDEA and/or Maven to automatically add directories with Java source code generated using jaxb2-maven-plugin?

In our project we are using jaxb2-maven-plugin to generate Java source code from XML Schema, which causes that our Maven module requires additional source code directory (in our case target/generated/main/java). Up to date I've been using Eclipse and maven-eclipse-plugin to import all the projects into Eclipse workspace. The plugin is (somehow) able to add the directory with generated source code automatically to Eclipse' .classpath file.
Recently I try to switch to (play with?) IntelliJ IDEA 9 (so I am a newbie in this environment) and I've noticed that additional source directory is not added during IDEA's importing process...
Is there any way I can configure IDEA/Maven to make importing directory with generated source code automatically?
The convention with Maven is to generate code in target/generated-sources/<tool>, for example target/generated-sources/jaxb2
Follow this convention and IDEA will add the folder as source folder (see IDEA-53198).
Generated code, using jaxb2-maven-plugin, was missing for me in Intellij 2017.1 whereas Eclipse Neon created it.
Fixed it from context menu of module by selecting 'Maven -> Generate Sources and Update Folders'.
Try with maven-jaxb2-plugin. If it does not work then it's IDEA problem.
In Maven you can add new source roots per configuration. Maven plugins can do this programmatically. This is for sure the case with maven-jaxb2-plugin. Then, if IDEA does not recognize it, then it's a problem on that side.
You can use the Maven Build Helper Plugin. It is located at http://www.mojohaus.org/build-helper-maven-plugin/
It allows to configure additional source roots. And the maven integration of IntelliJ will add the new source root. We are using this feature in quite a few builds and it works just fine. Tested with vers. 13 of IntelliJ IDEA.