zoukankan      html  css  js  c++  java
  • 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>
    

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

  • 相关阅读:
    jquery.validate ajax提交
    linux权限不够,sh不能用
    几个简单的基类
    类型转换辅助工具类TypeCaseHelper
    linux下修改tomcat内存大小
    Hibernate,JPA注解@OneToMany_Map
    Hibernate,JPA注解@OneToMany_Set
    Hibernate,JPA注解@PrimaryKeyJoinColumn
    Hibernate,JPA注解@OneToOne_JoinColumn
    Hibernate,JPA注解@SecondaryTables
  • 原文地址:https://www.cnblogs.com/je-ge/p/6376129.html
Copyright © 2011-2022 走看看