Eclipse无法找到pom.xml位置

时间:2015-12-01 11:25:47

标签: java eclipse maven pom.xml

我有一个现有的maven项目,我计划使用WebLogic Server进行部署。由于我需要一个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(我正确地登上了它并选择创建一个名为projectnameJARprojectnameWAR甚至projectnameEAR的新模块 -

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

以下是为pom模块生成的JAR -

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

pom模块生成WAR -

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

3 个答案:

答案 0 :(得分: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>

parent-module / 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>

答案 1 :(得分:1)

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

,则上面的树结构是默认的

答案 2 :(得分:0)

所以在经过大量的敲击之后,我决定将工作区切换一次并检查。和ta-daa。就是这样。问题解决了。由于某种原因,Eclipse在我当时的工作空间中行为不端。我创建了一个较新的工作区并尝试了同样的事情,一切顺利。希望这可以帮助。 :)