• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JavaFX Path to FXML in Jar vs e(fx)clipse

 
Greenhorn
Posts: 6
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

i have a question concerning a diffrence between path to the fxml in eclipse (Run As) and the same value when creating an executable jar-File via build.fxbuild:

when i want to run my application from eclipse i have to load the fxml this way:
URL p = c.getResource("/MyFxml.fxml");
when creating an executable jar-File this does not work.
I have to use this instead:
URL p = c.getResource("/resources/MyFxml.fxml");

the fxml resides in /src/resources, which is used as source-folder.

Can you help me?

Thanks in advance
 
Marcus Kuhn
Greenhorn
Posts: 6
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone,

has no one an idea on that topic?

FX generates a build.fxbuild. When openig this file you can klick on "generate build.xml and run".
This generates a build.xml and invokes ant-build on this file.
Is there a possibility of influencing the way the build.xml is generated?
Always changing my source wether i want to debug in eclipse or i want to run the application without eclipse can't be the correct way.
The other workaround woud be to put the fxml-file into the package where the java-code resides, but it seems also wrong to me.

So, if anyone has an idea please help me.

Thanks

 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Marcus Kuhn wrote:The other workaround woud be to put the fxml-file into the package where the java-code resides, but it seems also wrong to me.


This is the standard way with other resources (in fact you can put them to any package you want, just need to specify the path correctly relative to the class you choose to locate them). Why do you think this is not appropriate for the fxml file?
 
Marcus Kuhn
Greenhorn
Posts: 6
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems to me we have a misunderstanding. Perhaps i have described my thoughts not deailed enough.

My Package-Structure:
myFXapp/src/main/java <- where the *.java files reside
myFXapp/src/main/rsources <- where the resources reside (*.fxml; *.css)
With "the other Workaround" i meaned moving the *.fxml-files and *.css-Files to myFXapp/src/main/java
That would be the same as having all your files in the root-Directory without having any directories.
That cant be the right way in my opinion.

My Problem is that i can't use the correct relative location when i want to debug the application via ->Debug As->2 Java Application in e(fx)clipse.
If debugging would simply work with the correct path, i would not have a problem.

I have found some entries concernĂ­ng the loading of resource-Files in Stack Overflow. I will look there.
A way that works for me is simply try loading the resource via
Class<? extends MyFXclass> c = getClass();
URL p = c.getResource("/MyFxml.fxml");
if this returns null i try
URL p = c.getResource("/resources/MyFxml.fxml");
For the first this will solve my problem.
 
Martin Vashko
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've always kept resources in the source tree, together with the code that uses them. But I understand that you might prefer a different arrangement. Some discussion about managing resources can be found in Swing tutorial (this obviously isn't a JavaFX specific issue).

I might be wrong, but I believe that your problems is caused by the structure of your JAR file differing from the structure of your compiled classes. I assume that Eclipse runs the project from the compiled classes, not from the JAR, which would account for the difference. It should be quite easy to compare the structure of your JAR with the structure of the bin directory built by Eclipse.

Also, there's a setting in Eclipse somewhere which specifies files of types which will be copied from the source tree to the build location. If you didn't configure *.fxml to be included, they might not get copied to their target location.

Both of these are just my guesses. But I do believe that your problem involves Eclipse, so I've added this thread to our IDE forum.
 
Marcus Kuhn
Greenhorn
Posts: 6
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Martin,

thanks for your reply and suggestions.
Now i have a hint where i can investigate further.
Thanks again.

Marcus
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic