r/javahelp • • Jun 20 '19

Why do I need to add --module-path %PATH_TO_FX% --add-modules=javafx.controls on a new computer for javafx to work and how can I fix it?

Sorry for the long title. I've moved to a new laptop and I guess I forgot how I set everything up on my old machine and now I'm using openjdk. The only way I can get my anything using javafx to work is by adding the options. How can I make that permanent instead of keeping a note somewhere to add them when I want to run the program.

Thanks and sorry if this is a stupid question.

Also:

java --version
openjdk 11.0.2 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
18 Upvotes

11 comments sorted by

10

u/[deleted] Jun 20 '19

because javafx was decoupled from java since JDK 11.

you either need to add the module path as you are doing, or build the jar with the modules in it.

4

u/ishouldquitsmoking Jun 20 '19

okay so keep it this way as I'm developing my trash for now? Thanks!

2

u/saila456 Jun 20 '19

I don't know what you are using to develop, but I've added javaFX as a library to my eclipse run configuration. With this done, the parameter is no longer required. I assume other IDEs have similar settings.

0

u/ishouldquitsmoking Jun 20 '19

When you run it from the IDE or from the command line?

4

u/aenigmaclamo Extreme Brewer Jun 20 '19

You shouldn't be using javac directly to compile your programs. Use a build system like maven or gradle to build your project to keep your build process sane.

1

u/ishouldquitsmoking Jun 20 '19

I'm just fucking around learning right now though. No real projects in mind and working through examples.

4

u/aenigmaclamo Extreme Brewer Jun 20 '19

You can do whatever you like; however, in my opinion java build systems, like version control, are essential and there is no project too small for them to be overkill. They're a major quality of life improvement, the right way to do it, and any decent IDE will generate the boilerplate for you.

1

u/ishouldquitsmoking Jun 20 '19

Thanks. I was using eclipse and just installed intellij and will go from there.

1

u/[deleted] Jun 21 '19

The decoupling is the perfect reason to start learning maven or gradle. Was the kick in the pants I needed

0

u/[deleted] Jun 20 '19

[deleted]

2

u/ishouldquitsmoking Jun 20 '19

I don't want a java job. I'm just learning for the sake of learning.

0

u/[deleted] Jun 20 '19

[deleted]

5

u/ishouldquitsmoking Jun 20 '19

Dude relax. I still read books I first read 20 years ago. I'm a 40 something lawyer with 20+ years of development behind me. I'm literally just fucking around with javaFX because I never have before. Even if I never use it again in my life, I had fun.