Where to store static files, such as html / css / javascript, in a berth project?

I have a maven project that I run with the help of the pier:

$ mvn run:jetty 

Where in my project should I store my static files such as HTML, CSS, Javascript, images?

My layout uses a simple web application arch type:

 /src/main/java/webapp/web-inf/views/ 

Should I just create a folder where it is called, for example. "assets"?

And then my browsing pages will link to the /assets folder somehow? I am confused as to which path I will use in my html pages to link to an image like this:

 /assets/images/logo.png 
+6
source share
3 answers

This is not so much a Jetty question as a general Java Webapp question. If you plan to serve them directly (e.g. * .css, * .css, images, etc.), put them somewhere above WEB-INF , but below your docroot. Java WebApps are the following basic directory structure.

 <docroot> +WEB-INF/ +lib/ +classes/ 

Everything in <docroot> is available directly via http. There is nothing WEB-INF and below. A really simple webapp with one page (index.jsp), one image in the image directory and its configuration file (web.xml) will look like this.

 index.jsp images/bob.jpg WEB-INF/ web.xml lib/ classes/ 

In index.jsp you can refer to bob.jpg as ...

 <img src="images/bob.jpg"/> 
+17
source

This is a Maven question, not a Jetty question.

Usually you put your images (etc.) in the maven webapp directory - i.e. source/main/webapp/ (not under web-inf )

How you structure things under this is up to you, but basically it depends on how much content you expect and what you think is best to organize it.

source/main/webapp/assets/images fine, but it is also source/main/webapp/images or source/main/webapp/static/ .

Then in your HTML, you reference the images using any path that you put under the webapp bit.

+6
source

General answer: the root of your web application is webapp. Dynamic resources (like JSP pages or Freemarker templates) will be better located in the web-inf / sub folder (they are accessible through the class loader, but not from a direct browser request).

0
source

Source: https://habr.com/ru/post/907456/


All Articles