ACz
ACz

Reputation: 577

Get file to load in browser from resources root

I work on Intellij IDEA 2016.3, Java desktop application.

My module structure looks like that :

module
  |- resources
     |_ page.html
  |-src
  |-pom.xml

I compile projet to .exe by Maven.

I used SWT Browser and I want start with page from resources.

How to get path to this file from resources which can work after compilation ?

I tried load path to page.html as below :

String pagePath = new File(getClass().getClassLoader().getResource("page.html").getFile()).getPath();

But after compiling project - it can not find the file. However when running project (without compilation to .exe) - it works well.

How to correct that ?

Upvotes: 1

Views: 1016

Answers (2)

ACz
ACz

Reputation: 577

SOLVED

I solved it by loading page.html content as HTML and load it on browser by browser.setText(htmlPageContent)

Upvotes: 0

Michael Peacock
Michael Peacock

Reputation: 2104

The Maven convention is to place static web resources (html, css, js, images, etc) within /src/main/webapp. Refer to the standard directory layout here: http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

Upvotes: 3

Related Questions