【问题标题】:Problems in dependencies using maven with ecplise使用 Maven 和 Eclipse 的依赖关系问题
【发布时间】:2016-06-14 09:04:54
【问题描述】:

我对 Maven 了解不多,只知道基础知识,这给我带来了一些问题。

我正在使用 Ecplise Luna 和 maven(嵌入式版本 3.2.1 / 1.5.1.50109-1819)来管理我的项目。还安装了 JBoss Tools 插件以将我的项目发送到 OpenShift。到目前为止一切顺利。

但是,我在 OpenShift 中遇到了一些错误,在论坛中研究发现问题与 mysql-connector-java 的 5.0.8 版本有关。所以我从我的maven项目中进入pom.xml文件并将mysql-connector-java 5.0.8的版本更改为5.1.38,保存了pom,理论上我的maven应该下载新版本(5.1.38)mysql的版本-connector-java 并删除旧的(5.0.8),对吗? 好吧,如果那是应该发生的事情,那不是正在发生的事情。我找不到任何错误,但在我的 lib 文件夹中只有 5.0.8 版本的 mysql-connector-java。

奇怪的是,当我进行全新安装构建时成功生成,并生成了 MyApp-0.0.1-SNAPSHOT / WEB-INF / lib mysql-connector-java-5.0.8-bin.jar 文件和 mysql-connector -java-5.1.38.jar.

为什么会这样?据我所知,maven不应该将5.0.8版本替换为5.1.38,因为我在pom.xml中更改了版本?

知道发生了什么吗?

我的 pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
<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>
  <groupId>Picos</groupId>
  <artifactId>Picos</artifactId>
  <version>0.0.2-SNAPSHOT</version>
  <packaging>war</packaging>
  <dependencies>
    <dependency>
      <groupId>javax.faces</groupId>
      <artifactId>javax.faces-api</artifactId>
      <version>2.2</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.primefaces</groupId>
      <artifactId>primefaces</artifactId>
      <version>5.2</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.primefaces.themes</groupId>
      <artifactId>all-themes</artifactId>
      <version>1.0.10</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <version>4.3.6.Final</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-validator</artifactId>
      <version>5.2.1.Final</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.38</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>2.3.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>2.4</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>commons-codec</groupId>
      <artifactId>commons-codec</artifactId>
      <version>1.10</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
      <version>1.3.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.core</groupId>
      <artifactId>jersey-client</artifactId>
      <version>2.21</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.core</groupId>
      <artifactId>jersey-server</artifactId>
      <version>2.21</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.media</groupId>
      <artifactId>jersey-media-multipart</artifactId>
      <version>2.21</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>
          <artifactId>mimepull</artifactId>
          <groupId>org.jvnet.mimepull</groupId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.jvnet.mimepull</groupId>
      <artifactId>mimepull</artifactId>
      <version>1.9.6</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.containers</groupId>
      <artifactId>jersey-container-servlet-core</artifactId>
      <version>2.21</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-core-asl</artifactId>
      <version>1.9.13</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>com.ganyo</groupId>
      <artifactId>gcm-server</artifactId>
      <version>1.0.2</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpclient</artifactId>
      <version>4.5.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>javax.enterprise</groupId>
      <artifactId>cdi-api</artifactId>
      <version>1.2</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
  <repositories>
    <repository>
      <id>prime-repo</id>
      <name>PrimeFaces Maven Repository</name>
      <url>http://repository.primefaces.org</url>
    </repository>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>http://repo.maven.apache.org/maven2</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>http://repo.maven.apache.org/maven2</url>
    </pluginRepository>
  </pluginRepositories>
  <build>
    <sourceDirectory>D:\Meus documentos\Projetos\Thiago\app Picos\Workspace\Picos\src</sourceDirectory>
    <scriptSourceDirectory>D:\Meus documentos\Projetos\Thiago\app Picos\Workspace\Picos\src\main\scripts</scriptSourceDirectory>
    <testSourceDirectory>D:\Meus documentos\Projetos\Thiago\app Picos\Workspace\Picos\src\test\java</testSourceDirectory>
    <outputDirectory>D:\Meus documentos\Projetos\Thiago\app Picos\Workspace\Picos\target\classes</outputDirectory>
    <testOutputDirectory>D:\Meus documentos\Projetos\Thiago\app Picos\Workspace\Picos\target\test-classes</testOutputDirectory>
    <resources>
      <resource>
        <directory>D:\Meus documentos\Projetos\Thiago\app Picos\Workspace\Picos\src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>D:\Meus documentos\Projetos\Thiago\app Picos\Workspace\Picos\src\test\resources</directory>
      </testResource>
    </testResources>
    <directory>D:\Meus documentos\Projetos\Thiago\app Picos\Workspace\Picos\target</directory>
    <finalName>Picos-0.0.2-SNAPSHOT</finalName>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.2-beta-5</version>
        </plugin>
        <plugin>
          <artifactId>maven-dependency-plugin</artifactId>
          <version>2.8</version>
        </plugin>
        <plugin>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.3.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <executions>
          <execution>
            <id>default-compile</id>
            <phase>compile</phase>
            <goals>
              <goal>compile</goal>
            </goals>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
            </configuration>
          </execution>
          <execution>
            <id>default-testCompile</id>
            <phase>test-compile</phase>
            <goals>
              <goal>testCompile</goal>
            </goals>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.4</version>
        <executions>
          <execution>
            <id>default-war</id>
            <phase>package</phase>
            <goals>
              <goal>war</goal>
            </goals>
            <configuration>
              <warSourceDirectory>WebContent</warSourceDirectory>
              <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>2.5</version>
        <executions>
          <execution>
            <id>default-clean</id>
            <phase>clean</phase>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
        <executions>
          <execution>
            <id>default-testResources</id>
            <phase>process-test-resources</phase>
            <goals>
              <goal>testResources</goal>
            </goals>
          </execution>
          <execution>
            <id>default-resources</id>
            <phase>process-resources</phase>
            <goals>
              <goal>resources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12.4</version>
        <executions>
          <execution>
            <id>default-test</id>
            <phase>test</phase>
            <goals>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-install-plugin</artifactId>
        <version>2.4</version>
        <executions>
          <execution>
            <id>default-install</id>
            <phase>install</phase>
            <goals>
              <goal>install</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.7</version>
        <executions>
          <execution>
            <id>default-deploy</id>
            <phase>deploy</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-site-plugin</artifactId>
        <version>3.3</version>
        <executions>
          <execution>
            <id>default-site</id>
            <phase>site</phase>
            <goals>
              <goal>site</goal>
            </goals>
            <configuration>
              <outputDirectory>D:\Meus documentos\Projetos\Thiago\app Picos\Workspace\Picos\target\site</outputDirectory>
              <reportPlugins>
                <reportPlugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-project-info-reports-plugin</artifactId>
                </reportPlugin>
              </reportPlugins>
            </configuration>
          </execution>
          <execution>
            <id>default-deploy</id>
            <phase>site-deploy</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
            <configuration>
              <outputDirectory>D:\Meus documentos\Projetos\Thiago\app Picos\Workspace\Picos\target\site</outputDirectory>
              <reportPlugins>
                <reportPlugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-project-info-reports-plugin</artifactId>
                </reportPlugin>
              </reportPlugins>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <outputDirectory>D:\Meus documentos\Projetos\Thiago\app Picos\Workspace\Picos\target\site</outputDirectory>
          <reportPlugins>
            <reportPlugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-project-info-reports-plugin</artifactId>
            </reportPlugin>
          </reportPlugins>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <reporting>
    <outputDirectory>D:\Meus documentos\Projetos\Thiago\app Picos\Workspace\Picos\target\site</outputDirectory>
  </reporting>
  <profiles>
    <profile>
      <id>openshift</id>
      <build>
        <finalName>Picos</finalName>
        <plugins>
          <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
            <configuration>
              <outputDirectory>webapps</outputDirectory>
              <warName>ROOT</warName>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>

【问题讨论】:

  • 我不确定我是否理解。你能发布你的 POM 吗?
  • 在那里。看看我的编辑
  • 不要使用嵌入式 maven。将其安装在您的机器上并在 eclipse 上进行配置。更改依赖项也不会删除旧的依赖项。 Maven 只会更新对您项目的引用。嵌入式版本有很多问题。我的意思是,没有基于社区发布的任何帖子或错误的经验,因为它被错误了,我总是使用外部版本,它总是能正常工作。
  • 我尝试从教程中安装外部 Maven,但是当我去构建时得到这个错误 构建过程中发生错误。在项目“peaks”上运行构建器“Maven Project Builder”时出错。无法计算构建计划:插件 org.apache.maven.plugins:maven-resources-plugin:2.6 或其依赖项之一无法解决:无法读取工件描述符是 org.apache.maven.plugins:maven-Resources-插件:jar:2.6
  • 这可能不是您的问题,因为您的 `D:\Meus documentos\Projetos\Thiago\app Picos\Workspace\Picos` 是很好的做法。请记住,Maven 中的所有内容都是相对于 basedir 的,即 POM 的位置。所以你实际上可以完全放弃它。

标签: maven maven-plugin m2eclipse


【解决方案1】:

Maven 不会将依赖项导入到 Eclipse 项目的“lib”文件夹中。相反,它将被下载到本地 maven 存储库(位于 USER_HOME/.m2/repository)。构建项目后,maven 将复制项目“lib”文件夹的所有内容,并另外包含本地存储库中引用的 jar。

我怀疑您将旧版本保存在“lib”文件夹中,这就是您最终同时使用两个版本的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-08
    • 1970-01-01
    • 2019-12-14
    • 2012-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多