您的位置:首页 > 移动开发 > WebAPP

eclipse Maven 使用记录 ------ 建立 webapp项目

2017-03-24 08:55 549 查看
maven 建立 webapp 项目 有2种方式 , 1.在原先app上转换为webapp项目 2.建立maven项目的时候 filter 选择webapp 该选项把webapp文件目录建好,其他的还是要自己配。。。。。
采用将原先的app项目改成 webapp项目

1.改变项目,动态web工程


让项目成此结构



eclipse buliders 配置文件
<?xml version="1.0" encoding="UTF-8"?>

<projectDescription>

<name>mmvc</name>

<comment></comment>

<projects>

</projects>

<buildSpec>

<buildCommand>

<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>

<arguments>

</arguments>

</buildCommand>

<buildCommand>

<name>org.eclipse.jdt.core.javabuilder</name>

<arguments>

</arguments>

</buildCommand>

<buildCommand>

<name>org.eclipse.wst.common.project.facet.core.builder</name>

<arguments>

</arguments>

</buildCommand>

<buildCommand>

<name>org.eclipse.wst.validation.validationbuilder</name>

<arguments>

</arguments>

</buildCommand>

<buildCommand>

<name>org.eclipse.m2e.core.maven2Builder</name>

<arguments>

</arguments>

</buildCommand>

</buildSpec>

<natures>

<nature>org.eclipse.m2e.core.maven2Nature</nature>

<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>

<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>

<nature>org.eclipse.wst.common.project.facet.core.nature</nature>

<nature>org.eclipse.jdt.core.javanature</nature>

<nature>org.eclipse.wst.jsdt.core.jsNature</nature>

</natures>

</projectDescription>

[/code]

项目 工程下 .settings ---- .jsdtscope文件修改 java脚本路径
<?xml version="1.0" encoding="UTF-8"?>

<classpath>

<classpathentry kind="src" path="/src/main/webapp"/>   //改这里

<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>

<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">

<attributes>

<attribute name="hide" value="true"/>

</attributes>

</classpathentry>

<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>

<classpathentry kind="output" path=""/>

</classpath>

[/code]

配置 web context root deploy-path 目录
如果项目原先为 web工程 ,这时候要换目录则需要进入配置文件改动
项目 工程下 .settings ---- org.eclipse.wst.common.component文件修改 发布目录

<?xml version="1.0" encoding="UTF-8"?>

<project-modules id="moduleCoreId" project-version="1.5.0">

<wb-module deploy-name="mmvc">

<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>

<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>

<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resource"/>

<property name="context-root" value="mmvc"/>

<property name="java-output-path" value="/mmvc/build/classes"/>

</wb-module>

</project-modules>

[/code]

文件目录建好之后 , 为了让java 脚本及配置文件能 auto bulid 需要配置 这2个目自动编译至webapp发布目录 /classes



ok web项目基本构建完成

2.pom.xml 配置 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/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>mmvc</groupId>

<artifactId>mmvc</artifactId>

<version>1</version>

<packaging>war</packaging>


<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<spring.version>3.0.5.RELEASE</spring.version>

</properties>


<dependencies>

<dependency>

<groupId>org.apache.openejb</groupId>

<artifactId>javaee-api</artifactId>

<version>5.0-1</version>

<scope>provided</scope>

</dependency>

<dependency>

<groupId>javax.faces</groupId>

<artifactId>jsf-api</artifactId>

<version>1.2_04</version>

<scope>provided</scope>

</dependency>

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>jstl</artifactId>

<version>1.2</version>

<scope>provided</scope>

</dependency>

<dependency>

<groupId>javax.servlet.jsp</groupId>

<artifactId>jsp-api</artifactId>

<version>2.1</version>

<scope>provided</scope>

</dependency>

<dependency>

<groupId>javax.faces</groupId>

<artifactId>jsf-impl</artifactId>

<version>1.2_04</version>

<scope>provided</scope>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-webmvc</artifactId>

<version>${spring.version}</version>

<scope>runtime</scope>

</dependency>


</dependencies>

<build>

<!-- 列出所依赖的 plugin mvn自动选择包含的 -->

<pluginManagement>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<configuration>

<source>1.6</source>

<target>1.6</target>

</configuration>

</plugin>

<plugin>

<groupId>org.eclipse.m2e</groupId>

<artifactId>lifecycle-mapping</artifactId>

<version>1.0.0</version>

<configuration>

<lifecycleMappingMetadata>

<pluginExecutions>

<pluginExecution>

<pluginExecutionFilter>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-dependency-plugin</artifactId>

<versionRange>[2.0,)</versionRange>

<goals>

<goal>copy-dependencies</goal>

</goals>

</pluginExecutionFilter>

<action>

<ignore />

</action>

</pluginExecution>

</pluginExecutions>

</lifecycleMappingMetadata>

</configuration>

</plugin>

</plugins>

</pluginManagement>


<plugins>

<!-- remove jar plugins -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-clean-plugin</artifactId>

<executions>

<execution>

<id>clean</id>

<phase>install</phase>

<goals>

<goal>clean</goal>

</goals>

<configuration>

<directory>/src/main/webapp/WEB-INF/lib</directory>

</configuration>

</execution>

</executions>

</plugin>


<!-- copy jar plugins -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-dependency-plugin</artifactId>

<executions>

<execution>

<id>copy-dependencies</id>

<phase>package</phase>

<goals>

<goal>copy-dependencies</goal>

</goals>

<configuration>

<outputDirectory>src/main/webapp/WEB-INF/lib</outputDirectory>

<excludeTransitive>false</excludeTransitive>

<stripVersion>false</stripVersion> <!-- 复制jar 的时候去掉版本信息 true : 去掉 false: 不去掉 -->

<includeScope>runtime</includeScope>

</configuration>

</execution>

</executions>

</plugin>


</plugins>

</build>


</project>

[/code]

以上配置包含 javeee 自带的jar , springmvc 框架 所需jar ,可以从maven远程仓库获取至本地服务器仓库 ,再 从maven仓库获取
另包含 自动部署的时候 copy jar到 发布目录下的lib目录下
ok 需要生成 package的时候 会自动生成到 target 目录下并打成war包

maven package执行的时候会遇到jdk版本不对的问题 :原因是 maven所指定的jdk版本与项目使用的jdk版本不一致
参见 maven 使用记录之修改 maven默认jdk版本
跑起来吧 。。。。。。。。。。。。。。。。。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: