1

I work with eclipse.

Part One: I've got 2 projects. Project A is a simple FX-Dialog (Java-Controller and fxml-File). There is no main in it. package: info.azo

Project B is a databased FX-Application (main) package: ch.muellner

I want to load the login dialog of project A in project B

I do it this way, but the error is: 'Location not found'

FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("info.azo/Login.fxml"));
AnchorPane anchorPane = (AnchorPane) loader.load();

My path to fxml is not correct, what is the correct syntax?

Part Two: Project A is also a JAR-File, I could load this from Project B, but how?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
KolaSiro
  • 45
  • 1
  • 9
  • Possible duplicate of [Get a resource using getResource()](https://stackoverflow.com/questions/2593154/get-a-resource-using-getresource) –  May 07 '18 at 11:50
  • The resource path is `/`-seperated. Furthermore using a class you to load the resource you should add `/` as prefix. – fabian May 07 '18 at 11:50
  • 1
    The new resource path is still incorrect. Should be `"/info/azo/Login.fxml"`. Furthermore to make classes from project A available in project B, you need to include the jar of project A in the classpath when compiling/running project B. (For compilation it's only necessary if you use a type from project A in java code in project B. If project B only accesses project A by loading fxmls from it, project B will compile fine even without project A's classes available.) – fabian May 07 '18 at 12:22

1 Answers1

0

This works perfect for me: if the jar-file of Project A is in JavaBuildPath of Project B.

loader.setLocation(Main.class.getResource("/info/azo/Login.fxml"));
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
KolaSiro
  • 45
  • 1
  • 9
  • 1
    please add the solution to this answer (vs. as an edit to the question) - doing so makes it easier for future readers to see it :) – kleopatra Jan 16 '20 at 13:53