【问题标题】:Maven-glassfish-plugin: how to specify deploy target?Maven-glassfish-plugin:如何指定部署目标?
【发布时间】:2013-02-04 12:37:53
【问题描述】:

我将 Maven 3.0.4 与 maven-glassfish-plugin 2.1 (http://maven-glassfish-plugin.java.net/) 和 Glassfish 2.1.1 一起使用。

相关的 POM.XML 片段:

<profile>
        <id>deploy</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.glassfish.maven.plugin</groupId>
                    <artifactId>maven-glassfish-plugin</artifactId>
                    <version>2.1</version>
                    <configuration>
                        <glassfishDirectory>/home/user/glassfish</glassfishDirectory>
                        <domain>
                            <name>domain1</name>
                            <host>hostname</host>
                            <adminPort>4848</adminPort>
                        </domain>
                        <autoCreate>false</autoCreate>
                        <terse>true</terse>
                        <debug>false</debug>
                        <echo>true</echo>
                        <user>admin</user>
                        <passwordFile>/home/user/user.gfpass</passwordFile>
                        <components>
                            <component>
                                <name>${project.artifactId}</name>
                                <artifact>${project.build.directory}/${project.build.finalName}.war</artifact>
                            </component>
                        </components>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

问题是,我部署到的 Glassfish 服务器为每个开发人员配置了一个独立实例,并且运行 mvn glassfish:deploy 导致:

[INFO] --- maven-glassfish-plugin:2.1:deploy (default-cli) @ project ---
[INFO] deploy --port 4848 --enabled=true --host hostanme --precompilejsp=false --verify=false --echo=true --upload=true --terse=true --generatermistubs=false --passwordfile /home/user/user.gfpass --interactive=false --availabilityenabled=false --name project --target server --force=true --user admin /home/user/git/project/target/project-1.0.0-SNAPSHOT.war
[ERROR] CLI171 Command deploy failed : Application project is already deployed on other targets. Please remove all references or specify all targets (if not using asadmin command line) before attempting redeploy operation
[ERROR] Deployment of /home/user/git/project/target/project-1.0.0-SNAPSHOT.war failed.

在执行的命令中注明--target server

如何在 POM 中指定要部署到哪个实例(即target)?

【问题讨论】:

    标签: deployment maven-3 glassfish-2.x maven-glassfish-plugin


    【解决方案1】:

    经过更多研究,答案是不,我不能

    我知道有两种选择:

    1. 使用exec-maven-plugin 调用带有所需参数的asadmin,或
    2. fork 你自己的maven-glassfish-plugin 版本并进行更改 需要(这就是我现在所做的)。

    事实证明,该插件非常简单,我可以根据自己的需要对其进行修改。构建它更麻烦,但这是另一回事。

    【讨论】:

      【解决方案2】:

      您好,我的解决方案是这样的:

      我把 pom 留作重新部署执行

              <execution>
                      <id>gf-deploy</id>
                      <phase>package</phase>
                      <goals>
                          <goal>redeploy</goal>
                      </goals>
                  </execution>
      

      然后我修改了 asadmin.bat 文件,在脚本调用 appserver-cli.jar 文件的行之后,我添加了 3 个新行,请注意 redeploy 调用了一个 undeploy 和一个 deploy 命令,因此 maven glassfish 插件的这里的技巧是在 undeploy 命令运行时打印一些东西(Tihs 会混淆 maven 插件,就好像 undeploy 命令总是成功一样),但是,当 asadmin 命令部署时,流程将正常运行。

      :run
      if NOT %1 == undeploy goto :end
      %JAVA% -jar "%~dp0..\lib\client\appserver-cli.jar" %*
      ECHO "TEST"
      :end
      
      if %1 == undeploy goto :end1
      %JAVA% -jar "%~dp0..\lib\client\appserver-cli.jar" %*
      :end1
      

      在进行此修改后,relay 总是工作得很好!

      【讨论】:

        猜你喜欢
        • 2023-03-31
        • 1970-01-01
        • 1970-01-01
        • 2016-11-26
        • 1970-01-01
        • 2010-12-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多