Maven-glassfish-plugin:如何指定部署目標? (Maven-glassfish-plugin: how to specify deploy target?)


問題描述

Maven‑glassfish‑plugin:如何指定部署目標? (Maven‑glassfish‑plugin: how to specify deploy target?)

I'm using Maven 3.0.4 with maven‑glassfish‑plugin 2.1 (http://maven‑glassfish‑plugin.java.net/) and Glassfish 2.1.1.

Relevant POM.XML fragment:

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

The problem is, the Glassfish server I'm deploying onto has one stand‑alone instance per developer configured, and running mvn glassfish:deploy causes:

[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.

Note ‑‑target server in the executed command.

How can I specify in POM which instance (i.e. target) I want to deploy to?

‑‑‑‑‑

參考解法

方法 1:

After some more research, the answer is NO, I CANNOT.

There are two options I'm aware of:

  1. Use exec‑maven‑plugin to call asadmin with desired parameters, or
  2. Fork your own version of maven‑glassfish‑plugin with changes required (that's what I've done as for now).

As it turns out, the plugin is very simple, and I've no problem to modify it to suit my needs. More troublesome was building it, but that's another story.

方法 2:

Hello my solution was this:

I left the pom as a redeploy execution

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

then I modified the asadmin.bat file, and, after the lines where the script is calling the appserver‑cli.jar file I added 3 new lines, notice that redeploy calls an undeploy and a deploy command so the maven glassfish plugin's trick here  is print something when the undeploy command runs (Tihs will confuse the maven plugin as if the undeploy command were success always), but, when the asadmin command is deploy the flow will run normal.

: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

after do this modification reploy is alaways working so great!

(by JerzynaJerzynaJuan Pablo G)

參考文件

  1. Maven‑glassfish‑plugin: how to specify deploy target? (CC BY‑SA 3.0/4.0)

#maven-3 #maven-glassfish-plugin #deployment #glassfish-2.x






相關問題

Maven <include> wildcard cocok dengan nama folder parsial (Maven <include> wildcard match on partial folder name)

Eclipse 中使用 MAVEN 3.04 的動態 Web 應用程序 (Dynamic web application in eclipse using MAVEN 3.04)

Множныя рэпазітары Maven3 (Maven3 multiple repos)

замена ўласцівасці архетыпа maven (maven archetype property substitution)

Maven 發布和版本 Maven 插件 (Maven release and versions maven plugin)

Maven-glassfish-plugin:如何指定部署目標? (Maven-glassfish-plugin: how to specify deploy target?)

在 Maven WAR 構建中添加其他類 (Adding Additional classes in maven WAR build)

分佈式 Jenkins - Linux 上的主控和 Windows 上的從屬 - 如何配置節點特定設置 (Distributed Jenkins- Master on Linux and slave on windows- How to configure node specific setting)

如何觸發Maven SCM插件根據現有目錄自動切換目標? (How to trigger Maven SCM plugin to automatically switch goals based on existing directory?)

使用 MongoDB 存儲數據的 Java 應用程序是否需要 Maven? (Is Maven necessary for a Java application that uses MongoDB to store data?)

“el-api”在 pom.xml 中什麼時候有用? (When is "el-api" useful in pom.xml?)

無法在 JDK7 上運行 Maven 3.6.3 (Can't run Maven 3.6.3 on JDK7)







留言討論