遇到一个很讨厌的问题,用maven2构建web项目的时候,没有run on server的选项,很让人讨厌。google一下之后,看到一位iteye的仁兄写的帖子,试了一下,bingo,果然好用。

 

地址:http://celestialwolf.iteye.com/blog/720303#comments

 

 

初学maven即感受到其强大的便捷性,大体记录下maven的基础知识以备不时之需。

常用命令为 :

    mvn archetype:create :创建 Maven 项目

    mvn compile :编译源代码

    mvn test-compile :编译测试代码

    mvn test : 运行应用程序中的单元测试

    mvn site : 生成项目相关信息的网站

    mvn clean :清除目标目录中的生成结果

    mvn package : 依据项目生成 jar 文件

    mvn install :在本地 Repository 中安装 jar

    mvn deploy:将jar包发布到远程仓库

    mvn eclipse:eclipse :生成 Eclipse 项目文件

生成项目

   建一个 JAVA 项目 : mvn archetype:create -DgroupId=com.test -DartifactId=App

   建一个 web 项目 : mvn archetype:create -DgroupId=com.test -DartifactId=web-app -DarchetypeArtifactId=maven-archetype-webapp

解释:

   archetype 是一个内建插件,它的create任务将建立项目骨架

   archetypeArtifactId 项目骨架的类型

   groupId 项目的java包结构,可修改 artifactId 项目的名称,生成的项目目录也是这个名字,可修改

可用项目骨架有:

   maven-archetype-archetype

   maven-archetype-j2ee-simple

   maven-archetype-mojo

   maven-archetype-portlet

   maven-archetype-profiles (currently under development)

   maven-archetype-quickstart

   maven-archetype-simple (currently under development)

   maven-archetype-site

   maven-archetype-site-simple

   maven-archetype-webapp

web项目目录结构的布局:

   详见http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

Eclipse导入已存在的maven项目 :

    在导入之前需要在项目根目录下面执行如下命令:

 普通 Eclipse 项目执行 : mvn eclipse:eclipse Eclipse

 web 项目执行 : mvn eclipse:eclipse –Dwtpversion=1.0

    然后通过Eclipse的maven插件中选择导入已存在的maven项目即可将其导入。

学习过程中的问题:

     安装好m2eclipse插件后一般会报错误:Eclipse is running in a JRE, but a JDK is required Some Maven plugins may not work when importing projects or updating source folders.

    解决方式为:

1.创建一个Eclipse的启动的快捷方式,在其启动路径后添加-vm 你的JDK安装路径/bin/javaw.exe

2.在eclipse的安装目录下打开eclipse.ini中的-vmargs上面添加-vm 你的JDK安装路径/bin/javaw.exe         

    eclipse导入创建的web项目问题

在用eclipse导入web项目时 如果eclipse安装了wtp插件在会自动将其转化为eclipse认得到的web项目,在项目上面点击右键run as 的run on server可以用,但是当eclipse没有安装wtp插件时run on server则不用,此时的解决方式为用命令行切换到项目的根目录然后执行 mvn eclipse:eclipse –Dwtpversion=1.0即可解决。

 

GitHub 加速计划 / ma / maven
36
2
下载
Maven: Apache Maven是一个开源的项目管理和构建工具,主要用于Java项目。适合需要自动化项目构建和依赖管理的开发者。特点包括约定优于配置、易于使用和社区驱动。
最近提交(Master分支:1 个月前 )
83a38634 When using flatten-maven-plugin with updatePomFile=true and parent expansion, Maven incorrectly detected a parent cycle during the install phase. The error occurred because the consumer POM builder was using Path instead of ModelSource when reading the flattened POM. This change updates the PomArtifactTransformer API to use ModelSource instead of Path. ModelSource includes the necessary context (base directory, ModelLocator) to properly resolve parent POMs and avoid false cycle detection. Changes: - Updated PomArtifactTransformer.transform() to accept ModelSource instead of Path - Modified ConsumerPomArtifactTransformer to create ModelSource with proper resolution context - Updated DefaultConsumerPomBuilder and related classes to work with ModelSource - Added integration test to verify the fix Fixes #11399 (cherry picked from commit 5ec059c2d75393aaada2d2c1d0fe0100a1f79554) 1 天前
3411fd2f 1 天前
Logo

新一代开源开发者平台 GitCode,通过集成代码托管服务、代码仓库以及可信赖的开源组件库,让开发者可以在云端进行代码托管和开发。旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐