首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >马文。使用模块部署到glassfish

马文。使用模块部署到glassfish
EN

Stack Overflow用户
提问于 2016-09-29 00:21:45
回答 2查看 946关注 0票数 0

日安。

我使用cmd中的'mvn clear package glassfish: deploy‘进行部署。对于只包含项目的应用程序来说,这是可以的。但是对于子模块,我在部署时遇到了一些问题。

此命令会给出以下错误:

错误远程失败:找不到文件:此处项目路径\target\test2.war

错误:部署此处项目路径\target\test2.war失败

如何解决这个问题?

父pom.xml:

代码语言:javascript
复制
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>test.net</groupId>
  <artifactId>test2</artifactId>
  <packaging>pom</packaging>
  <version>1.0-SNAPSHOT</version>
  <modules>
    <module>child1</module>
    <module>child2</module>
  </modules>
  <name>test2 Maven Webapp</name>


  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.glassfish.maven.plugin</groupId>
                <artifactId>maven-glassfish-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                <glassfishDirectory>${local.glassfish.home}</glassfishDirectory>
                    <user>admin</user>
                    <passwordFile>${local.glassfish.passfile}</passwordFile>
                    <domain>
                        <name>domain1</name>
                        <httpPort>8080</httpPort>
                        <adminPort>4848</adminPort>
                    </domain>
                    <components>
                        <component>
                            <name>${project.artifactId}</name>
                            <artifact>target/${project.build.finalName}.war</artifact>
                        </component>
                    </components>
                    <debug>true</debug>
                    <terse>false</terse>
                    <echo>true</echo>
                </configuration>
            </plugin>

        </plugins>
        <finalName>test2</finalName>
    </build>

</project>

Child1 pom:

代码语言:javascript
复制
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <parent>
    <artifactId>test2</artifactId>
    <groupId>test.net</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>child1</artifactId>
  <packaging>war</packaging>
  <name>child1 Maven Webapp</name>

  <properties>
    <deploy.glassfish>true</deploy.glassfish>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.glassfish.maven.plugin</groupId>
        <artifactId>maven-glassfish-plugin</artifactId>
      </plugin>
    </plugins>
    <finalName>child1</finalName>
  </build>
</project>

Child2 pom:

代码语言:javascript
复制
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <parent>
    <artifactId>test2</artifactId>
    <groupId>test.net</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>child2</artifactId>
  <packaging>war</packaging>
  <name>child2 Maven Webapp</name>

  <properties>
    <deploy.glassfish>true</deploy.glassfish>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.glassfish.maven.plugin</groupId>
        <artifactId>maven-glassfish-plugin</artifactId>
      </plugin>
    </plugins>
    <finalName>child2</finalName>
  </build>
</project>
EN

回答 2

Stack Overflow用户

发布于 2016-09-29 01:01:33

该问题与父pom.xml中的以下代码有关

代码语言:javascript
复制
<components>
    <component>
       <name>${project.artifactId}</name>
       <artifact>target/${project.build.finalName}.war</artifact>
    </component>
</components>

您的父级pom基本上是在生成一个类型为pom的工件。

<artifact>target/${project.build.finalName}.war</artifact>正在尝试部署一个名为test2.war的文件,因为${project.build.finalName}.war指向字符串"test2.war“。但是test2.war不在目标目录中。目标目录中的文件是test2.pom。因此,你得到了这个错误。

部署工件有两种方法。

第一种方法:如果你想从父模块中部署子模块,那么你需要在你的父pom中拥有glashfish插件的以下代码。

代码语言:javascript
复制
<components>
    <component>
       <artifact>path-to-your-child1-module</artifact>    // something like ../child1/target/child1.war
    </component>
    <component>
       <artifact>path-to-your-child2-module</artifact>    // something like ../child2/target/child2.war
    </component>
</components>

第二种方法(我认为更好)是将你的maven glassfish插件从父模块移到子模块。

用下面显示的代码替换您的孩子pom中的maven glassfish插件代码。

对于child1 pom.xml:

代码语言:javascript
复制
<plugin>
            <groupId>org.glassfish.maven.plugin</groupId>
            <artifactId>maven-glassfish-plugin</artifactId>
            <version>2.1</version>
            <configuration>
            <glassfishDirectory>${local.glassfish.home}</glassfishDirectory>
                <user>admin</user>
                <passwordFile>${local.glassfish.passfile}</passwordFile>
                <domain>
                    <name>domain1</name>
                    <httpPort>8080</httpPort>
                    <adminPort>4848</adminPort>
                </domain>
                <components>
                    <component>
                        <name>${project.artifactId}</name>
                        <artifact>target/${project.build.finalName}.war</artifact>
                    </component>
                </components>
                <debug>true</debug>
                <terse>false</terse>
                <echo>true</echo>
            </configuration>
        </plugin>

    </plugins>
    <finalName>child1</finalName>
</build>

对于子项2 pom.xml:

代码语言:javascript
复制
<plugin>
            <groupId>org.glassfish.maven.plugin</groupId>
            <artifactId>maven-glassfish-plugin</artifactId>
            <version>2.1</version>
            <configuration>
            <glassfishDirectory>${local.glassfish.home}</glassfishDirectory>
                <user>admin</user>
                <passwordFile>${local.glassfish.passfile}</passwordFile>
                <domain>
                    <name>domain1</name>
                    <httpPort>8080</httpPort>
                    <adminPort>4848</adminPort>
                </domain>
                <components>
                    <component>
                        <name>${project.artifactId}</name>
                        <artifact>target/${project.build.finalName}.war</artifact>
                    </component>
                </components>
                <debug>true</debug>
                <terse>false</terse>
                <echo>true</echo>
            </configuration>
        </plugin>

    </plugins>
    <finalName>child2</finalName>
</build>

不要忘记从您的父pom中删除maven glassfish插件代码。

票数 0
EN

Stack Overflow用户

发布于 2016-09-29 02:45:08

尝试将glassfish-maven-plugin移动到父pom下的build -> pluginManagement下:

代码语言:javascript
复制
<pluginManagement>
     <plugins>
        <plugin>
            <groupId>org.glassfish.maven.plugin</groupId>
            <artifactId>maven-glassfish-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <glassfishDirectory>${local.glassfish.home}</glassfishDirectory>
                <user>${local.glassfish.user}</user>
                <passwordFile>${local.glassfish.passfile}</passwordFile>
                <domain>
                    <name>${local.glassfish.domain}</name>
                    <httpPort>${local.glassfish.httpport}</httpPort>
                    <adminPort>${local.glassfish.adminport}</adminPort>
                </domain>
                <components>
                    <component>
                        <name>${project.name}</name>
                        <artifact>target/${project.name}-${project.version}.war</artifact>
                    </component>
                </components>
                <debug>true</debug>
                <terse>false</terse>
                <echo>true</echo>
            </configuration>
        </plugin>
    </plugins>

然后,在每个子pom中,添加这个插件调用:

代码语言:javascript
复制
<plugins>
  <plugin>
    <groupId>org.glassfish.maven.plugin</groupId>
    <artifactId>maven-glassfish-plugin</artifactId>
  </plugin>
</plugins>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39752837

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档