gpt4 book ai didi

eclipse - 我收到 “package javafx.geometry does not exist”错误,使用gradle进行编译

转载 作者:行者123 更新时间:2023-12-03 03:17:31 33 4
gpt4 key购买 nike

当我运行gradle“run”任务时,我无法完成Java的编译,因为我收到许多形式的错误:“错误:所有javaFX导入的程序包javafx.XXXXX不存在”。我的测试项目可以很好地导入,尽管它没有使用gradle进行编译。

我正在尝试在Ubuntu VM上运行客户端程序“BilliardViewer”。它是通过许多程序员的手中完成的,其中一些程序员可能没有那么多的编码经验。我不确定这是gradle问题,eclipse问题,库问题还是编码问题。我知道JavaFX库已正确安装,因为我可以运行单独的HelloWorld jfx程序。两者之间构建路径的唯一区别是BilliardViewer程序具有一些外部依赖性,因为它使用C++和Java。我相信MacOS Mojave可以在Mac上运行该程序。

我的HelloWorld程序有效。

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();
}

BilliardViewer程序中的某些代码不起作用(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);
}
}
}

我希望该版本至少能够编译Java,因为完全相同的代码在客户端的Mac笔记本电脑上可以正常编译。

编辑: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"
}

最佳答案

我最终通过在我的eclipse项目中添加gradle.properties文件解决了这个问题,据stackoverflow,该文件向gradle显示了在哪里寻找JDK。因此,为了澄清起见,我必须安装一个JDK,并将gradle指向该JDK。

关于eclipse - 我收到 “package javafx.geometry does not exist”错误,使用gradle进行编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57066232/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com