I started a Gradle project with java and I wanted to add JavaFx Library but when I run my application I'd got "JavaFX runtime components are missing, and are required to run this application".
This is my Gradle file:
plugins {
id 'java'
id 'org.openjfx.javafxplugin' version '0.0.9'
}
group 'org.personal'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
javafx {
version = "15.0.1"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}
test {
useJUnitPlatform()
}
And this is the main class:
package client;
import javafx.application.Application;
import javafx.stage.Stage;
public class ClientApp extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
}
}
And this is my "Edit Configuration": Edit Configuration here
you need to add the JavaFX JDK libs to the path. Otherwise, you need to use JDK 8 (JDK1.8) which integrates the JavaFX SDK
Related
I'm trying run with code with gradle and without it.
public class Example {
public static void main(String[] args) throws RuntimeException {
throw new RuntimeException();
}
}
With gradle it's not working.
[Exception when i run code with gradle][1]
[1]: https://i.stack.imgur.com/kJtyL.png
Without gradle it works.
I tried to run this code on java 8 - java 18 versions and used different versions of gradle.
My gradle file
plugins {
id 'java'
}
group 'org.example'
version '0.0.1'
repositories {
mavenCentral()
}
sourceCompatibility = JavaVersion.VERSION_18
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}
test {
useJUnitPlatform()
}
How can I fix it?
Thank you!
build.gradle
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
implementation("net.dv8tion:JDA:5.0.0-alpha.8")
}
test {
useJUnitPlatform()
}
bot.java
package Main;
import net.dv8tion.jda.api.JDABuilder;
;
public class testbotgradle {
public static void main(String[] args) throws LoginException {
JDABuilder jda = new JDABuilder.createDefault("my tocen");
jda.setActivity(Ativity.playing("test"));
jda.setStatus(OnlineStatus.ONLINE);
jda.build();
}
}
throws
java.lang.ClassNotFoundException: bot
Also seams like Java cant import the JDA package but I have no idea why. I have installed the dependencies. They are in the same project. Im using IntellijIDEA
It's probably a little late but for me the error can come from two places:
Either you did not launch your gradle.build after putting the code
Either the alpha 8 is no longer available and in this case
implementation("net.dv8tion:JDA:5.0.0-alpha.9")
This is my first javafx and gradle application. First I created a gradle project in IntelliJ and then I added JavaFX dependencies referring this tutorial. My gradle file looks like this:
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
plugins {
id 'application'
}
group 'com.skb'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
def javaFXPlatform = getJavaFXPlatform()
def javaFXVersion = "15.0.1"
dependencies {
// you need a dependency for each of the JavaFX modules you're going to use
implementation "org.openjfx:javafx-base:${javaFXVersion}:${javaFXPlatform}"
implementation "org.openjfx:javafx-controls:${javaFXVersion}:${javaFXPlatform}"
implementation "org.openjfx:javafx-graphics:${javaFXVersion}:${javaFXPlatform}"
}
application {
//Java Module System module name
mainModule.set('com.skb')
//Your JavaFX application class
mainClass.set('com.skb.EditorApp')
}
java {
// this enables Java Modularity in Gradle (version 6.7 and above)
modularity.inferModulePath.set(true)
}
// Based on this StackOverflow answer: https://stackoverflow.com/a/65209664/653519
private static String getJavaFXPlatform() {
def currentOS = DefaultNativePlatform.currentOperatingSystem
if (currentOS.isWindows()) {
return 'win'
} else if (currentOS.isLinux()) {
return 'linux'
} else if (currentOS.isMacOsX()) {
return 'mac'
}
return null
}
My module_info.java lloks like this:
module com.skb {
requires javafx.fxml;
requires javafx.controls;
requires javafx.graphics;
requires java.base;
//requires org.fxmisc.richtext;
//requires org.json;
opens com.skb;
}
EditorApp class contains just some biolerplate code:
package com.skb;
import javafx.application.Application;
import javafx.stage.Stage;
public class EditorApp extends Application {
#Override
public void start(Stage primaryStage) {
System.out.println("Running...");
}
public static void main(String[] args) {
launch(args);
}
}
Project structure is like this:
I am using IntelliJ 2021.1 Community Edition.
Please help me out. I have already searched a lot on this error, and got nothing that solved the error.
I made a minimalist java gradle project to test java 9 modules.
I made only 1 module and tried testing depending on a third party module. But I keep getting the error when I try to build or run the project:
module not found: commons.validator
here are my files:
Demo.java"
public class Demo {
public static void main(String[] args) {
boolean result = EmailValidator.getInstance().isValid("abcd");
System.out.println(result);
}
}
module-info.java:
module auth.server.main {
requires commons.validator;
}
build.gradle:
plugins {
id 'java'
}
repositories {
mavenCentral()
}
dependencies {
// for email validation
implementation 'commons-validator:commons-validator:1.7'
}
/*this is to let gradle infer the locations of the modules*/
java {
modularity.inferModulePath.set(true)
}
Whats wrong and how to solve it?
This might easy way.
plugins {
id 'java'
id "org.javamodularity.moduleplugin" version "1.1.1"
}
repositories {
mavenCentral()
}
dependencies {
implementation 'commons-validator:commons-validator:1.7'
}
Check it out : https://github.com/java9-modularity/gradle-modules-plugin
I am new to Gradle and i am using Gradle 6.1.
I am writing small application to understand the concepts of multi project Application and Java-Library plugin of Gradle.
My Question is :
How App.java is running perfectly fine without importing DefaultRandomGenerator class from SubProject-2
Why am i getting the error message "No candidates found for method call api" in build.grade file of Parent project (MultiProjectApp).
Below are my application code :
Parent Project (MultiProjectApp) files
settings.gradle
rootProject.name = 'MultiProjectApp'
include 'SubProject-1'
include 'SubProject-2'
build.gradle
allprojects {
apply plugin: 'java'
group 'org.example'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
}
project(':SubProject-1') {
dependencies {
implementation project(':SubProject-2')
}
}
project(':SubProject-2') {
apply plugin: 'java-library'
dependencies {
api 'org.apache.commons:commons-math3:3.2'
implementation 'org.apache.logging.log4j:log4j-core:2.5'
testImplementation "junit:junit:4.12"
}
}
SubProject-2 files
build.gradle
Empty file
RandomGenerator.java
package org.examples;
public interface RandomGenerator {
String name();
int generate();
}
DefaultRandomGenerator.java
package org.examples;
import org.apache.commons.math3.random.RandomDataGenerator;
public class DefaultRandomGenerator implements RandomGenerator {
public String name() {
return "Main Random Number Generator";
}
public int generate() {
final RandomDataGenerator randomDataGenerator = new RandomDataGenerator();
return randomDataGenerator.nextInt(5, 10);
}
}
SubProject-1 files
build.gradle
Empty file
App.java
package org.examples;
import org.apache.commons.math3.random.RandomDataGenerator;
public class App {
public static void main(String[] args) {
RandomGenerator aRandomGenerator = new DefaultRandomGenerator();
System.out.println("The 1st random number is :" + aRandomGenerator.generate());
System.out.println("The 2nd random number is :" + generateMy());
}
public static int generateMy() {
final RandomDataGenerator aRandomDataGenerator = new RandomDataGenerator();
return aRandomDataGenerator.nextInt(5, 10);
}
}
How App.java is running perfectly fine without importing
DefaultRandomGenerator class from SubProject-2
It works because they are both in the same package (org.examples).
Note that this will not work if using the new module system introduced in Java 9. Because the two projects are considered "split", and you will need various hacks to make it work.
Why am I getting the error message "No candidates found for method
call api" in build.grade file of Parent project (MultiProjectApp).
This is an IDE problem, not a gradle problem. If you run, it should still work.
Example of runnig it in Vscode