第一步、pom.xml 添加 eclipse-jetty 依赖
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| <build> <plugins> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.4.11.v20180605</version> <configuration> <webAppSourceDirectory>src/main/webapp</webAppSourceDirectory> <scanIntervalSeconds>60</scanIntervalSeconds> <stopKey>foo</stopKey> <stopPort>9090</stopPort> <jettyXml>src/main/webapp/WEB-INF/jetty.xml</jettyXml> <httpConnector> <port>8080</port> <idleTimeout>60000</idleTimeout> </httpConnector> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.5</version> <configuration> <target>1.7</target> <source>1.7</source> <encoding>utf-8</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-clean-plugin</artifactId> <version>2.5</version> <configuration> <filesets> <fileset> <directory>src/main/webapp/WEB-INF</directory> <includes> <include>classes</include> </includes> <followSymlinks>false</followSymlinks> </fileset> </filesets> </configuration> </plugin> </plugins> <outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory> </build>
|
第二步,创建 jetty.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="OtherServer" class="org.eclipse.jetty.server.Server"> <Call name="addConnector"> <Arg> <New class="org.eclipse.jetty.server.ServerConnector"> <Arg name="server"> <Ref refid="OtherServer"/> </Arg> <Set name="port">8888</Set> </New> </Arg> </Call> </Configure>
|
第三步,创建 jetty-env.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| <Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext"> <Set name="contextPath">/ydzf</Set> <New id="defaultDB" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg><Ref refid="wac"/></Arg> <Arg>jdbc/default</Arg> <Arg> <New class="org.apache.tomcat.dbcp.dbcp.BasicDataSource"> <Set name="validationQuery">select 1</Set> <Set name="maxActive">10</Set> <Set name="maxIdle">30</Set> <Set name="maxWait">10000</Set> <Set name="username">{username}</Set> <Set name="password">{password}</Set> <Set name="driverClassName">com.microsoft.sqlserver.jdbc.SQLServerDriver</Set> <Set name="url">jdbc:sqlserver://{host}:{port};databaseName={databaseName};user={username};password={password}</Set> </New> </Arg> </New> <New id="workflowDB" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg><Ref refid="wac"/></Arg> <Arg>jdbc/workflow</Arg> <Arg> <New class="org.apache.tomcat.dbcp.dbcp.BasicDataSource"> <Set name="validationQuery">select 1</Set> <Set name="maxActive">10</Set> <Set name="maxIdle">30</Set> <Set name="maxWait">10000</Set> <Set name="username">{username}</Set> <Set name="password">{password}</Set> <Set name="driverClassName">com.microsoft.sqlserver.jdbc.SQLServerDriver</Set> <Set name="url">jdbc:sqlserver://{host}:{port};databaseName={databaseName};user={username};password={password}</Set> </New> </Arg> </New> </Configure>
|
确保 pom.xml 里面有依赖 com.microsoft.sqlserver.jdbc.SQLServerDriver 等数据库连接