- Create a own profile - this allows more flexibility
<profile> <id>jetty-run</id> </profile>
<plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <configuration> <webAppSourceDirectory>${basedir}/src/main/webapp</webAppSourceDirectory> <scanIntervalSeconds>2</scanIntervalSeconds> <scanTargets> <scanTarget>src/main/java</scanTarget> </scanTargets> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin>
<properties> <maven.test.skip>true</maven.test.skip> </properties>
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <executions> <execution> <id>default-war</id> <phase>none</phase> </execution> </executions> </plugin>
- Skip optimzation (we use the primefaces-extensions plugin for this)
<plugin> <groupId>org.primefaces.extensions</groupId> <artifactId>resources-optimizer-maven-plugin</artifactId> <executions> <execution> <id>optimize</id> <phase>none</phase> </execution> </executions> </plugin>
@Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { final OutputStream ouputStream = response.getOutputStream(); response.setContentType(getServletConfig().getInitParameter("contentType"); final List<File> filesToMerge = getFiles(getServletContext().getRealPath(getServletConfig().getInitParameter("includeDirectory"))); for (final File fileToMerge : filesToMerge) { final FileInputStream inputStream = new FileInputStream(fileToMerge); IOUtils.copy(inputStream, ouputStream); inputStream.close(); } ouputStream.close(); }
We just create a second web.xml (this is just for localhost and jetty) with the name "web-localhost.xml" in your "src/main/webapp/WEB-INF" directory with the following servlet mapping
<servlet> <servlet-name>Merge Javascript Servlet</servlet-name> <servlet-class>xxx.servlet.MergeResourceServlet</servlet-class> <init-param> <param-name>includeDirectory</param-name> <param-value>/javascript/</param-value> </init-param> <init-param> <param-name>contentType</param-name> <param-value>application/x-javascript</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>Merge Javascript Servlet</servlet-name> <url-pattern>/javascript/bundle.js</url-pattern> </servlet-mapping>
<plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <configuration> <webAppConfig> <overrideDescriptor>src/main/webapp/WEB-INF/web-localhost.xml</overrideDescriptor> </webAppConfig> ... </configuration> </plugin>Finished! You will be able to start jetty now via "mvn package -P jetty-run".