GlassFish 3 + Maven +远程部署 [英] GlassFish 3 + Maven + remote deploy

查看:142
本文介绍了GlassFish 3 + Maven +远程部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到任何关于如何通过maven将简单的基于Maven的项目部署到远程GlassFish服务器的明确答案,如

  mvn package xxx:deploy 

我认为只有货运插件支持GlassFish 3.对吗?



我在配置方面存在问题。

任何示例远程GlassFish部署都非常棒。货物不是必须的,如果其他人支持远程GlassFish,那么我们也可以使用它。 解决方案

如果你想只使用maven-glassfish-plugin(假设版本2.1),你可以通过指定host参数来进行远程部署。下面是一个配置在maven settings.xml中设置的例子,并且一个插件使用一个配置文件加载它们:



在settings.xml中定义一个配置文件:

 <个人资料> 
< id> production-config< / id>
<属性>
< glassfish.glassfishDirectory> / var / local / glassfish /< /glassfish.glassfishDirectory>
< glassfish.user>管理员< /glassfish.user>
< glassfish.admin密码> adminadmin< /glassfish.adminPassword>
< glassfish.domain.name> prd-domain< /glassfish.domain.name>
< glassfish.domain.host> NAMEOFYOURREMOTEHOST< /glassfish.domain.host>
< glassfish.domain.adminPort> 10161< /glassfish.domain.adminPort>


< / properties>
< / profile>

接下来将此配置文件放入您的活动配置文件中:

 < activeProfiles> 
< activeProfile> production-config< / activeProfile>
< / activeProfiles>

在您的maven项目pom.xml中,创建一个配置文件并将maven-glassfish插件添加到您的个人资料列表:

 <个人资料> 
< id>制作< / id>
<激活>
< activeByDefault> false< / activeByDefault>
< os>
< arch> x86< / arch>
< family> linux< / family>
< / os>
<属性>
<名称>个人资料< / name>
<值>生产< /值>
< / property>
< file>
<存在>
$ {glassfish.glassfishDirectory} / domains / $ {glassfish.domain.name} /config/domain.passwords
< / exists>
< / file>
< / activation>
< build>
< plugins>
< plugin>
< groupId> org.glassfish.maven.plugin< / groupId>
< artifactId> maven-glassfish-plugin< / artifactId>
<配置>
< terse> true< / terse>
< echo> true< / echo>
< debug> true< / debug>
< glassfishDirectory> $ {glassfish.glassfishDirectory}< / glassfishDirectory>
< user> $ {glassfish.user}< / user>
< adminPassword> $ {glassfish.adminPassword}< / admin密码>
< domain>
< name> $ {glassfish.domain.name}< / name>
< host> $ {glassfish.domain.host}< / host>
< adminPort> $ {glassfish.domain.adminPort}< / adminPort>
< / domain>
<组件>
< component>
<名称> $ {project.artifactId}< / name>
< artifact> $ {project.build.directory} / $ {project.build.finalName} .war< / artifact>
< / component>
< /组件>
< / configuration>
<执行次数>
<执行>
<目标>
< goal> deploy< / goal>
< /目标>
< /执行>
< /执行次数>
< / plugin>
< / plugins>
< / build>
< / profile>

这应该是个诀窍。您可以使用maven运行此配置文件: mvn glassfish:deploy -P production 或者 mvn deploy -P production (因为我们已经将目标部署添加到插件的执行部分)



使用上述模型,您可以在每个环境(dev,acc,tst,prd)中创建不同的配置文件,并使用不同的设置。例如,您可以创建一个开发人员配置文件,其中使用本地glassfish来部署和运行单元/集成测试。



人们犯的常见错误是混淆了从要从中安装部署的主机进行远程部署的机器设置。 glassfishDirectory是您从中运行部署插件的地方。由于错误的插件挂起,无所事事,只是等待给人的印象是事情正在发生。另一个错误是为远程部署指定一个密码文件而不是密码,这也不会导致任何结果。


I couldn't find any clear answer about how to deploy simple Maven based project to remote GlassFish server via maven like

mvn package xxx:deploy

I think only cargo plugin supports GlassFish 3. Right?

I've problems at configuration side.

Any sample remote GlassFish deployment will be great. Cargo is not a must, if others are support remote GlassFish then we can also use it too.

解决方案

In case you want to only use maven-glassfish-plugin (let say version 2.1), you can do a remote deploy by specifying the "host" parameter. Below is an example where configurations are setup in maven settings.xml and an plugin loads them using a profile:

In settings.xml define a profile:

<profile>
     <id>production-config</id>    
     <properties>
       <glassfish.glassfishDirectory>/var/local/glassfish/</glassfish.glassfishDirectory>
       <glassfish.user>admin</glassfish.user>
       <glassfish.adminPassword>adminadmin</glassfish.adminPassword>
       <glassfish.domain.name>prd-domain</glassfish.domain.name>
       <glassfish.domain.host>NAMEOFYOURREMOTEHOST</glassfish.domain.host>
       <glassfish.domain.adminPort>10161</glassfish.domain.adminPort>
       .
       .
     </properties> 
</profile>

Next put this profile in your active profiles:

<activeProfiles>
    <activeProfile>production-config</activeProfile>
</activeProfiles>

In your maven project pom.xml, create a profile and add the maven-glassfish-plugin in your list of profiles:

<profile>
    <id>production</id>
    <activation>
     <activeByDefault>false</activeByDefault>
     <os>
    <arch>x86</arch>
    <family>linux</family>
     </os>
     <property>
    <name>profile</name>
    <value>production</value>
     </property>
     <file>
      <exists>
       ${glassfish.glassfishDirectory}/domains/${glassfish.domain.name}/config/domain.passwords
      </exists>
     </file>
   </activation>
   <build>
      <plugins>
          <plugin>
               <groupId>org.glassfish.maven.plugin</groupId>
               <artifactId>maven-glassfish-plugin</artifactId>
               <configuration>
                  <terse>true</terse>
                  <echo>true</echo>
                  <debug>true</debug>
                  <glassfishDirectory>${glassfish.glassfishDirectory}</glassfishDirectory>
                  <user>${glassfish.user}</user>
                  <adminPassword>${glassfish.adminPassword}</adminPassword>
                  <domain>
                     <name>${glassfish.domain.name}</name>
                     <host>${glassfish.domain.host}</host>
                     <adminPort>${glassfish.domain.adminPort}</adminPort>
                  </domain>
                  <components>
                    <component>
                      <name>${project.artifactId}</name>  
                 <artifact>${project.build.directory}/${project.build.finalName}.war</artifact>
                    </component>
                  </components>
               </configuration>
               <executions>
                    <execution>
                <goals>
            <goal>deploy</goal>
            </goals>
            </execution>
        </executions>
         </plugin>
      </plugins>
    </build>
</profile>

This should do the trick. You can run this profile using maven : mvn glassfish:deploy -P production or just mvn deploy -P production (since we have added the goal deploy inside the executions part of plugin)

Using the model above you can create different profile per environment (dev, acc, tst, prd), and use different settings. For instance you can create a developer profile where a local glassfish is being used to deploy and run unit/integration tests on it.

Common mistake people make is to mix up the settings for the machine from where you are doing the remote deployment with the host where deployment is to be installed. glassfishDirectory is place from where you are running the deployment plugin from. As a result of mistake plugin just hangs, doing nothing and just waiting giving the impression that something is happening. Another mistake is to specify a password file instead of a password for a remote deploy which will also result in nothing.

这篇关于GlassFish 3 + Maven +远程部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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