Maven 菜鸟教程 3 怎样启动web项目

2022-10-04 19:08:30 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

方案1:dos运行

运行cmd输入
  • mvn jetty:run
jetty插件版本
  • 先在pom.xml添加jetty插件
  • jdk7可以使用jetty插件7.1.0.RC1
  • jdk8要使用高版本插件,如8.1.16.v20140903
代码语言:javascript复制
<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
代码语言:javascript复制
<Context path="" docBase="指向webapp文件路径"/>

方案3:右键运行

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

代码语言:javascript复制
<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://javaforall.cn/196201.html原文链接:https://javaforall.cn

0 人点赞