知识点

相关文章

更多

最近更新

更多

使用eclipse创建maven项目图文详解

2019-03-06 22:46|来源: 网路

基于eclipse创建maven Java项目

打开ecilpse,File--->New--->Other--->Maven--->Maven Projet进入创建maven项目窗口

选择maven-archetype-quickstart,快速创建一个java项目


接下来,输入Group Id,Artifact Id,Package等信息,点击finish结束


生成的Java项目包结构如下


从上图可以看出,JDK是1.5,使用maven-compiler-plugin指定编译时的JDK版本

<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>cn.luxh.app</groupId>
    <artifactId>my-app</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>my-app</name>
    <url>http://maven.apache.org</url>
 
    <!-- 指定属性 -->
    <properties>
        <junit.version>4.10</junit.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <jdk.version>1.6</jdk.version>
    </properties><build><plugins>
 
    <!-- 指定JDK的编译版本 -->
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.5.1</version>
        <configuration>
            <source>${jdk.version}</source>
            <target>${jdk.version}</target>
            <showWarnings>true</showWarnings>
        </configuration>
    </plugin>
    </plugins>
    </build>
 
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>


基于eclipse maven创建java Web项目

File--->New--->Other--->Maven--->Maven Projet

选择maven-archetype-webapp创建web项目

            


接下来,输入Group Id,Artifact Id,Package等信息,点击finish结束



创建Web项目结构如下:


把项目转为 Dynamic Web Module,在项目上点击右键,选择属性,然后选择Project facets,然后点击Convert to faceted form...

勾选Dynamic Web Module,选择3.0,表示支持servlet3.0

勾选Java,选择1.6或更高的jdk版本


工具只生成了一个叫 src/main/resource的source folder,我们需要手工添加 src/main/java、src/test/java和src/test/resource 三个source folder,在项目上右键 New ---->Source Folder,输入folder name即可。

修改Source Folder的编译路径,进入Java Build Bath窗口,双击每个文件夹下的Output folder,指定路径。

源代码应该放置到src/main/java中

源代码的资源文件应该放置在src/main/resources文件夹中

测试代码应该放置到src/test/java中

测试代码的资源文件应该放置在src/test/resources文件夹中


src/main/java和src/main/resource指定target/calsses

src/test/java和src/test/resource指定target/test-classes

都选上选上Allow output folders for source folders.

配置部署的程序Deployment Assembly,删掉test的那两项,test的程序发布的时候不需要,添加maven的依赖库,发布的时候可以发布到lib目录中,添加/src/main/webapp为部署的根目录


配置tomcat7,发布运行项目


转自:http://xidajiancun.iteye.com/blog/2004527


相关问答

更多
  • 如果只是想在Eclipse 中使用maven的话。不需要配置什么东西。 只需要安装maven插件就可以了。从你的图里面可以看出来你的Eclipse已经安装了插件。 如果说你还想要在命令行中使用maven 需要下载Apache maven 到电脑。 在环境变量中配置maven 变量,并且加入到 path 变量下 并且在Eclipse 中配置maven 。 window --》 prefrence --》 maven --- update user Setting ---> 选择你配置的maven config ...
  • 确保选择“创建简单项目”并编辑高级选项以链接现有项目。 Make sure you select Create simple project and edit advanced option to link existing projects.
  • 似乎eclipse无法生成此工件,因为给定的参数是错误的。 尝试使用命令行创建它,然后将其作为maven项目导入eclipse: mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeGroupId=co.ntier -DarchetypeArtifactId=spring-mvc-archetype -DarchetypeVersion=1.0.2 -DinteractiveMode=false ...
  • 按Ctrl + 3(在Eclipse Juno 3.8或4.2中) 键入maven select New Maven Project 另见http://www.vogella.com/articles/EclipseShortcuts/article.html Press Ctrl+3 (In Eclipse Juno 3.8 or 4.2) type maven select New Maven Project See also http://www.vogella.com/articles/Eclips ...
  • 也许Tycho( http://tycho.sonatype.org/ )会帮助你。 目前,它似乎有点像alpha,但在发布Maven 3.0后,Jason van Zyl承诺将花更多时间在Tycho上( http://www.sonatype.com/people/2010/10/maven-3-0-已降落/ )。 Maybe Tycho (http://tycho.sonatype.org/) will help you. Currently, it seems to be a little bit a ...
  • 同样的错误让我非常挣扎,我可以从eclipse市场下载testNG和其他东西,但是当我创建一个maven项目时,我得到了这个错误。 因为我的互联网连接正在通过代理。 我尝试了上述所有,但我无法解决这个错误,但这个人给了我解决方案: http://www.javahelps.com/2015/08/set-proxy-for-maven-in-eclipse.html 完成上述过程后,您必须从以下文件夹C:\ Users.m2 \ repository \ org \ apache \ maven \ arc ...
  • 我找到了答案,我忘了添加我在.m2 /目录中的settings.xml文件中使用的代理服务器。 I found the answer, I forgot to add the proxy server I was using in settings.xml file in .m2/ directory.
  • 以下xml文件确实对我有用。,这样做.. 1 | 在以下位置创建xml文件( settings.xml ), C:\Users\username\.m2\settings.xml 2 | 复制并粘贴下面包含多个镜像标记的xml片段。 3 | 保存xml文件。
  • I want to create a Maven project and convert it into a Java EE project. 你可以以任何一种方式工作。 让我们看看可能性 创建一个新项目(动态Web项目)并在JEE项目中添加所需的任何构面。 操作方法:设置项目后,只需右键单击项目 - > 配置 - > 转换为maven项目 ,指定artifactID和groupID即可完成! 而不是制作动态项目,只需先设置一个空白的maven项目,然后再添加facet。 如何:在Eclipse中, 新项目 ...
  • 问题可能是我的一些“ .lastUpdated”可能会阻止你的下载,你需要删除“ .lastUpdated”并更新maven项目。 找到{user} /。m2 / repository并删除所有可以执行此操作的“* .lastUpdated”文件 在%USERPROFILE%。m2中搜索* .lastUpdated,然后删除Eclipse报告为有问题的文件 要么 cd %userprofile%\.m2\repository for /r %i in (*.lastUpdated) do del %i 一 ...