2015-12-01 50 views
1

我有一個現有的maven項目,我打算使用​​服務器進行部署。由於我需要一個ear文件的相同,我正在按照步驟來創建一個jar modulewar module我後來計劃包括在parent module。但是,當我製作jar模塊時,文件夾反映在eclipse的那一刻,我收到有關pom.xml的錯誤。錯誤表示Project build error: Non-readable POM pom.xml /*ProjectName*JARModule line 1 Maven pom Loading Problem。任何想法爲什麼發生這種情況?當我嘗試創建war模塊時也是如此。直到我沒有準備好這兩個模塊,我無法繼續製作一個ear模塊,並且包括這兩個模塊。 非常感謝! **更新 - **這是我parent project pom.xml(在我右cliked並選擇創建一個名爲projectnameJARprojectnameWAR甚至projectnameEAR新的模塊 -Eclipse無法找到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/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>Project_name</groupId> 
<artifactId>Project_name</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>pom</packaging> 
<name>Project_name</name> 
<build> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.5.1</version> 
       <inherited>true</inherited> 
       <configuration> 
        <source>1.7</source> 
        <target>1.7</target> 
       </configuration> 
      </plugin> 
    <plugin> 
     <artifactId>maven-war-plugin</artifactId> 
     <version>2.4</version> 
     <configuration> 
     <warSourceDirectory>WebContent</warSourceDirectory> 
     <failOnMissingWebXml>false</failOnMissingWebXml> 
     </configuration> 
    </plugin> 
    </plugins> 
</build> 
<dependencyManagement> 
     <dependencies> 
      <dependency> 
       <groupId>org.glassfish.jersey</groupId> 
       <artifactId>jersey-bom</artifactId> 
       <version>${jersey.version}</version> 
       <type>pom</type> 
       <scope>import</scope> 
      </dependency> 
      <dependency> 
       <groupId>com.fasterxml.jackson.jaxrs</groupId> 
       <artifactId>jackson-jaxrs-json-provider</artifactId> 
       <version>2.6.0</version> 
     </dependency> 
     <dependency> 
        <groupId>javax</groupId> 
        <artifactId>javaee-web-api</artifactId> 
        <version>7.0</version> <!-- Put here the version of your Java EE app, in my case 7.0 --> 
        <scope>provided</scope> 
      </dependency> 

      <dependency> 
        <groupId>javax.servlet</groupId> 
        <artifactId>javax.servlet-api</artifactId> 
        <version>3.1.0</version> 
        <scope>provided</scope> 
      </dependency> 

      <dependency> 
        <groupId>javax.servlet</groupId> 
        <artifactId>jstl</artifactId> 
        <version>1.2</version> 
      </dependency> 

     <dependency> 
      <groupId>org.glassfish.jersey.containers</groupId> 
      <artifactId>jersey-container-servlet-core</artifactId> 
      <!-- use the following artifactId if you don't need servlet 2.x compatibility --> 
      <!-- artifactId>jersey-container-servlet</artifactId --> 
     </dependency> 

     <dependency> 
      <groupId>org.glassfish.jersey.media</groupId> 
      <artifactId>jersey-media-moxy</artifactId> 
     </dependency> 
     </dependencies> 
    </dependencyManagement> 


    <properties> 
     <jersey.version>2.16</jersey.version> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
    <modules> 
     <module>Project_nameJARModule</module> 
     <module>Project_nameWARModule</module> 
     <module>Project_nameEARModule</module> 
    </modules> 
</project> 

下面是一個是爲JAR模塊所產生的pom -

<?xml version="1.0"?> 
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<modelVersion>4.0.0</modelVersion> 
<parent> 
    <groupId>Project_name</groupId> 
    <artifactId>Project_name</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
</parent> 
<groupId>Project_nameJAR</groupId> 
<artifactId>Project_nameJAR</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<name>CADJAR</name> 
<url>http://maven.apache.org</url> 
<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
</properties> 
<dependencies> 
    <dependency> 
    <groupId>junit</groupId> 
    <artifactId>junit</artifactId> 
    <version>3.8.1</version> 
    <scope>test</scope> 
    </dependency> 
</dependencies> 
</project> 

而對於WAR模塊產生的pom -

<?xml version="1.0"?> 
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<modelVersion>4.0.0</modelVersion> 
<parent> 
    <groupId>Project_name</groupId> 
    <artifactId>Project_name</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
</parent> 
<groupId>Project_nameWAR</groupId> 
<artifactId>Project_nameWAR</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>war</packaging> 
<name>Project_nameWAR Maven Webapp</name> 
<url>http://maven.apache.org</url> 
<dependencies> 
    <dependency> 
    <groupId>junit</groupId> 
    <artifactId>junit</artifactId> 
    <version>3.8.1</version> 
    <scope>test</scope> 
    </dependency> 
</dependencies> 
<build> 
    <finalName>Project_nameWAR</finalName> 
</build> 
</project> 
+0

而你的pom.xml看起來像什麼?並存儲在哪裏?選擇哪種包類型並不重要,直到找到pom並且可以將其解析爲xml。我建議從一個簡單的例子開始。 – Timo

+0

我發佈了「父項目pom」。請檢查我的編輯並讓我知道你的想法。而'pom'位於'父目錄'中。 – TheLuminor

+0

請從JARModule發佈你的pom。根據你的錯誤信息,POM無法讀取。在與您父母相同的文件夾中,您需要一個名爲Project_nameJARModule的dir,其中包含一個pom.xml。像Aurelien說的。是這樣嗎? – Timo

回答

0

所以很多頭撞的身邊後,我決定換我工作區一次並檢查。和ta-daa。就是這樣。問題解決了。 Eclipse出於某種原因在我當時的工作空間中行爲異常。我創建了一個更新的工作空間,並嘗試了相同的事情,並且一切順利。希望這可以幫助。 :)

1

我有一個可以在eclipse和weblogic-10.3.6上工作的多模塊項目。你能確認你有相同的樹狀結構嗎?

parent-module 
|_module-war 
| |_pom.xml 
|_module-jar 
| |_pom.xml 
|_module-ear 
| |_pom.xml 
|_pom.xml 

parent-module/module-ear/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/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>group-module-ear</groupId> 
    <artifactId>module-ear</artifactId> 
    <version>0.0.2</version> 
    <packaging>ear</packaging> 
    <parent> 
     <groupId>group.parent</groupId> 
     <artifactId>parent</artifactId> 
     <version>0.0.1</version> 
    </parent> 
    <dependencies> 
    <dependency> 
     <groupId>group-module-war</groupId> 
     <artifactId>module-war</artifactId> 
     <version>0.0.2</version> 
     <type>war</type> 
    </dependency> 
    <dependency> 
     <groupId>group-module-jar</groupId> 
     <artifactId>module-jar</artifactId> 
     <version>0.0.2</version> 
    </dependency> 
    </dependencies> 
    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-ear-plugin</artifactId> 
     <version>2.10</version> 
     <configuration> 

     <defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>   
      <modules> 
      <webModule> 
       <groupId>group-module-war</groupId> 
       <artifactId>module-war</artifactId> 
       <bundleDir>/</bundleDir> 
      </webModule> 
      <jarModule> 
       <groupId>group-module-jar</groupId> 
       <artifactId>module-jar</artifactId> 
       <bundleDir>/</bundleDir> 
      </jarModule>    
      </modules>   
     </configuration> 
     </plugin> 

    </build> 

</project> 

父模塊/ 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/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>ETIC_J</groupId> 
    <artifactId>ETIC_J</artifactId> 
    <version>0.0.1</version> 
    <packaging>pom</packaging> 

    <properties> 
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
      <artifactory.url>localhost:8080</artifactory.url> 
    </properties> 

    <modules>  
     <module>module-jar</module> 
     <module>module-war</module>   
     <module>metier-etic-ear</module>    
    </modules> 

</project> 
+0

是你的'模塊 - 戰爭','模塊jar','模塊耳'文件在'父模塊'?如果是這樣,那麼不。我的'war','jar'和'ear'在父項目之外。 (父項目是我右鍵單擊並創建模塊的項目)。 – TheLuminor

+0

謝謝你的幫助! :) – TheLuminor

+0

不客氣! :) – Aurelien

1

你的POM的似乎是好了,所以它可能是你的父POM和他的孩子的之間的路徑問題。

parent-module (i.e. your eclipse workspace) 
|_Project_nameJARModule 
| |_pom.xml 
|_Project_nameWARModule 
| |_pom.xml 
|_Project_nameEARodule 
| |_pom.xml 
|_pom.xml 

這與已發佈的@Aurelien樹一樣。 如果你不這樣構造樹,你必須定義父路徑和模塊路徑。

工作原理:

<modules> 
    <module>../path/to/your/child/module/</module> 
</modules> 

<parent> 
    <groupId>com.mycompany.app</groupId> 
    <artifactId>my-app</artifactId> 
    <version>1</version> 

    <!-- define the path to the parent --> 
    <relativePath>../path/pom.xml</relativePath> 
</parent> 

否則樹形的結構上面是默認的,如果你不定義一個特定的<relativePath>

+0

你的意思是說'JAR','WAR','EAR''''模塊'在同一個工作區中,對不對? – TheLuminor

+0

謝謝你的幫助! :) – TheLuminor