如何使用maven构建后运行该项目 [英] How to run the project after building with maven

查看:195
本文介绍了如何使用maven构建后运行该项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的maven。所以我有一个项目与pom.xml文件。所以我用maven运行,构建成功了。我有玻璃鱼Glassfish已经分开运行。那么现在Glassfish运行项目的下一步是什么?我的IDE是eclipse。

解决方案

你必须先告诉Maven构建WAR,看看这个插件: href =http://maven.apache.org/plugins/maven-war-plugin/ =nofollow noreferrer> http://maven.apache.org/plugins/maven-war-plugin/ 。



然后你需要告诉maven如何部署到glassfish,你可以配置一个Maven执行插件来做到这一点(参见这里: http://mojo.codehaus.org/exec-maven-plugin/ )。或者您可以查看一个专门用于将maven与glassfish集成的自定义插件。这一个看起来很有前途,但我没有使用它: http://maven-glassfish-plugin.java .net /



Maven提供了很多基本的功能开箱即用,但构建自动化的大多数更酷的东西都是通过插件完成的。 / p>

更新



只需更新即可添加一个非常简单的Pom, -deployment。注意:如果您运行mvn clean install,将包装设置为war,maven将为您构建.war文件并将其放在目标/文件夹中。如果您只想开始,您可以手动将其部署到glassfish。



以下是一个非常简单的pom的一部分,它使用Maven执行插件来自动部署到glassfish作为构建函数:

 < build> 
< plugins>
< plugin>
< groupId> org.codehaus.mojo< / groupId>
< artifactId> exec-maven-plugin< / artifactId>
<执行>
< execution>
< goals>
< goal> exec< / goal>
< / goals>
< phase> install< / phase>
< / execution>
< / executions>
< configuration>
< executable> $ {path-to-asadmin-util}< / executable>
< arguments>
< argument> deploy< / argument>
< argument> - user = $ {username}]< / argument>
< argument> - passwordfile = $ {password-file}< / argument>
< argument> - host = localhost< / argument>
< argument> - port = 4848< / argument>
< argument> target / $ {project.name}< / argument>
< / arguments>
< / configuration>
< / plugin>
< / plugins>
< / build>

这基本上只是在glassfish asadmin实用程序[1]上调用deploy命令。您需要填写以下变量:




  • $ {path-to-asadmin-util} - >这是您的asadmin实用程序
    的路径(通常在glassfish_home / bin中)

  • $ {username} - > glassfish admin username

  • $ {password-file} - >登录glassfish的密码文件
    admin [2]

  • $ {project.name} - >你的战争名称



如果你想变得更复杂,我建议看看这个线程: GlassFish v3和glassfish-maven-plugin(Mac)



[1] - http://docs.oracle .com / cd / E18930_01 / html / 821-2433 / deploy-1.html#SJSASEEREFMANdeploy-1



[2] - http://docs.oracle.com/cd/E18930_01/html/821-2435/ghgrp.html#ghytn


I am new to maven. So I have a project with pom.xml file. So I ran that with maven and the build was successful. I have glassfish. Glassfish is already running separately. So now what is the next step to run the project with Glassfish? My IDE is eclipse.

解决方案

You have to first tell Maven to build the WAR, check out this plugin for that: http://maven.apache.org/plugins/maven-war-plugin/.

Then you need to tell maven how to deploy to glassfish, you can either configure a Maven execution plugin to do this (see here: http://mojo.codehaus.org/exec-maven-plugin/). Or you can look around for a custom plugin devoted to integrating maven with glassfish. This one looks promising, but I have not used it: http://maven-glassfish-plugin.java.net/.

Maven provides a lot of basic functionality out of the box, but most of the cooler stuff with build automation is done through plugins.

Update

Just updating to add a very simple Pom that will do a auto-deployment. Note: if you just run a "mvn clean install", with the packaging set to 'war', maven will build the .war file for you and place it in the target/ folder. You can take this and deploy it to glassfish manually if you just want to get started.

Below is part of a very simple pom that uses the Maven execution plugin to auto-deploy to glassfish as a function of the build:

<build>
  <plugins>
    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <executions>
        <execution>
        <goals>
              <goal>exec</goal>
        </goals>
        <phase>install</phase>
        </execution>
    </executions>
    <configuration>
        <executable>${path-to-asadmin-util}</executable>
        <arguments>
            <argument>deploy</argument>
            <argument>--user=${username}]</argument>
            <argument>--passwordfile=${password-file}</argument>
            <argument>--host=localhost</argument>
            <argument>--port=4848</argument>
            <argument>target/${project.name}</argument>
        </arguments>
    </configuration>
 </plugin>
 </plugins>
 </build>

This basically just calls the deploy command on the glassfish asadmin utility[1]. You need to fill in the following variables:

  • ${path-to-asadmin-util} --> this is the path to your asadmin utility (normally in the glassfish_home/bin)
  • ${username} --> glassfish admin username
  • ${password-file} --> password file for logging into glassfish admin[2]
  • ${project.name} --> name of your war

If you want to get more complicated I suggest taking a look at this thread: GlassFish v3 and glassfish-maven-plugin (Mac).

[1] - http://docs.oracle.com/cd/E18930_01/html/821-2433/deploy-1.html#SJSASEEREFMANdeploy-1

[2] - http://docs.oracle.com/cd/E18930_01/html/821-2435/ghgrp.html#ghytn

这篇关于如何使用maven构建后运行该项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆