r/JavaFX • • Jun 15 '25

Help Please help me setup JavaFX on VS Code πŸ™πŸ½

So as shown in the screenshots, I have been trying to setup JavaFX in VS Code for an upcoming project I have to do soon. I have tried adding the .jar files to my referenced library, manually adding them to my lib folder, adding to the .json file and nothing seems to work. Every tutorial I look up tells me the same things and I fear that I may be missing something very simple so if anyone knows what that might be then please let me know.

Any help is greatly appreciated!

10 Upvotes

22 comments sorted by

View all comments

Show parent comment

2

u/Spare-Plum Jun 15 '25

I would highly recommend Maven + Intellij. If you download Intellij there is an option to create new project -> JavaFX application and it works out of the box

I've spent hours trying to get JavaFX to properly run manually and it's not fun, and sensitive to version or platform changes

1

u/[deleted] Jun 15 '25

I’m downloading Intellij as I type this but I’m a bit new to this so could you maybe explain more what Maven exactly is because I’m still unsure. Also am I right in assuming Intellij is just another IDE?

2

u/Spare-Plum Jun 15 '25

Yup intellij is just another IDE. Maven is a build tool. Basically you just define an XML file, and you list out what dependencies you have. The build tool automatically downloads them and references them appropriately. It also knows how to run your project.

There are also plugins for maven that you can specify, for example there is a JavaFX maven plugin. This finds all of the JavaFX binaries that will be used to run your application, independent of which platform (like windows or unix) you are on.

The nice thing about maven is that anyone can use your project, and can build it and it will automatically download all the dependencies for you. You can also publish your own projects to maven so you can reference other things you made within your project

1

u/[deleted] Jun 15 '25

Yah nothing worked so far and im at a loss. I really have 0 clue why this isn’t working, I swear all my configs are correct but just no results. I tried Eclipse but the IDE is just so bad that I immediately went back to testing Vs code. I guess i’ll try intellij but I really desperately want this to work on vs code

1

u/[deleted] Jun 15 '25

So can you explain how I would transfer a project over from intellij to VS code. Im assuming just open the file in vs and it should load all the properties?

1

u/Spare-Plum Jun 16 '25

i'm sure there's a guide due porting it. But once you have the maven file the vscode maven extension should be able to figure out the build agnostic to the ide

1

u/hamsterrage1 Jun 17 '25

Go into Intellij and pick New...Project which will start up a wizard. Tell it you want a JavaFX project in Java with Maven or Gradle as the build engine. Give it a name, and set a group, something like "com.superprogrammer.firstproject", or whatever. Let the wizard run and you'll get a stupid little "Hello World" project that will show you everything you need to know although it uses FXML (boo! hiss!).

Both Maven and Gradle impose a standard project layout that is easy to understand. If you followed my instructions you'll have a src->main->java directory and then the group you specified giving the package structure.

You'll also have src->main->resources, and maybe the package structure as directories.

Run the project using the Gradle/Maven menus over at the right side of the screen. It should run perfectly without any issues or complaints.

Drag and drop your java files into the same place as the java files that the wizard created. Go into the build.gradle file, or the POM file if you are using Maven, and change "Application" section to the Main() class of your stuff. It should run.

BTW, once you have a build.gradle or POM file, double clicking it should open the project in Intellij.

1

u/hamsterrage1 Jun 17 '25

BTW, I totally forgot that I wrote a step-by-step guide for this last year. It's here: https://www.pragmaticcoding.ca/javafx/gradle-intellij

It's possibly a little bit out of date, I'll have to review it, and Intellij, Gradle, Java, and JavaFX all have new versions. Some of the tweaks I describe may not be needed any more.