I am trying to use CalendarFX as a gradle dependency in my JavaFX project with the gradle javafx plugin, but I get the error that Module javafx.controls is nout found, while clearly specifying in the build.gradle file that it should use the javafx.controls module. My setup is this:
build.gradle:
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
group 'org.example'
version '1.0-SNAPSHOT'
mainClassName = "org.example.MainApp"
sourceCompatibility = 13
repositories {
mavenCentral()
}
dependencies {
implementation 'com.calendarfx:view:11.8.3'
}
javafx {
version = "13"
modules = ['javafx.controls', 'javafx.fxml']
}
MainApp.java:
package org.example;
import com.calendarfx.model.Calendar;
import com.calendarfx.model.CalendarSource;
import com.calendarfx.view.CalendarView;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import java.time.LocalDate;
import java.time.LocalTime;
public class MainApp extends Application {
#Override
public void start(Stage primaryStage) throws Exception {
CalendarView calendarView = new CalendarView();
Calendar test = new Calendar("Test");
test.setShortName("T");
test.setStyle(Calendar.Style.STYLE1);
CalendarSource familyCalendarSource = new CalendarSource("Source");
familyCalendarSource.getCalendars().add(test);
calendarView.getCalendarSources().setAll(familyCalendarSource);
calendarView.setRequestedTime(LocalTime.now());
StackPane stackPane = new StackPane();
stackPane.getChildren().add(calendarView);
Thread updateTimeThread = new Thread("Calendar: Update Time Thread") {
#Override
public void run() {
while (true) {
Platform.runLater(() -> {
calendarView.setToday(LocalDate.now());
calendarView.setTime(LocalTime.now());
});
try {
// update every 10 seconds
sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
updateTimeThread.setPriority(Thread.MIN_PRIORITY);
updateTimeThread.setDaemon(true);
updateTimeThread.start();
Scene scene = new Scene(stackPane);
primaryStage.setTitle("Calendar");
primaryStage.setScene(scene);
primaryStage.setWidth(1300);
primaryStage.setHeight(1000);
primaryStage.centerOnScreen();
primaryStage.show();
}
}
And the error I get when I try to run is:
$ ./gradlew run
> Task :run FAILED
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.controls not found
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':run'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 738ms
3 actionable tasks: 2 executed, 1 up-to-date
Try this in your VM arguments:
--module-path \path\to\javafx-sdk\lib --add-modules=javafx.controls,javafx.fxml
JavaFx does not come with CalendarFx ,
Download the lib and import it in your project.
https://github.com/dlsc-software-consulting-gmbh/CalendarFX/releases/download/11.8.3/view-11.8.3.jar
Related
I am trying to build a jar with the following build.gradle:
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.10'
}
application {
mainClass.set("edu.hm.dako.auditLogServer.AdminGuiStarter")
}
jar.enabled = true
javafx {
version = "18"
modules = ['javafx.controls', 'javafx.fxml']
}
sourceSets {
main {
resources {
srcDirs = ["src/main/java"]
includes = ["**/*.fxml"]
}
}
}
dependencies {
implementation project(':common')
implementation project(':communication')
implementation 'org.openjfx:javafx:18'
implementation group: 'org.apache.commons', name: 'commons-configuration2', version: '2.8.0'
implementation group: 'commons-beanutils', name: 'commons-beanutils', version: '1.9.4'
}
repositories {
mavenCentral()
}
jar {
manifest {
attributes "Main-Class": "edu.hm.dako.auditLogServer.AdminGuiStarter"
}
archiveBaseName = 'AdminGradle'
archiveVersion = '0.1.0'
}
The Main class of the project is following:
package edu.hm.dako.auditLogServer;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class AdminGuiStarter extends Application{
#Override
public void start(Stage stage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("AdminGui.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
} catch (IOException e) {
e.printStackTrace();
System.out.println(e);
}
}
// bitte über gradle starten, da sonst JavaFx Runtime components fehlen
public static void main(String[] args) {
launch();
}
}
When I then try to execute the jar, I get this error: java.lang.NoClassDefFoundError: javafx/application/Application
How can I fix this so that the jar will execute successful? When I run the Application via Gradle run, everything works fine.
package com.example.flutter_app;
import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
public class MainActivity extends FlutterActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
new MethodChannel(getFlutterView(), "course.flutter.dev/battery").setMethodCallHandler(
new MethodCallHandler() {
#Override
public void onMethodCall(MethodCall call, Result result) {
if (call.method.equals("getBatteryLevel")) {
int batteryLevel = getBatteryLevel();
if (batteryLevel != -1) {
result.success(batteryLevel);
} else {
result.error("UNAVAILABLE", "Could not fetch battery level.", null);
}
} else {
result.notImplemented();
}
}
}
);
}
private int getBatteryLevel() {
int batteryLevel = -1;
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
BatteryManager batteryManager = (BatteryManager) getSystemService(BATTERY_SERVICE);
batteryLevel = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
} else {
Intent intent = new ContextWrapper(getApplicationContext()).registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
batteryLevel = (intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) * 100) / intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
}
return batteryLevel;
}
}
My java code is given above. I was following a tutorial of writing native java code to get the battery level in my flutter app.
But it gives me the error given below:
(Debug console output)
Launching lib\main.dart on LDN L21 in debug mode...
lib\main.dart:1
C:\Users\ARPC\flutter_app\android\app\src\main\java\com\example\flutter_app\MainActivity.java:22: error: incompatible types: MainActivity cannot be converted to FlutterEngine
GeneratedPluginRegistrant.registerWith(this);
^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 3s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
Kindly tell me what I am doing wrong I thought that I have to turn verbose to true but I don't know how to do that if someone knows the solution please tell me.
Remove the below code in manifest file
meta-data
android:name="flutterEmbedding"
android:value="2"
and run the project it will work
Referencing the quick start for OpenCSV, having trouble opening a file which shows as present through the OS and by using exists to demonstrate.
code:
package net.bounceme.dur.basexfromjaxb.csv;
import com.opencsv.CSVReaderHeaderAware;
import java.io.File;
import java.io.FileReader;
import java.net.URI;
import java.util.Map;
import java.util.logging.Logger;
public class ReaderForCVS {
private static final Logger LOG = Logger.getLogger(ReaderForCVS.class.getName());
public ReaderForCVS() {
}
public void unmarshal(URI inputURI) throws Exception {
LOG.info(inputURI.toString());
File encyptFile = new File(inputURI);
System.out.println(encyptFile.exists());
Map<String, String> values = new CSVReaderHeaderAware(new FileReader("file:/home/thufir/jaxb/input.csv")).readMap();
}
}
file not found:
thufir#dur:~/NetBeansProjects/BaseXFromJAXB$
thufir#dur:~/NetBeansProjects/BaseXFromJAXB$ gradle run
> Task :run FAILED
Jan 10, 2019 1:47:50 PM net.bounceme.dur.basexfromjaxb.csv.ReaderForCVS unmarshal
INFO: file:/home/thufir/jaxb/input.csv
true
Exception in thread "main" java.io.FileNotFoundException: file:/home/thufir/jaxb/input.csv (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at java.io.FileReader.<init>(FileReader.java:58)
at net.bounceme.dur.basexfromjaxb.csv.ReaderForCVS.unmarshal(ReaderForCVS.java:23)
at net.bounceme.dur.basexfromjaxb.App.marshalCSV(App.java:24)
at net.bounceme.dur.basexfromjaxb.App.main(App.java:16)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':run'.
> Process 'command '/usr/lib/jvm/java-8-openjdk-amd64/bin/java'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
3 actionable tasks: 2 executed, 1 up-to-date
thufir#dur:~/NetBeansProjects/BaseXFromJAXB$
thanks to:
https://stackoverflow.com/a/18552188/262852
Why this works I don't know:
public void unmarshal(URI inputURI) throws Exception {
FileReader f = new FileReader(new File(inputURI));
Map<String, String> values = new CSVReaderHeaderAware(f).readMap();
}
I need to import a .proto file defined in a jar in our central maven.
Here's my build.gralde:
apply plugin: 'com.google.protobuf'
buildscript {
repositories {
maven {
url 'http://abc.def.com/content/groups/public/'
}
maven {
url 'http://abc.def.com/content/repositories/snapshot/'
}
}
dependencies {
classpath 'def.abc.someObj:someObj-proto:1.2'
}
}
protobuf {
generatedFilesBaseDir="$projectDir/src/"
}
sourceSets {
main {
// this tells the plugin where your project specific
// protofiles are located
proto {
srcDir 'src/main/resources/proto/'
}
java {
srcDir 'src/main/java'
}
}
}
Here's my other.proto file:
syntax = "proto3";
option java_multiple_files = true;
option java_package = "com.def.abc";
import "google/protobuf/any.proto";
import "someObj.proto";
whenever I try to compile, it's always complaining at
Import "someObj.proto" was not found or had errors.
I've downloaded the jar file from this maven, and clearly saw that this someObj.proto is in there.
Any ideas please?
Thanks!
In a Java application for Android, made in JavaFX under Eclipse Neon2, I want to use the android media SoundPool class.
To do that, I have added, in the Java Build Path:
the android-sdks platform : android-25 (called android.jar).
the jfxdvk-8.60.8.jar
Then, for instance, I create a SoundPool instance as follows:
import android.media.SounPool;
import android.media.MediaPlayer;
...
SoundPool sp = new SoundPool(MAX_STREAMS,AudioManager.STREAM_MUSIC,0);
The syntax is correct and the Eclipse editor does not notice any error.
But, when compiling the file, I have two errors "package android.media does not exist import android.media.AudioManager" and "package android.media does not exist import android.media.SoundPool;", and then, (it is a consequence), "cannot find symbols" at "AudioManager.STREAM_MUSIC" and at "new SoundPool" of the previous line code.
I don't understand these errors because I have added, in my JavaBuild Path, this android-sdks platform: android.jar (android-25) ad the Eclipse editor can fetch these two imports.
Thanks in advance for your response
Further information:
Errors raised on java compilation:
[sts] -----------------------------------------------------
[sts] Starting Gradle build for the following tasks:
[sts] androidInstall
[sts] -----------------------------------------------------
:validateManifest
:collectMultiDexComponents
:compileJavaC:\Users\pascal\workspaceNeon\JFX_withGluon_11.0gAvecSoundPoolKO\src\main\java\com\gluonapplication\GluonApplication.java:3: error: package android.media does not exist
import android.media.AudioManager;
^
C:\Users\pascal\workspaceNeon\JFX_withGluon_11.0gAvecSoundPoolKO\src\main\java\com\gluonapplication\GluonApplication.java:4: error: package android.media does not exist
import android.media.SoundPool;
^
C:\Users\pascal\workspaceNeon\JFX_withGluon_11.0gAvecSoundPoolKO\src\main\java\com\gluonapplication\GluonApplication.java:635: error: cannot find symbol
static SoundPool androidSoundPoolApplication = null;
----------------------
Related code:
package com.gluonapplication;
import android.media.AudioManager;
import android.media.SoundPool;
import com.gluonhq.charm.down.Services; // line 3
import com.gluonhq.charm.down.plugins.AccelerometerService; // line 4
......
final static int MAX_STREAMS = 10;
static SoundPool androidSoundPoolApplication = null; // line 635
And the build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.2'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'com.gluonapplication.GluonApplication'
dependencies {
compile 'com.gluonhq:charm:4.3.0'
}
jfxmobile {
downConfig {
version '3.2.0'
plugins 'accelerometer', 'compass', 'device', 'orientation', 'storage', 'vibration', 'display', 'magnetometer', 'lifecycle', 'statusbar', 'position'
}
android {
applicationPackage = 'com.gluonapplication'
manifest = 'src/android/AndroidManifest.xml'
androidSdk = 'C:/Users/pascal/AppData/Local/Android/sdk'
resDirectory = 'src/android/res'
compileSdkVersion = '25'
buildToolsVersion = '25.0.1'
}
ios {
infoPList = file('src/ios/Default-Info.plist')
forceLinkClasses = [
'com.gluonhq.**.*',
'javax.annotations.**.*',
'javax.inject.**.*',
'javax.json.**.*',
'org.glassfish.json.**.*'
]
}
}