简体   繁体   English

尽管战争子项目包含最新的jar版本,为什么Maven耳包仍使用项目的旧jar版本?

[英]Why Maven ear package uses project's old jar version despite war subprojects contains latest jar version?

I have a maven project with 4 subprojects, let's say the following structure: 我有一个带有4个子项目的Maven项目,让我们说以下结构:

  Main 
   |- core (jar)
   |- webapp1 (war)
   |- webapp2 (war)
   |- webapp3 (war)

The three webapp subprojects depends on core subproproject. 这三个webapp子项目取决于核心子项目。 So the poms are like: 所以poms就像:

Main (pom.xml): 主要(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>myGroup</groupId>
  <artifactId>MyArtifact</artifactId>
  <version>1.0</version>
  <packaging>pom</packaging>

  <properties>
  </properties>

  <repositories>
  </repositories>

  <modules>
    <module>core</module>
    <module>webapp1</module>
    <module>webapp2</module>
    <module>webapp3</module>
  </modules> 
   ...
</project>

Core (pom.xml): 核心(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>
  <artifactId>core</artifactId>
  <packaging>jar</packaging>
  <parent>
    <groupId>MyGroup</groupId>
    <artifactId>MyArtifact</artifactId>
    <version>1.0</version>
  </parent>
...
</project>

And web app poms are like this: 和网络应用程序poms是这样的:

<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>
  <artifactId>webapp1</artifactId>
  <version>1.1.0-A1</version>
  <packaging>war</packaging>
  <parent>
    <groupId>MyGroup</groupId>
    <artifactId>MyArtifact</artifactId>
    <version>1.0</version>
  </parent>
<dependencies>
  <dependency>
    <groupId>MyGroup</groupId>
    <artifactId>core</artifactId>
    <version>1.0</version>
  </dependency>
 </dependencies>
  ...
</project>

Everything worked fine during months when i execute 'mvn package' on the project's root folder and deploy the wars being generated. 在我在项目的根文件夹上执行“ mvn软件包”并部署正在产生的战争的几个月中,一切工作正常。

But now i want to deploy an Ear instead of separate War files so i added a subproject called earproject. 但是现在我想部署一个Ear而不是单独的War文件,所以我添加了一个名为earproject的子项目。 With the following pom.xml: 使用以下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>
  <artifactId>earproject</artifactId>
  <packaging>ear</packaging>
  <parent>
    <groupId>MyGroup</groupId>
    <artifactId>MyArtifact</artifactId>
    <version>1.0</version>
  </parent>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-ear-plugin</artifactId>
          <version>2.10.1</version>
          <configuration>
              <finalName>EarName</finalName>
              <version>5</version>
              <generatedDescriptorLocation>${basedir}/src/main/applicatio/META-INF</generatedDescriptorLocation>
          <modules>
              <webModule>
                  <groupId>MyGroup</groupId>
                  <artifactId>webapp1</artifactId>
                  <bundleFileName>webapp1.war</bundleFileName>
                  <contextRoot>/webapp1</contextRoot>
              </webModule>
              <webModule>
                  <groupId>MyGroup</groupId>
                  <artifactId>webapp2</artifactId>
                  <bundleFileName>webapp2.war</bundleFileName>
                  <contextRoot>/webapp2</contextRoot>
              </webModule>
              <webModule>
                  <groupId>MyGroup</groupId>
                  <artifactId>webapp3</artifactId>
                  <bundleFileName>webapp3.war</bundleFileName>
                  <contextRoot>/webapp3</contextRoot>
              </webModule>
          </modules>
        </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
  <dependencies>
    <dependency>
      <groupId>MyGroup</groupId>
      <artifactId>core</artifactId>
      <version>1.0</version>
    </dependency>
    <dependency>
      <groupId>MyGroup</groupId>
      <artifactId>webapp1</artifactId>
      <type>war</type>
      <version>1.0</version>
    </dependency>
    <dependency>
      <groupId>MyGroup</groupId>
      <artifactId>webapp2</artifactId>
      <type>war</type>
      <version>1.0</version>
    </dependency>
    <dependency>
      <groupId>MyGroup</groupId>
      <artifactId>webapp3</artifactId>
      <type>war</type>
      <version>1.0</version>
    </dependency>
  </dependencies>
</project>

Whith this configuration when i run 'mvn clean' and 'mvn package' the ear file is generated but the war files inside the ear file contains an invalid old version of the core.jar. 当我运行'mvn clean'和'mvn package'时,如果使用此配置,则会生成耳文件,但是耳文件中的war文件包含无效的旧版本的core.jar。 If i check target directories on webapp projects the War files has a right core.jar version. 如果我在webapp项目上检查目标目录,则War文件具有正确的core.jar版本。 It seems like EAR packaging uses an old version of the jar that is in my mvn repository, but i don't know why, because on the separate war files maven puts the recently created core.jar. 似乎EAR打包使用了我的mvn存储库中的jar的旧版本,但我不知道为什么,因为maven在单独的war文件中放置了最近创建的core.jar。

Why is this happening? 为什么会这样呢? Do i need to specify anything more on earproject's pom.xml? 我需要在earproject的pom.xml中指定更多内容吗?

I think the problem you are describing can be solved easily. 我认为您所描述的问题可以轻松解决。 In appearance Maven ear plugin is getting the core jar file from the repository instead of the new compiled one. 在外观上,Maven耳朵插件将从存储库中获取核心jar文件,而不是从新编译的jar文件中获取。 I don't know the reason of this plugin's behaviour but I found this issue long time ago. 我不知道此插件行为的原因,但很久以前我发现了这个问题。

You should install your jar libraries in the local repository by using the following command 您应该使用以下命令将jar库安装在本地存储库中

mvn clean install

instead of 代替

mvn package

which only generates the artifacts 只会产生伪像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM