【问题标题】:Eclipse not being able to find pom.xml locationEclipse 无法找到 pom.xml 位置
【发布时间】:2015-12-01 11:25:47
【问题描述】:

我有一个现有的maven 项目,我计划使用WebLogic 服务器进行部署。因为我需要一个ear 文件,所以我按照步骤创建一个jar module 和一个war 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>

以下是为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>

【问题讨论】:

  • 你的 pom.xml 看起来像什么?并且存放在哪里?在找到 pom 并且可以将其解析为 xml 之前,您选择哪种包类型并不重要。我建议从一个简单的例子开始。
  • 我已经发布了parent projects pom。请检查我的编辑,让我知道你的想法。而pom 位于parent directory
  • 请同时从 JARModule 发布您的 pom。根据您的错误消息,无法读取 pom。在与您的父级相同的文件夹中,您需要一个名为 Project_nameJARModule 的目录,其中包含一个 pom.xml。就像奥雷连说的。是这样吗?
  • 为我创建的JAR and WAR 模块发布了pom。他们都给出了同样的错误。是的,错误确实表明pom 不可访问,是不是因为我可能以错误的方式创建了模块?又因为它们不在parent project之下,而是作为不同的模块,在包资源管理器中?

标签: java eclipse maven pom.xml


【解决方案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>

否则,如果你没有定义特定的&lt;relativePath&gt;,上面的树结构是默认的

【讨论】:

  • 你的意思是说JAR,WAR,EAR modules 应该在同一个工作区,对吧?
  • 感谢您的帮助! :)
【解决方案2】:

我有一个可与 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>

【讨论】:

  • 您的module-war,module-jar,module-ear 文件在parent-module 内吗?如果是这样,那么没有。我的warjarear 在父项目之外。 (父项目是我右键单击并创建模块的项目)。
  • 感谢您的帮助! :)
【解决方案3】:

因此,经过一番折腾,我决定切换一次我的工作区并检查一下。和ta-daa。就是这样。问题解决了。 Eclipse 出于某种原因在我当时拥有的工作区中行为不端。我创建了一个更新的工作区并尝试了同样的事情,一切都很顺利。希望这可以帮助。 :)

【讨论】:

  • 将工作区切换到未使用的工作区并切换回原来的工作区对我来说已经足够了。我不需要制作一个新的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-11-23
  • 2023-04-08
  • 2019-10-11
  • 1970-01-01
  • 1970-01-01
  • 2012-09-19
  • 2016-09-09
相关资源
最近更新 更多