NetBeans 7.2,启动maven spring项目并添加hibernate

时间:2013-01-12 15:17:14

标签: java spring hibernate maven netbeans

我正在尝试将maven作为构建系统迁移,以便对依赖项进行更标准的管理。

这是我要做的步骤和我问的简单(maven新手)问题。这个过程是最直接的,我可以想象,所以这个问题应该很容易重现。

  1. 让我们从File,New Project,Maven,Web Application开始。 在下面的表单中,我保留所有默认值,但是对于我选择“Apache Tomcat 7.0.11.0”的应用程序服务器字段。 我注意到这个向导没有提出任何框架(Sring,Hibernate等),而标准的非maven项目创建向导确实允许包含框架的选择。
  2. 如果我们现在看看这个项目,我们看到的是:

    enter image description here

    所以第一个问题是:为什么春天已经被包括在内,甚至在我明确添加之前呢?

    让我们来看看项目属性:
    enter image description here

    所以没有选择框架。 我想将spring用于它的依赖注入容器(以后我可能会添加spring安全性,但这不是当下的优先事项)。 我是否需要再次添加,因为如上所述,已经包含了一些核心模块?

    1. 在项目属性中,在框架节点中,我添加了Hibernate并选择了数据库连接。依赖关系现在变为如下。

    2. enter image description here

      其中两个(我在屏幕截图中突出显示它们)被标记为“依赖尚未下载。构建项目以纠正错误”(当您将指针移到它们上面时,您可以看到此消息作为提示)。我已经建立了这个项目,但错误仍然存​​在 在maven的输出中,我看到:

      Failed to execute goal on project CreatingMavenSpringProject: Could not resolve dependencies for project com.mycompany:CreatingMavenSpringProject:war:1.0-SNAPSHOT: The following artifacts could not be resolved: javax.sql:jdbc-stdext:jar:2.0, javax.transaction:jta:jar:1.0.1B: Could not find artifact javax.sql:jdbc-stdext:jar:2.0 in unknown-jars-temp-repo (file:C:\Users\agostino\Documents\NetBeansProjects\CreatingMavenSpringProject/lib) -> [Help 1]
      
      To see the full stack trace of the errors, re-run Maven with the -e switch.
      Re-run Maven using the -X switch to enable full debug logging.
      

      我按照它的建议尝试了:

      org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal o
      n project CreatingMavenSpringProject: Could not resolve dependencies for project
       com.mycompany:CreatingMavenSpringProject:war:1.0-SNAPSHOT: The following artifa
      cts could not be resolved: javax.sql:jdbc-stdext:jar:2.0, javax.transaction:jta:
      jar:1.0.1B: Failure to find javax.sql:jdbc-stdext:jar:2.0 in file:C:\Users\agost
      ino\Documents\NetBeansProjects\CreatingMavenSpringProject/lib was cached in the
      local repository, resolution will not be reattempted until the update interval o
      f unknown-jars-temp-repo has elapsed or updates are forced
              at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDe
      pendencies(LifecycleDependencyResolver.java:210)
              at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.resol
      veProjectDependencies(LifecycleDependencyResolver.java:117)
              at org.apache.maven.lifecycle.internal.MojoExecutor.ensureDependenciesAr
      eResolved(MojoExecutor.java:258)
              at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
      .java:201)
              at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
      .java:153)
              at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
      .java:145)
              at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
      ct(LifecycleModuleBuilder.java:84)
              at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
      ct(LifecycleModuleBuilder.java:59)
              at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBu
      ild(LifecycleStarter.java:183)
              at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(Lifecycl
      eStarter.java:161)
              at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
              at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
              at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
              at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
              at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
      cher.java:290)
              at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
      a:230)
              at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
      uncher.java:409)
              at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
      352)
      Caused by: org.apache.maven.project.DependencyResolutionException: Could not res
      olve dependencies for project com.mycompany:CreatingMavenSpringProject:war:1.0-S
      NAPSHOT: The following artifacts could not be resolved: javax.sql:jdbc-stdext:ja
      r:2.0, javax.transaction:jta:jar:1.0.1B: Failure to find javax.sql:jdbc-stdext:j
      ar:2.0 in file:C:\Users\agostino\Documents\NetBeansProjects\CreatingMavenSpringP
      roject/lib was cached in the local repository, resolution will not be reattempte
      d until the update interval of unknown-jars-temp-repo has elapsed or updates are
       forced
              at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(D
      efaultProjectDependenciesResolver.java:189)
              at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDe
      pendencies(LifecycleDependencyResolver.java:185)
              ... 22 more
      Caused by: org.sonatype.aether.resolution.DependencyResolutionException: The fol
      lowing artifacts could not be resolved: javax.sql:jdbc-stdext:jar:2.0, javax.tra
      nsaction:jta:jar:1.0.1B: Failure to find javax.sql:jdbc-stdext:jar:2.0 in file:C
      :\Users\agostino\Documents\NetBeansProjects\CreatingMavenSpringProject/lib was c
      ached in the local repository, resolution will not be reattempted until the upda
      te interval of unknown-jars-temp-repo has elapsed or updates are forced
              at org.sonatype.aether.impl.internal.DefaultRepositorySystem.resolveDepe
      ndencies(DefaultRepositorySystem.java:375)
              at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(D
      efaultProjectDependenciesResolver.java:183)
              ... 23 more
      Caused by: org.sonatype.aether.resolution.ArtifactResolutionException: The follo
      wing artifacts could not be resolved: javax.sql:jdbc-stdext:jar:2.0, javax.trans
      action:jta:jar:1.0.1B: Failure to find javax.sql:jdbc-stdext:jar:2.0 in file:C:\
      Users\agostino\Documents\NetBeansProjects\CreatingMavenSpringProject/lib was cac
      hed in the local repository, resolution will not be reattempted until the update
       interval of unknown-jars-temp-repo has elapsed or updates are forced
              at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolve(Def
      aultArtifactResolver.java:538)
              at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArti
      facts(DefaultArtifactResolver.java:216)
              at org.sonatype.aether.impl.internal.DefaultRepositorySystem.resolveDepe
      ndencies(DefaultRepositorySystem.java:358)
              ... 24 more
      Caused by: org.sonatype.aether.transfer.ArtifactNotFoundException: Failure to fi
      nd javax.sql:jdbc-stdext:jar:2.0 in file:C:\Users\agostino\Documents\NetBeansPro
      jects\CreatingMavenSpringProject/lib was cached in the local repository, resolut
      ion will not be reattempted until the update interval of unknown-jars-temp-repo
      has elapsed or updates are forced
              at org.sonatype.aether.impl.internal.DefaultUpdateCheckManager.newExcept
      ion(DefaultUpdateCheckManager.java:230)
              at org.sonatype.aether.impl.internal.DefaultUpdateCheckManager.checkArti
      fact(DefaultUpdateCheckManager.java:204)
              at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolve(Def
      aultArtifactResolver.java:427)
              ... 26 more
      

      现在我陷入困境,请注意,当您尝试添加hibernate时,这是maven项目的开箱即用行为。如何解决这个问题?

3 个答案:

答案 0 :(得分:3)

使用Tomcat 7.0.27我没有看到第一个问题(Spring依赖项),但我可以复制第二个问题(无法下载depdencies)。检查pom.xml我发现它有错误,例如这种依赖:

<dependency>
    <groupId>unknown.binary</groupId>
    <artifactId>derbyclient</artifactId>
    <version>SNAPSHOT</version>
</dependency>

和此存储库:

<repository>
    <id>unknown-jars-temp-repo</id>
    <name>A temporary repository created by NetBeans for libraries and jars it 
    could not identify. Please replace the dependencies in this repository with 
    correct ones and delete this repository.</name>
    <url>file:${project.basedir}/lib</url>
</repository>

尽管Netbeans wiki页面显示了使用Maven项目选择框架的示例,但我建议您从“Dependencies”节点的“Add dependency ...”选项中添加依赖项。

修改:在其他计算机上重复相同步骤后添加了pom.xml错误。

答案 1 :(得分:3)

您可以通过在存储库部分下添加以下存储库来手动修改POM文件:

<repositories>
   ...
   <repository>
      <id>java.net-m2</id>
      <name>java.net - Maven 2</name>
      <url>https://repository.jboss.org/nexus/content/repositories/java.net-m2</url>
   </repository>
</repositories>

答案 2 :(得分:-1)

您始终可以手动下载依赖项。 例如,您可以下载   - 来自http://download.java.net/maven/2/javax/sql/jdbc-stdext/2.0/jdbc-stdext-2.0.jar的jdbc-stdext-2.0.jar   - 来自http://download.java.net/maven/2/javax/transaction/jta/1.0.1B/jta-1.0.1B.jar

的jta-1.0.1B.jar

然后将jar放在.m2存储库中的正确位置。   - .m2 / repository / javax / sql / jdbc-stdext / 2.0 / jdbc-stdext-2.0.jar   - .m2 / repository / javax / transaction / jta / 1.0.1B / jta-1.0.1B.jar

然后运行maven clean并构建。