Jetty embedded web war Release Method

Source: Internet
Author: User

Jetty embedded web war Release Method
I. Launch method of direct war:1) the content of the Runner class is as follows: note that it must be in the root directory, but I personally think it is not necessarily ImportJava. io. File;ImportJava.net. URL;ImportJava. security. ProtectionDomain;ImportOrg. eclipse. jetty. server. Server;ImportOrg. eclipse. jetty. server. nio. NetworkTrafficSelectChannelConnector;ImportOrg. eclipse. jetty. util. thread. QueuedThreadPool;ImportOrg. eclipse. jetty. webapp. WebAppContext;Public ClassRunner {Public Static VoidMain (String [] args)ThrowsException {String jettyVersion = Server.GetVersion();Final IntPort = Integer.ParseInt(System.GetProperty("Port", "8088"); ProtectionDomain protectionDomain = Runner.Class. GetProtectionDomain (); URL location = protectionDomain. getCodeSource (). getLocation (); String warFile = location. toExternalForm (); String currentDir =NewFile (location. getPath (). getParent (); File workDir =NewFile (currentDir, "work"); System.Out. Println ("######### jettyVersion =" + jettyVersion); System.Out. Println ("######### port =" + port); System.Out. Println ("######### currentDir =" + currentDir); System.Out. Println ("######### workDir =" + workDir); System.Out. Println ("######### warFile =" + warFile); WebAppContext webapp =NewWebAppContext (); webapp. setContextPath ("/"); // webapp. setResourceBase (". "); webapp. setTempDirectory (workDir); // webapp. setClassLoader (Thread. currentThread (). getContextClassLoader (); webapp. setWar (warFile); NetworkTrafficSelectChannelConnector conne=NewNetworkTrafficSelectChannelConnector (); connector. setPort (port); connector. setMaxIdleTime (60000); connector. setRequestHeaderSize (10240); connector. setSoLingerTime (-1); connector. setThreadPool (NewQueuedThreadPool (1024); Server server =NewServer (); server. addConnector (connector); server. setHandler (webapp); server. start (); server. join ();}}2) Running Mode:1: java-jar tdt-web-0.0.1-SNAPSHOT-fat.war 2: mvn jetty: run; 3: directly run the main method of the above class, but pay attention to the war path and lib path;3) add all dependent jar files;<Dependency> <groupId> org. eclipse. jetty. orbit </groupId> <artifactId> javax. servlet </artifactId> <version> 3.0.0.v201112011016 </version> <scope> provided </scope> </dependency> <groupId> org. eclipse. jetty </groupId> <artifactId>Jetty-Server </artifactId> <version >$ {jetty. version }</version> <scope> provided </scope> </dependency> <groupId> org. eclipse. jetty </groupId> <artifactId>Jetty-Webapp</ArtifactId> <version >$ {jetty. version }</version> <scope> provided </scope> </dependency> <groupId> org. eclipse. jetty. orbit </groupId> <artifactId> org. apache. jasper. glassfish </artifactId> <version> 2.2.2.v201112011158 </version> <scope> provided </scope> </dependency> <groupId> org. eclipse. jetty. orbit </groupId> <artifactId> javax. el </artifactId> <version> 2.2.0.v201108011116 </version> <scope> provided </scope> </dependency>
<Dependency> <groupId> javax. servlet </groupId> <artifactId>Servlet-Api</ArtifactId> <version> 2.5 </version> <scope> provided </scope> </dependency>4) The war package method is as follows:<! --Jetty--> <Plugin> <groupId> org. mortbay. jetty </groupId> <artifactId>Jetty-Maven-Plugin</ArtifactId> <configuration> <webAppSourceDirectory >$ {basedir}/src/webapp </webAppSourceDirectory> <webAppConfig> <contextPath>/</contextPath> <descriptor >$ {basedir} /src/webapps/WEB-INF/web. xml </descriptor> </webAppConfig> <classesDirectory >$ {basedir}/target/classes </classesDirectory> <connectors> <connector implementation ="Org. eclipse. jetty. server. nio. SelectChannelConnector"& Gt; <port> 8088 </port> <maxIdleTime> 60000 </maxIdleTime> </connector> </connectors> </configuration> </plugin> <! -- InsertJettyClass (compiler) --> <plugin> <groupId> org. apache. maven. plugins </groupId> <artifactId>Maven-War-Plugin</ArtifactId> <version> 2.3 </version> <configuration> <archive> <manifest> <mainClass> Runner </mainClass> <! -- <AddClasspath> true </addClasspath> --> </manifest> </archive> </configuration> </plugin> <groupId> org. apache. maven. plugins </groupId> <artifactId>Maven-Antrun-Plugin</ArtifactId> <version> 1.7 </version> <executions> <execution> <id> main-class-placement </id> <phase> prepare-package </phase> <configuration> <target> <move todir ="$ {Project. build. directory}/$ {project. artifactId}-$ {project. version}-$ {package. environment }/"> <Fileset dir ="$ {Project. build. directory}/classes /"> <Include name ="Runner. class"/> </Fileset> </move> </target> </configuration> <goals> <goal> run </goal> </goals> </execution> </executions> </plugin> <groupId> org. apache. maven. plugins </groupId> <artifactId>Maven-Dependency-Plugin</ArtifactId> <version> 2.5.1 </version> <executions> <execution> <id>Jetty-Classpath</Id> <phase> prepare-package </phase> <goals> <goal> unpack-dependencies </goal> </goals> <configuration> <includeGroupIds> org. eclipse. jetty, org. eclipse. jetty. orbit </includeGroupIds> <includeScope> provided </includeScope> <! -- Remove some files in order to decrease size --> <excludes> *, about_files/*, META-INF/* </excludes> <outputDirectory >$ {project. build. directory}/$ {project. artifactId}-$ {project. version}-$ {package. environment}/</outputDirectory> </configuration> </execution> </executions> </plugin>5) The contents of the packaged war are as follows:












Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.