2016-09-28 157 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