Maven 教程3-怎样启动web项目

方案1:dos运行

运行cmd输入
  • mvn jetty:run
jetty插件版本
  • 先在pom.xml添加jetty插件
  • jdk7可以使用jetty插件7.1.0.RC1
  • jdk8要使用高版本插件,如8.1.16.v20140903
<plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <!--jdk1.7-->
                <!--version>7.1.0.RC1</version-->
                <!--jdk1.8-->
                <version>8.1.16.v20140903</version>
                <configuration>
                    <webAppConfig>
                        <contextPath>/</contextPath>
                    </webAppConfig>
                </configuration>
            </plugin>

方案2:Eclipse运行

安装tomcat插件

下载地址http://www.eclipsetotale.com/tomcatPlugin.html
- tomcatPluginV331.zip
http://www.eclipsetotale.com/tomcatPlugin/tomcatPluginV331.zip
- 解压缩之后,只有一个jar文件
把此jar文件放入eclipse根目录plugin

配置运行
  • 打勾
    添加tomcat插件,打一个唯一的勾后运行tomcat,相当于把pom里面配置的jar文件和编译的class添加到tomcat的classpath
    这里写图片描述
  • 添加server runtime至工程
  • 修改外置tomcat的server.xml
<Context path="" docBase="指向webapp文件路径"/>

方案3:右键运行

pom.xml配置一下把maven项目变成标准web工程结构

<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>
    <groupId>com.jege.maven</groupId>
    <artifactId>maven-tomcat-plugin</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>maven-tomcat-plugin Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.9</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>dev.eclipse</id>
            <build>
                <finalName>maven-tomcat-plugin</finalName>
                <directory>${basedir}/src/main/webapp/WEB-INF/</directory>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>2.3.2</version>
                        <configuration>
                            <source>1.7</source>
                            <target>1.7</target>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-resources-plugin</artifactId>
                        <version>2.7</version>
                        <configuration>
                            <encoding>UTF-8</encoding>
                            <outputDirectory>${basedir}/src/main/webapp/WEB-INF/classes</outputDirectory>
                        </configuration>
                        <dependencies>
                            <dependency>
                                <groupId>org.apache.maven.shared</groupId>
                                <artifactId>maven-filtering</artifactId>
                                <version>1.3</version>
                            </dependency>
                        </dependencies>
                    </plugin>
                    <plugin>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>2.1</version>
                        <executions>
                            <execution>
                                <id>copy-dependencies</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>copy-dependencies</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <includeTypes>jar</includeTypes>
                            <overWriteSnapshots>true</overWriteSnapshots>
                            <type>jar</type>
                            <outputDirectory>${basedir}/src/main/webapp/WEB-INF/lib</outputDirectory>
                            <excludeArtifactIds>jsp-api,servlet-api</excludeArtifactIds>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>dev.eclipse2</id>
            <build>
                <finalName>maven-tomcat-plugin</finalName>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>2.3.2</version>
                        <configuration>
                            <source>1.7</source>
                            <target>1.7</target>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-resources-plugin</artifactId>
                        <version>2.7</version>
                        <configuration>
                            <encoding>UTF-8</encoding>
                            <outputDirectory>${basedir}/target/classes</outputDirectory>
                        </configuration>
                        <dependencies>
                            <dependency>
                                <groupId>org.apache.maven.shared</groupId>
                                <artifactId>maven-filtering</artifactId>
                                <version>1.3</version>
                            </dependency>
                        </dependencies>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

如果觉得我的文章或者代码对您有帮助,可以请我喝杯咖啡。
您的支持将鼓励我继续创作!谢谢!
微信打赏
支付宝打赏

转载于:https://www.cnblogs.com/je-ge/p/6376129.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值