eclipse builds maven web project

eclipse builds maven web project

Label: eclipseEclipsejavaJavaJAVAmavenMavenweb serviceweb service
  108379 people read   comments (21)   collection   report
  Classification:
JAVA web development (8) 

Build a web project using Eclipse's maven

1. Select to create a Maven Project, select File -> New -> Other, select Maven -> Maven Project in the New window; click next

        

 

 

2. Select the project path Usedefault Workspace location default workspace

        

 

 

3. Select the project type and select maven-archetype-webapp in Artifact Id

        

 

 

4. Enter Group ID and Artifact ID, and Package

        The Group ID is generally written in capital letters for the project name. Artifact ID is the subproject name.

        Package is to build a package for you by default, you can also not write it

        

 

5. The newly created file structure is as shown below

        If there is a lot of content displayed here, it is generally a problem of Filters settings; or the perspective is JavaEE mode, and you can change it to Java mode.

        

 

6. To configure the project, you need to add three folders: src/main/java, src/test/java, and src/test/resources. Right-click the project root directory and click New -> Source Folder to create these three folders

        Note: It is not a normal Folder, but a Source Folder

        

 

        

 

7、更改class路径 右键项目,Java Build Path -> Source 下面应该有4个文件夹。src/main/java,src/main /resources,src/test/java ,src/test/resources

        选上Allow output folders for source folders

        双击每个文件夹的Output folder,选择路径

        src/main/java,src/main/resources,选择target/classes;

        src/test/java ,src/test/resources, 选择target/test-classes;        

        在此处还要更改:更改文件夹显示的顺序:点击Order and Export;更改JDK版本:在Libraries双击JRE System Library,要1.6版本

        

        

 

8、把项目变成Dynamic Web项目 右键项目,选择Project Facets,点击Convert to faceted fro

        

 

9、配置Project Facets 更改Dynamic Web Module的Version为2.3。(3.0为Java7的)。
        如果提示错误,可能需要在Java Compiler设置Compiler compliance level 为1.6,或者需要在此窗口的Java的Version改成1.6

        

10、设置部署程序集(Web Deployment Assembly)
        上面步骤设置完成后,点击OK,Properties窗口会关 闭,在右键项目打开此窗口。在左侧列表中会出现一个Deployment Assembly,点击进去后,如下图

        

 

        此处列表是,部署项目时,文件发布的路径。

        (1) We delete the two items of test, because test is used for testing and does not need to be deployed.

        (2) Set to publish Maven's jar package to lib.

        Add -> JavaBuild Path Entries -> Maven Dependencies -> Finish

        Setting completed renderings

        

 

11. The build framework adds the required jar package to pom.xml

        Use the Maven POM editor to open the pom.xml file in the project, select Dependencies, and click Add in the Dependencies column. First, a search button will pop up. For example, if you enter jsf, it will automatically search for JSF-related jar packages. We choose version 2.0.4 jsf, add all the jsf packages

        Other jar packages that need to be added are: junit, jstl

        Or click pom.xml to directly edit the pom.xml file, so that you can directly copy the dependencies content;

        Our pom.xml file can directly copy the following content:

        <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.smile.maven.demo</groupId>
                <artifactId>maven-demo-web</artifactId>
                <packaging>war</packaging>
                <version>0.0.1-SNAPSHOT</version>
                <name>maven-demo-web Maven Webapp</name>
                <url>http://maven.apache.org</url>

                <dependencies>
                        <dependency>
                                <groupId>junit</groupId>
                                <artifactId>junit</artifactId>
                                <version>3.8.1</version>
                                <scope>test</scope>
                        </dependency>
                        <dependency>
                                <groupId>com.sun.faces</groupId>
                                <artifactId>jsf-api</artifactId>
                                <version>2.0.4-b09</version>
                        </dependency>
                        <dependency>
                                <groupId>com.sun.faces</groupId>
                                <artifactId>jsf-impl</artifactId>
                                version>2.0.4-b09</version>
                        </dependency>
                        <dependency>
                                <groupId>javax.servlet</groupId>
                                <artifactId>jstl</artifactId>
                                <version>1.2</version>
                        </dependency>
                        <dependency>
                                <groupId>taglibs</groupId>
                                <artifactId>standard</artifactId>
                                <version>1.1.2</version>
                        </dependency>
                </dependencies>

                <build>
                        <finalName>maven-demo-web</finalName>
                </build>

        </project>

 

12. Right-click on the project to publish: Run As -> Maven install and then Run As -> Mavenpackage.
        After generating, run it with Tomcat

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326866953&siteId=291194637