У меня есть две папки:
- src/main/java/application, содержащий мой исходный код.
- src/main/resources, который должен содержать ресурсы.
в src/main/resources и запускаю с помощью mvn javafx:run, у меня возникает
ошибка, которая сообщает мне: что он не находит файл fxml. Однако в моем
pom.xml есть ссылка на ресурсы:
build>
src/main/java
src/main/resources
*
но когда я помещаю fxml в src/main/java/application, он работает, поэтому maven находит его.
вот мой файл pom.xml:
p>
4.0.0
fr.miminbat
cryptor-miminbat
0.0.1-SNAPSHOT
cryptor
13
Launcher
Main
org.openjfx
javafx-controls
${javafx.version}
org.openjfx
javafx-fxml
${javafx.version}
src/main/java
src/main/resources
*
maven-compiler-plugin
3.8.1
21
org.openjfx
javafx-maven-plugin
0.0.8
application.${main.gui}
org.codehaus.mojo
exec-maven-plugin
3.0.0
application.${main.gui}
org.apache.maven.plugins
maven-assembly-plugin
3.3.0
jar-with-dependencies
application.${launcher.main}
make-assembly
package
single
И мой Java-код:
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import java.net.URL;
public class Main extends Application {
@Override
public void start(Stage stage) throws Exception {
URL fxmlLocation = getClass().getResource("/login.fxml");
FXMLLoader loader = new FXMLLoader(fxmlLocation);
Parent root = loader.load();
Scene scene = new Scene(root);
// 400, 300
String css = this.getClass().getResource("/style.css").toExternalForm();
scene.getStylesheets().add(css);
stage.setTitle("Login Application");
Image icon = new Image("icon.png");
stage.getIcons().add(icon);
stage.setWidth(400);
stage.setHeight(600);
stage.setResizable(true);
stage.setFullScreen(false);
// stage.setFullScreenExitHint("for exit presse 'echap' ");
// stage.setFullScreenExitKeyCombination(KeyCombination.valueOf("g"));
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
вот ошибка, которую я получаю, когда выполняю mvn javafx:run :
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------< fr.miminbat:cryptor-miminbat >--------------------
[INFO] Building cryptor 0.0.1-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> javafx:0.0.8:run (default-cli) > process-classes @ cryptor-miminbat >>>
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ cryptor-miminbat ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 3 resources from src\main\resources to target\classes
[INFO]
[INFO] --- compiler:3.8.1:compile (default-compile) @ cryptor-miminbat ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO]
Подробнее здесь: https://stackoverflow.com/questions/787 ... with-maven