2016-09-28 442 views
0

美好的一天。Maven。部署到玻璃鱼模块

我使用'mvn clear package glassfish:deploy'从cmd进行部署。只包含项目的应用程序可以使用。但有了子模块,我在部署时遇到了一些麻烦。

这个命令给了我这个错误:

[错误]远程故障:未找到文件:[点击这里项目路径] \目标\ test2.war

[错误]的部署[在此项目路径] \ target \ test2.war失败

如何解决这个问题?

家长的pom.xml:

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

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

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

回答

0

问题是与下面的代码在你父母的pom.xml

<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的文件部署到字符串“test2.war”,因为${project.build.finalName}.war。但test2.war不在目标目录中。目标目录中存在的文件是test2.pom。因此你得到错误。
可以有两种部署工件的方法。

第一种方法:如果您想从父模块内部署子模块,那么您需要在父pom中为glashfish插件提供以下代码。

<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的插件。
用下面显示的替换您的孩子poms中的maven glassfish插件代码。
对于child1的pom.xml:

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

<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

谢谢你的回答。但是对于使用第二种方法进行部署的命令,应该为每个孩子分别执行?在父pom中执行它的原因我有错误,'玻璃鱼'是不正确的前缀 – Evgeniy175

+0

对于第二种方法,您不必指定部署命令。尝试在父级别使用命令'mvn clean install'。这是因为部署相关的东西将由您的poms中的插件代码照顾。另外,您不必为每个模块单独使用deploy命令。你的父母pom会一个一个地触发孩子poms,这会部署孩子的文物。尝试上面的命令,让我知道。 –

+0

它已成功编译,子模块现在包含文件夹“目标”。但没有部署到glassfish – Evgeniy175

0

尝试移动下构建了GlassFish,Maven的插件 - > pluginManagement你父POM下:

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

内。然后每个子多金属氧酸盐,添加此插件调用:

<plugins> 
    <plugin> 
    <groupId>org.glassfish.maven.plugin</groupId> 
    <artifactId>maven-glassfish-plugin</artifactId> 
    </plugin> 
</plugins> 
+0

再次,找不到文件错误 – Evgeniy175