Static Content with Maven Jetty Plugin

How can I serve static content with the maven plugin prefix (7.x)

thanks

+4
source share
2 answers

I have this configuration in my jetty.xml. I just wanted to update my question.

<Set name="handler"> <New class="org.eclipse.jetty.server.handler.HandlerList"> <Set name="handlers"> <Array type="org.eclipse.jetty.server.Handler"> <Item> <New class="org.eclipse.jetty.servlet.ServletContextHandler"> <Set name="contextPath">/static</Set> <Set name="resourceBase">${static-resources-path}</Set> <Call name="addServlet"> <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg> <Arg>/</Arg> </Call> </New> </Item> </Array> </Set> </New> </Set> 
+1
source

put the static content in any folder below /yourStaticApp/src/main/webapp - say, under /yourStaticApp/src/main/webapp/static . When you start Jetty, they will be available as http://host:port/contextRoot/static/fileName.ext


Hmmm, unsure if possible. The Eclipse Jetty Maven plugin documents a way to configure the location of a static source, which boils down to the alternative webapps location mentioned above.

  ... <plugin> ... <configuration> <webAppSourceDirectory>${basedir}/src/staticfiles</webAppSourceDirectory> ... </configuration> ... </plugin> ... 

As the dock points out:

<webAppSourceDirectory> . By default, this parameter is set to $ {basedir} / src / main / webapp. If your static sources are located elsewhere, set this option accordingly.

refer: http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin


Update: Another study revealed that you can specify the location of webdefault.xml from the Jetty-maven plugin; and in webdefault.xml you can configure static content.

In the Jetty Maven configuration, specify the location of the wendefault.xml file

  <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <configuration> ... <defaultsDescriptor>/my/path/to/webdefault.xml</defaultsDescriptor> ... </configuration> </plugin> 

Now, using webdefault.xml in your hand, you can specify the configuration webdefault.xml here: http://docs.codehaus.org/display/JETTY/Static+Content - except that the package names have been changed from org.mortbay.jetty... at org.eclipse.jetty... below:

 <Configure class="org.eclipse.jetty.servlet.Context"> <Set name="contextPath">/javadoc</Set> <Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/javadoc/</Set> <Call name="addServlet"> <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg> <Arg>/</Arg> </Call> </Configure> 

: http://wiki.eclipse.org/Jetty/Reference/webdefault.xml

I have not tested / used above. But let me know if you do. Or if something else is needed for this.

+3
source

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


All Articles