- Create a own profile - this allows more flexibility
- Add jetty-maven-plugin to the profile. We also configure the plugin to get all resources from the src directory and only scan the java sources
- Skip unit testing via profile property
- Skip building the WAR file
- If you optimize and aggregate your javascript or CSS files, skip this too! Compression of this files is on localhost just prevents debugging. We created an own servlet which merges the files on-the-fly. Changes on JS or CSS will be also available after F5 in your browser - that's the nice side effect of the servlet :)
- Skip optimzation (we use the primefaces-extensions plugin for this)
- Create a servlet to merge the resources (we also implemented a init-param called includeDirectory to read all source files)
- For example, if your optimizer plugin aggregates your javascript files to "/javascript/bundle.js", we must overwrite this URL via a servlet mapping.
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 - Now we configure jetty to use our "web-localhost.xml" as overrideDescriptor
1 2 3 | < profile > < id >jetty-run</ id > </ profile > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | < 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 > |
1 2 3 | < properties > < maven.test.skip >true</ maven.test.skip > </ properties > |
1 2 3 4 5 6 7 8 9 10 | < plugin > < groupId >org.apache.maven.plugins</ groupId > < artifactId >maven-war-plugin</ artifactId > < executions > < execution > < id >default-war</ id > < phase >none</ phase > </ execution > </ executions > </ plugin > |
1 2 3 4 5 6 7 8 9 10 | < plugin > < groupId >org.primefaces.extensions</ groupId > < artifactId >resources-optimizer-maven-plugin</ artifactId > < executions > < execution > < id >optimize</ id > < phase >none</ phase > </ execution > </ executions > </ plugin > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | @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(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | < 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 > |
1 2 3 4 5 6 7 8 9 10 | < 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 > |