设为首页 收藏本站
查看: 392|回复: 0

[经验分享] 发布项目到jetty/tomcat

[复制链接]

尚未签到

发表于 2017-1-25 07:17:11 | 显示全部楼层 |阅读模式
  将maven管理的web模块发布到jetty服务器中
  student-parent模块的pom.xml中声明插件

<!-- jetty插件 -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<scanIntervalSeconds>1000</scanIntervalSeconds>
</configuration>
</plugin>
</plugins>
  
  student-web模块的pom.xml中引入插件

<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
  开启服务:
  pom.xml右键---build---goals:jetty:run
  停止服务:
  直接在eclipse的控制台点击停止按钮即可!
  将maven管理的web模块发布到tomcat服务器中
  第一种:作为一个独立的项目进行发布,不与其它项目一起部署,tomcat启动后只能访问该项目
  student-web模块的pom.xml

<!-- cargo插件 配置tomcat-->
<!-- 独立发布 -->
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<container>
<containerId>tomcat6x</containerId>
<home>E:\technology-hqh\soft\server\apache-tomcat-6.0.29</home>
</container>
<configuration>
<type>standalone</type>
<home>${project.build.directory}/tomcat6-deploy</home>
<properties>
<cargo.servlet.port>9999</cargo.servlet.port>
</properties>
</configuration>
</configuration>
</plugin>

  第二种:war包被放到tomcat的webapps目录下,tomcat启动后,所有项目都能被访问到
  student-web模块的pom.xml

<!-- 将war包加入到tomcat的webapps下,与其它项目一起运行 -->
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<!-- Container configuration -->
<container>
<containerId>tomcat6x</containerId>
<home>E:\technology-hqh\soft\server\apache-tomcat-6.0.29</home>
</container>
<!-- Configuration to use with the container (which will also configure the deployer) -->
<configuration>
<type>existing</type>
<home>E:\technology-hqh\soft\server\apache-tomcat-6.0.29</home>
</configuration>
</configuration>
</plugin>

  启动服务
  pom.xml右键---build---goals:celan package cargo:start
  pom.xml右键---build---goals:cargo:run
  停止服务
  pom.xml右键---build---goals:cargo:stop
  注意:使用eclipse控制的停止按钮不会停止tomcat服务,端口8080仍然被监听着,必须使用cargo:stop命令才能在eclipse中停止掉tomcat服务!
  ---------------------------------------------------------------------------------------------------------------
  项目相关的配置文件
  parent模块的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- 模型版本 -->
<modelVersion>4.0.0</modelVersion>
<!-- 聚合:聚合其它模块 -->
<modules>
<module>../student-core</module>
<module>../student-persistent</module>
<module>../student-service</module>
</modules>
<!-- 继承:超级pom的坐标,该pom中的配置用于其它模块继承所用 -->
<groupId>com.hqh.student</groupId>
<artifactId>student-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<!-- 配置项目发布到私服的哪个仓库中 -->
<distributionManagement>
<!-- 配置SNAPSHOT版本发布的目标仓库 -->
<snapshotRepository>
<id>student-SNAPSHOT</id>
<name>student project snapshot</name>
<!-- 使用nexus默认提供的snapshot仓库,没有按项目为单位创建仓库 -->
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
<!-- 配置release版本发布的目标仓库 -->
<repository>
<id>student-release</id>
<name>student project release</name>
<!-- 使用nexus默认提供的release仓库,没有按项目为单位创建仓库 -->
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
</distributionManagement>
<name>student-parent</name>
<url>http://maven.apache.org</url>
<!-- 单点维护属性,其它地方通过${name}来引用 -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.10</junit.version>
<spring.version>3.0.5.RELEASE</spring.version>
</properties>
<!-- 下面的配置需要子类显示声明才能被继承 -->
<dependencyManagement>
<dependencies>
<!-- 模块 -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>student-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>student-persistent</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>student-service</artifactId>
<version>${project.version}</version>
</dependency>
<!-- junit测试单元 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- 日志 -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
</dependency>
<!-- SPRING -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.11</version>
</dependency>
<!-- ORM -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.10.Final</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<!-- database -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.19</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<!-- j2se -->
<dependency>
<groupId>com.kenai.nbpwr</groupId>
<artifactId>javax-inject</artifactId>
<version>1.0-201002241208</version>
</dependency>
<!-- commons -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>
<!-- servlet+jstl+jsp -->
<dependency>
<groupId>servletapi</groupId>
<artifactId>servletapi</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>jsptags</groupId>
<artifactId>pager-taglib</artifactId>
<version>2.0</version>
</dependency>
<!-- json -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.6</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.6</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- jetty插件 -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<scanIntervalSeconds>1000</scanIntervalSeconds>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

  student-web模块的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:beans.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>srpingMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>srpingMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
  springMVC需要的servlet配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="        http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven/>
<!-- 配置需要被扫描的包 -->
<context:component-scan base-package="com.hqh.student"/>
<!-- 配置对静态资源文件的访问不被过滤 -->
<mvc:resources location="/resources/" mapping="/resources/**"/>
<!-- 配置返回的数据如何呈现:前缀+逻辑视图+后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<!-- <property name="defaultErrorView">
<value>failure</value>
</property> -->
<property name="exceptionMappings">
<props>
<prop key="com.hqh.student.exception.StudentException">error</prop>
</props>
</property>
</bean>
</beans>
  student-web模块的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- 继承 -->
<parent>
<groupId>com.hqh.student</groupId>
<artifactId>student-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../student-parent/pom.xml</relativePath>
</parent>
<artifactId>student-web</artifactId>
<packaging>war</packaging>
<name>student-web Maven Webapp</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>student-service</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
</dependencies>
<build>
<finalName>student-web</finalName>
<plugins>
<!-- jetty插件 -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
<!-- cargo插件 配置tomcat-->
<!-- 第一种方式:独立发布
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<container>
<containerId>tomcat6x</containerId>
<home>E:\technology-hqh\soft\server\apache-tomcat-6.0.29</home>
</container>
<configuration>
<type>standalone</type>
<home>${project.build.directory}/tomcat6-deploy</home>
<properties>
<cargo.servlet.port>9999</cargo.servlet.port>
</properties>
</configuration>
</configuration>
</plugin>
-->
<!-- 第二种方式:与其它项目一起运行(将war包加入到tomcat的webapps下) -->
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<!-- Container configuration -->
<container>
<containerId>tomcat6x</containerId>
<home>E:\technology-hqh\soft\server\apache-tomcat-6.0.29</home>
</container>
<!-- Configuration to use with the container (which will also configure the deployer) -->
<configuration>
<type>existing</type>
<home>E:\technology-hqh\soft\server\apache-tomcat-6.0.29</home>
</configuration>
</configuration>
</plugin>
</plugins>
</build>
</project>

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-332996-1-1.html 上篇帖子: Tomcat启动失败问题解决 下篇帖子: 解决tomcat端口被占用
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表