当前位置: 首页 > 知识库问答 >
问题:

使用maven和ecplise的依赖关系问题

艾文斌
2023-03-14

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

我正在使用ecplise Luna和maven(EMBEDDED版本3.2.1/1.5.1.50109-1819)来管理我的项目。还安装了JBoss Tools插件来将我的项目发送到OpenShift。到目前为止还不错。

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

奇怪的是,当我给clean install to build成功生成时,MyApp-0.0.1-SNAPSHOT/WEB-INF/lib生成了mysql-connector-java-5.0.8-bin。jar文件和mysql连接器-java-5.1.38。罐子

为什么会这样?据我所知,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>

共有1个答案

南宫龙野
2023-03-14

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

我怀疑您将旧版本保存在lib文件夹中,这就是为什么您最终使用两个版本。

 类似资料:
  • 问题内容: 我正在运行一个依赖groovy 1.7-beta-1的项目。gmaven插件使用groovy 1.6版作为依赖项。在pom中,我在依赖性管理部分中将grooyv-all版本指定为: 但是,当我在调试模式下运行maven时,我看到groovy 1.6被用于对gmaven插件的依赖。我以为我的依赖项管理部分会重写此设置,因此它们都使用1.7-beta-1,但是由于常规版本不同,我遇到了错误

  • 问题内容: 我有一个依赖关系如下: 当我部署一切正常时,这将拉下另一个引发ClassDefNotFound的依赖项。 我添加了两个依赖项,如下所示: 并且仍然面临着同样的问题,即:MVN带来下来不 我该如何解决? 编辑: 添加; 问题答案: 您可能有一个传递依赖项,另一个依赖项取决于您不需要的版本。 要获得所有直接和传递依赖关系的概述,请尝试: mvn依赖项:树 如果您发现同一依赖项的不同版本之间

  • 我想构建这个项目,以便最终的jar在一个jar文件中包含所有依赖项(如果不可能的话,包括从依赖项到jar文件的类),我遵循了线程Including dependencies in a jar with Maven,但它也包含了我在pom中甚至没有提到的依赖项。这是我的POM,它只有两个依赖项。 我想当Final构建时,它包括pom中提到的特定依赖项(以类或jar形式)

  • 我有一个简单的maven插件,它依赖于父pom文件。父pom文件有十个(10个)第三方jar依赖项,这些依赖项已经使用以下命令安装在我的本地回购中。 类似地,我已经安装了所有其他9个罐子到我的本地回购。这是uber pom.xml文件。 我也尝试使用uber-pom作为一个插件依赖,因为我是绝望的。有什么想法吗?

  • 问题内容: 我正在使用Spring 3和Hibernate 4 JPA。我对 javax.persistence JAR 感到困惑。我在Google上发现了以下两个Maven依赖项。请告诉我以下两个依赖项中需要哪个? 问题答案: 其中的第一个是API Jar,它定义了应用程序应使用的与供应商无关的接口。 第二个是该API的EclipseLink实现。 可以删除对第一个依赖项的引用,而只需使用Ecl

  • 我遇到了一个关于OSGI包和“普通”maven jar依赖关系的问题。 A.M是普通的java应用程序,它启动OSGI框架并加载包。 在项目顶层pom(a.pom)中,我定义了一个commons-logging-1.1.1的依赖项,然后在OSGI包a.x中使用commons-logging。maven-bundle-plugin为a.x生成清单,其中包含一个发生“commons-logging”的