简体   繁体   English

使用命令行运行Java Maven项目

[英]run java maven project with command line

I create a HelloWorld REST Web-Server with eclipse. 我用Eclipse创建了一个HelloWorld REST Web服务器。 I created a Dynamic Web Project with Eclipse, I converted the project to a maven project ... When I run the project with eclipse everything is working fine. 我用Eclipse创建了一个Dynamic Web Project,然后将项目转换为maven项目。当我使用Eclipse运行项目时,一切工作正常。 Know I want to run the project with command line. 知道我想用命令行运行项目。 I installed maven and then I run mvn clean install site .It build successfully. 我安装了maven,然后运行mvn clean install site它成功构建。 What shall I do after that ? 之后我该怎么办?

You should deploy your created war on a server so that you can start using this. 您应该将创建的战争部署在服务器上,以便可以开始使用它。 Within maven this can be done with the cargo-maven2-plugin . 在maven中,这可以通过cargo-maven2-plugin

An example of such a deployment with cargo is shown below: 此类货物部署的示例如下所示:

            <!--
        Plugin to initiate instance of tomcat server
        -->
        <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.4.9</version>
            <inherited>false</inherited>
            <configuration>
                <wait>true</wait>
                <container>
                    <containerId>tomcat7x</containerId>
                    <zipUrlInstaller>
                        <url>
                            http://apache.mirror1.spango.com/tomcat/tomcat-7/v${tomcat.version}/bin/apache-tomcat-${tomcat.version}.zip
                        </url>
                        <downloadDir>
                            ${project.build.directory}/downloads
                        </downloadDir>
                        <extractDir>
                            ${project.build.directory}/extracts
                        </extractDir>
                    </zipUrlInstaller>
                    <type>installed</type>

                    <dependencies>
                        <dependency>
                            <groupId>org.jboss.narayana.jta</groupId>
                            <artifactId>narayana-jta</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>org.uniknow.tomcat</groupId>
                            <artifactId>narayana-tomcat-listener
                            </artifactId>
                        </dependency>
                        <dependency>
                            <groupId>javax.transaction</groupId>
                            <artifactId>jta</artifactId>
                        </dependency>
                        <dependency>
                            <groupId>org.jboss.logging</groupId>
                            <artifactId>jboss-logging</artifactId>
                        </dependency>
                    </dependencies>
                    <!--<log>${project.build.directory}/logs/tomcat.log</log>-->
                    <!--<output>${project.build.directory}/logs/tomcat.out-->
                    <!--</output>-->
                </container>

                <!-- Configuration web server -->
                <configuration>
                    <type>standalone</type>
                    <home>${project.build.directory}/tomcat</home>
                    <properties>
                        <!--<cargo.logging>high</cargo.logging>-->
                        <cargo.servlet.port>8080</cargo.servlet.port>
                        <cargo.rmi.port>8206</cargo.rmi.port>
                        <cargo.tomcat.ajp.port>8010</cargo.tomcat.ajp.port>
                    </properties>
                    <files>
                        <copy>
                            <file>${basedir}/src/config/server.xml</file>
                            <todir>conf</todir>
                            <configfile>true</configfile>
                            <overwrite>true</overwrite>
                        </copy>
                        <copy>
                            <file>${basedir}/src/config/context.xml</file>
                            <todir>conf</todir>
                            <configfile>true</configfile>
                            <overwrite>true</overwrite>
                        </copy>
                    </files>
                </configuration>

                <deployables>
                    <deployable>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>${project.artifactId}</artifactId>
                        <type>war</type>
                    </deployable>
                </deployables>
            </configuration>
        </plugin>

This is part of the project you can find here tutorials/rest 这是项目的一部分,您可以在这里找到教程/ rest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM