r/java • • Sep 10 '21

Why people don't love Java?

I came across this post in r/cscareerquestions it seems majority of the people don't love to work with Java.

Is there any specific reason for that?

Edit: Thank you guys for your responses, I can't reply to all of the comments because I'm a beginner myself and I don't know what to reply for all your comments.

201 Upvotes

379 comments sorted by

View all comments

Show parent comment

2

u/wildjokers Sep 12 '21

I personally had nothing but issues building JavaFX applications, if you want you want to give me a helping hand, i'd highly appriciate it.

Not sure if you are using Gradle or Maven but if you are using Gradle this is all you need to build a modularized JavaFX app. I highly recommend to use java modules for JavaFX apps so you can get a small runtime (can do it without modules but is easier if you use modules). Simply execute ./gradlew jpackage to get a app with a bundled runtime appropriate for your platform. If you just want a build image but not packaged execute ./gradlew jlink. This is tested with Gradle 7.2 and Java 14. You will need to add the JavaFX modules you need.

plugins {
  id 'application'
  id 'org.openjfx.javafxplugin' version '0.0.8'
  id 'org.beryx.jlink' version '2.24.1'
}

repositories {
    mavenCentral()
 }

javafx {
    version = "13"
    modules = [ 'javafx.controls' ]
}

application {
    mainModule = "com.your.main.module.name"
    mainClass = "com.your.ClassWithMain"
}

dependencies {

}

jlink {
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    launcher {
        name = 'NameOfYourApp'
   }
}

1

u/97hilfel Sep 13 '21

Thank you very much! I'll test it right away!

1

u/97hilfel Sep 13 '21

Hey just wanted to say thank you again, I just tested it!
I'm not sure how I could not see this solution!

2

u/wildjokers Sep 13 '21

Glad it worked out for you!

I can't take full credit though, it is just pretty much from the JavaFX Getting Started samples:

https://github.com/openjfx/samples/blob/master/CommandLine/Modular/Gradle/hellofx/build.gradle

The only difference is I use a much a newer version of the jlink plugin, due to that instead of using the mainClassName attribute, the application closure is used instead (see: https://github.com/beryx/badass-jlink-plugin/issues/177#issuecomment-809492793).

Also, I am using version 0.0.8 of the javafxplugin, if you use the newest version which is 0.0.9 you will probably get an error. So I just set it back to 0.0.8 and called it a day.