Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to store static files like html/css/javascript in a jetty project?

Tags:

java

maven

jetty

I have a maven project that I run using jetty:

$ mvn run:jetty

Where in my project should I be storing my static files like HTML, CSS, Javascript, images?

My layout is using a simple web app arch type:

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

Should I just create a folder there named e.g. 'assets' ?

And then my view pages will reference the /assets folder somehow? I'm confused as to what path I will use in my html pages to reference an image like:

/assets/images/logo.png
like image 627
Blankman Avatar asked Feb 02 '12 04:02

Blankman


People also ask

How do I organize my HTML CSS and JavaScript files?

One approach is to place HTML files inside a folder, CSS files inside a folder and javascript file inside a js folder and include the javascript files from the js folder into the main HTML page.

Are HTML files static files?

Static files, such as HTML, CSS, images, and JavaScript, are assets an ASP.NET Core app serves directly to clients by default.

What are static files in web?

Static files are typically files such as scripts, CSS files, images, etc... that aren't server-generated, but must be sent to the browser when requested. If node. js is your web server, it does not serve any static files by default, you must configure it to serve the static content you want it to serve.


1 Answers

This isn't so much a Jetty question as it is a general Java webapp question. If you plan to serve them out directly (like *.css, *.css, images, etc), put them somewhere above WEB-INF but below your docroot. Java WebApps are all the following basic directory structure.

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

Anything in <docroot> is reachable directly through straight up http. Anything WEB-INF and below is not. A really simple webapp with one page (index.jsp), one image in an images directory, and its configuration file (web.xml) would look like this.

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

In index.jsp you could reference bob.jpg like...

<img src="images/bob.jpg"/>
like image 92
Bob Kuhar Avatar answered Nov 15 '22 19:11

Bob Kuhar