Biscuit128 Biscuit128 - 3 months ago 10
HTML Question

Jersey not loading index.html

I am having some difficulty loading an index.html with the way my project is set up - my structure looks as follows;

enter image description here

My web.xml looks as follows;

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

<module-name>restprj</module-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
<servlet-name>SpringApplication</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.rest.test.demo.MyApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpringApplication</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
</web-app>


I can call my rest end points with no issue - for example

http://localhost:8080/service/entry-point/test2/hi

this gives me output - however if i navigate to the url http://localhost:8080/service/ i get a 404 - it makes no difference where i place my index.html - is anyone able to point out what im doing wrong?

Thanks

Answer

It looks like you are placing index.html in the /target folder, use the src/main/webapp folder for all your .js and .html files. Target folder will be cleaned up every time you mvn clean install and they will not be included in your packaging, ever.

After you make the changes, build the project, copy the war to a certain location, rename the .war to .zip, extract the contents and see if it contains the index.html file in the root folder. You may do this before and after the changes I suggested to understand how and where the index.html is packaged to.