【问题标题】:run java maven project with command line使用命令行运行 java maven 项目
【发布时间】:2016-04-12 12:48:41
【问题描述】:

我用 eclipse 创建了一个 HelloWorld REST Web-Server。我用 Eclipse 创建了一个动态 Web 项目,我将该项目转换为一个 Maven 项目......当我用 Eclipse 运行该项目时,一切正常。知道我想用命令行运行项目。我安装了 maven,然后运行mvn clean install site。它构建成功。之后我该怎么办?

【问题讨论】:

  • 可能正在部署您的网络项目?
  • 在哪里?如何 ?生成了哪些文件? build 文件夹是空的...这是我的第一个 Web 应用程序,所以我有点困惑...
  • 好吧,我真的不知道,但是如果有类似“战争”的东西,请查看您的目标目录。安装tomcat,在eclipse中创建新服务器,添加你的项目并部署。或者将你的war文件复制到服务器webapps目录中,将部署。启动服务器并转到 url(类似于 localhost:8080)

标签: java maven pom.xml


【解决方案1】:

您应该在服务器上部署您创建的战争,以便您可以开始使用它。在 maven 中,这可以通过 cargo-maven2-plugin 来完成。

下面显示了这样一个带有货物的部署示例:

            <!--
        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>

这是项目的一部分,您可以在这里找到 tutorials/rest

【讨论】:

    猜你喜欢
    • 2018-07-16
    • 1970-01-01
    • 2011-04-10
    • 2013-05-08
    • 2019-07-04
    • 2014-05-04
    • 2016-07-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多