Where do I put my resources in Scala?

Ivan

While studying using Scala with JavaFX I have met the following code in a ProScalaFX example:

  val resource = getClass.getResource("AdoptionForm.fxml")
  if (resource == null) {
    throw new IOException("Cannot load resource: AdoptionForm.fxml")
  }

  ...

  val root: jfxs.Parent = jfxf.FXMLLoader.load(resource)

Where do I put the actual "AdoptionForm.fxml" content in this case? Unfortunately I am neither familiar with using resources in Java.

I use SBT as the building system and Idea as an IDE.

There is a related question which suggests a way (putting the resource files in "src/main/resources" or "src/main/resources/packagename"), but it also says it doesn't work actually (needless to say I have tried).

bluenote10

src/main/resources is the correct location for placing resources in a default SBT configuration.

However, one has to be aware of the difference between getClass.getResource and ClassLoader.getResource. Using getClass.getResource("AdoptionForm.fxml") requires the file to be located in a path which corresponds to the package of the class.

For instance: If the class is located in com.domain.utils then the resource must be located at src/main/resources/com/domain/utils/AdoptionForm.fxml.

In order to switch from package-relative locations to absolute locations one can either use ClassLoader.getResource or just prepend the resource string with a /.

Example: getClass.getResource("/AdoptionForm.fxml") loads the resource from src/main/resources/AdoptionForm.fxml

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Where will i put my image resources?

From Dev

AndEngine Loading Graphics: Where Do I put my assets folder and my resources?

From Dev

Where should I put my resources for a Java program?

From Dev

Where should I put my resources for a Java program?

From Dev

Where do I put my stubs?

From Dev

Where Do I Put My Extra Into An ArrayList?

From Dev

Where do I put my helper functions?

From Dev

Where do I put my favicon?

From Dev

Where do I put my systemd service?

From Dev

Where do I put my code in rails web app

From Dev

Where do I put my Hello world PHP file on Ubuntu?

From Dev

Where do I put the code to initialize my controls?

From Dev

Polymer: Where exactly do I put my Javascript for an Element?

From Dev

Where do I put my templates folder in a Flask app?

From Dev

Where do I put coding logic in my React Application

From Dev

Where in my Class do I put the @XmlElement Annotation?

From Dev

Where do I properly put my constants in Meteor

From Dev

Where do I put my XML beans in a Spring Boot application?

From Dev

Where do I put my python files in the venv folder?

From Dev

Where do I put my systemd unit file?

From Dev

Sinatra: Where do I put my gem dependencies?

From Dev

Polymer: Where exactly do I put my Javascript for an Element?

From Dev

Where do I put my environment variables for API credentials?

From Dev

Where do I put my clear fix to clear the float?

From Dev

Where do I put my tests when I split my Play project into sub modules

From Dev

Where do I put the PDO?

From Dev

Where do I put $(this) in the function?

From Dev

Where do I put the if statement?

From Dev

Where do I put my helpers and how do I test them?

Related Related

HotTag

Archive