When I run the gradle "run" task, i cannot finish compiling java, as I get many errors of the form:"error: package javafx.XXXXX does not exist" for all of the javaFX imports. My test project can do imports just fine, although it isn't using gradle to compile.
I am trying to get a client's program "BilliardViewer" running on a Ubuntu VM. It has been through the hands of many programmers, some of which likely may not have had that much experience doing coding. I'm not sure whether this is a gradle issue, and eclipse issue, a library issue, or a coding issue. I know that the JavaFX library is properly installed, since I can run a separate HelloWorld jfx program. The only difference in the build paths between the two is that the BilliardViewer program has some external dependencies, since it uses C++ as well as Java. The program currently runs on his Mac, with I believe MacOS Mojave.
My HelloWorld Program, which works.
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
...
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
}
Some code from the BilliardViewer Program, which does not work (Colors.java)
import java.util.Optional;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
...
public ColorPicker(final int x, final int y) {
stage.setX(x);
stage.setY(y);
stage.focusedProperty().addListener((obs, wasFocused, isNowFocused) -> {
if (!isNowFocused) {
stage.hide();
}
});
stage.setScene(new Scene(grid));
stage.setTitle("SO COLORFUL");
grid.setPadding(new Insets(10));
for (int row = 0; row < ROWS; row++) {
for (int col = 0; col < COLS; col++) {
final Color currentColor = color[row][col];
final Rectangle rect = new Rectangle(RECT_SIZE, RECT_SIZE, currentColor);
rect.setOnMouseClicked(event -> {
selectedColor = Optional.of(currentColor);
stage.close();
});
Tooltip.install(rect, new Tooltip(Colors.colorMap.get(currentColor).get()));
grid.add(rect, col, row);
}
}
}
I expected the build to at least be able to compile java, since the exact same code compiles just fine on the client's Mac laptop.
EDIT: build.gradle
apply plugin: 'cpp'
apply plugin: TestingModelBasePlugin
//apply plugin: 'findbugs'
mainClassName = 'billiards.viewer.Main'
repositories {
jcenter()
}
dependencies {
// When getting the version number for a dependency, don't go to Maven Central and
// simply search for the package you want. You will often find many versions of the
// package, most of which are unofficial or out-of-date. Instead, go to the website
// of the package, and they will usually give you the correct Maven information there.
compile 'org.eclipse.collections:eclipse-collections-api:9.2.0' // All the interfaces
compile 'org.eclipse.collections:eclipse-collections:9.2.0' // The actual classes
compile 'com.google.guava:guava:25.1-jre'
compile 'org.apache.commons:commons-math3:3.6.1'
compile 'org.apache.commons:commons-lang3:3.7' // can remove this now I think?
compile 'org.apache.commons:commons-io:1.3.2'
compile 'io.javaslang:javaslang:2.0.5'
compile 'org.xerial:sqlite-jdbc:3.23.1'
compile 'net.java.dev.jna:jna:4.5.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.2.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
}
test {
useJUnitPlatform()
}
compileJava {
options.compilerArgs << '-Xlint' << '-Werror'
}
jar {
baseName = 'billiard-viewer'
manifest.attributes 'Main-Class': 'billiards.viewer.Main'
}
sourceSets {
main {
java {
srcDir 'src/java'
}
//resources {
//srcDir 'css'
//}
}
}
applicationDefaultJvmArgs = ['-server', '-Djna.library.path=./build/libs/backend/shared', '-Xss10000m']
sourceCompatibility = 1.8
targetCompatibility = 1.8
model {
components {
backend(NativeLibrarySpec) {
binaries.all {
cppCompiler.define "NDEBUG"
cppCompiler.args '-O3', '-march=native', '-flto', '-ftrapv'
linker.args '-lgmp', '-lmpfr', '-lmpfi', '-lsqlite3', '-ltbb'
if (toolChain in Clang) {
cppCompiler.args '-Weverything', '-Werror',
'-Wno-padded', '-Wno-comma',
'-Wno-exit-time-destructors', '-Wno-global-constructors',
'-Wno-c++98-compat', '-Wno-c++98-compat-pedantic',
'-std=c++14'
}
if (toolChain in Gcc) {
cppCompiler.args '-Wall', '-Wextra', '-Wpedantic', '-Werror',
'-Wno-c++11-compat', '-Wno-c++14-compat',
'-std=c++14'
}
checkedBy $.tasks.testBackend
}
}
test(NativeExecutableSpec) {
sources.cpp {
lib library: 'backend', linkage: 'static'
}
binaries.all {
cppCompiler.define "NDEBUG"
cppCompiler.args '-O3', '-march=native', '-flto', '-ftrapv'
linker.args '-lgmp', '-lmpfr', '-lmpfi', '-lboost_unit_test_framework'
if (toolChain in Clang) {
cppCompiler.args '-Weverything', '-Werror',
'-Wno-padded', '-Wno-comma',
'-Wno-disabled-macro-expansion', '-Wno-global-constructors',
'-Wno-c++98-compat', '-Wno-c++98-compat-pedantic',
'-std=c++14'
}
if (toolChain in Gcc) {
cppCompiler.args '-Wall', '-Wextra', '-Wpedantic', '-Werror',
'-Wno-c++11-compat', '-Wno-c++14-compat',
'-std=c++14'
}
}
}
}
}
task testBackend(type: Exec, dependsOn: 'testExecutable') {
commandLine 'build/exe/test/test'
// save the results here
//standardOutput = new FileOutputStream('build/test-results/test.out')
//errorOutput = new FileOutputStream('build/test-results/test.err')
}
// Make sure the C++ code is up to date when running the Java program
run.dependsOn "backendSharedLibrary"
//run.dependsOn "coverExecutable"
run.doFirst {
// Having this hardcoded isn't the best, put it works for now
//environment 'LD_PRELOAD', '/usr/local/Cellar/jemalloc/5.0.1/lib/libjemalloc.so.2'
//commandLine "./test.fish"
}