【问题标题】:Maven did not download libs (netbeans)Maven 没有下载库(netbeans)
【发布时间】:2013-12-25 15:29:34
【问题描述】:

问题是当我描述所有依赖项时,Maven 应该下载所有必要的库。用 eclipse 做的是:mvn eclipse:eclipse。但是 NetBeans 呢?看来 Maven 并没有成功,因为后来我尝试在使用 sessionFactory 的地方编写 HibernateUtil 类,但找不到后者,看起来像这样:

然后我点击在Maven中搜索它,它显示:

那么我怎样才能让我的 Maven 完成它的工作并单独下载所有必要的库?

提前致谢

已编辑:

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>com.hibernate.project</groupId>
    <artifactId>FirstHibernate</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
 
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
 
        <!-- MySQL database driver -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.9</version>
    </dependency>
 
    <!-- Hibernate framework -->
    <dependency>
        <groupId>hibernate</groupId>
        <artifactId>hibernate3</artifactId>
        <version>3.2.3.GA</version>
    </dependency>
 
 
    <!-- Hibernate library dependecy start -->
    <dependency>
        <groupId>dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version>1.6.1</version>
    </dependency>
 
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
    </dependency>
 
    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2.1</version>
    </dependency>
 
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2</version>
    </dependency>
    <!-- Hibernate library dependecy end -->
 
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
    </dependency>
 
  </dependencies>
</project>

【问题讨论】:

    标签: java maven netbeans


    【解决方案1】:

    尝试通过 cmd 在您的项目根目录(项目pom.xml 所在的位置)中运行mvn validate。如果成功,它会将所有依赖项下载到本地存储库中。然后你应该在 netbeans 选项中搜索 maven 存储库配置,并确保将你的本地存储库添加到那里。

    【讨论】:

    • 是的,它成功了(非常快)。它应该显示下载了哪些文件吗?因为它只显示:Building Hibernate 1.0-SNAPSHOT,然后是 SUCCESS。
    • 而且设置repository看起来很简单,但是netbeans 7.3.1在maven选项中没有任何repository路径。我该做什么?我看到我的存储库在我的用户 m2 中。但是如何将其设置为 netbeans?
    • 是的,它应该显示下载文件列表。你能展示你项目的 pom.xml 吗?您可以在 pom.xml 中手动添加对休眠库的依赖。
    • 我添加了文件:pom.xml。而netbean的版本在maven options中没有关于repository的字段..
    • 您的依赖项似乎是正确的,所以我猜库已经下载到您的本地仓库。存储库管理应位于“服务”选项卡中。
    【解决方案2】:

    上面的答案不是解决办法,但是max_yashin回复了一些不错的cmets。因此,此解决方案基于该信息。首先,有用的命令是:mvn compile 在我的项目目录中。它显示有关缺少工件的错误。这些工件是hibernate3。所以,首先我下载了​​hibernate-3.2.3.Ga.jar,然后(Maven 建议我)手动安装这些遗漏的工件。所以我使用了这一行(根据我的参数进行了调整):

    mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
        -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
    

    它显示了成功。当我再次尝试编译 Maven 时,所有错误都没有发生,然后我输入了mvn validate(以防万一),它解决了我的问题。现在我可以在我的项目中使用 Maven。

    【讨论】:

      【解决方案3】:

      我有类似的问题,我尝试使用mvn validate,但它在我的情况下不起作用,但后来我在pom.xml 所在的终端中使用mvn clean install 解决了它

      更多详情:

      https://www.vogella.com/tutorials/ApacheMaven/article.html

      【讨论】:

        猜你喜欢
        • 2021-10-24
        • 2014-02-20
        • 2020-04-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-21
        相关资源
        最近更新 更多