繁体   English   中英

导入javax.persistence在我的第一个Maven Hibernate项目中无法解决

[英]import javax.persistence couldn't be resolved in my first Maven Hibernate Project

我已经阅读了一个月的书籍和文章,然后尝试创建我的第一个Maven项目:)但是开始并不像我预期的那么顺利。 我一直在用各种依赖工件来摆弄我的POM.xml以启用休眠注释,但是似乎没有任何效果。 我总是收到错误,在导入中未解析javax.persistence.Entity或任何其他注释。

<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>FirstHibernateExample</groupId>
      <artifactId>FirstHibernateExample</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <name>FirstHibernateExample</name>
      <description>This is my first project with Hibernate</description>
      <build>
        <sourceDirectory>src</sourceDirectory>
        <resources>
          <resource>
            <directory>src</directory>
            <excludes>
              <exclude>**/*.java</exclude>
            </excludes>
          </resource>
        </resources>
        <plugins>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
            </configuration>
          </plugin>
        </plugins>
      </build>
       <repositories>
        <repository>
          <id>JBoss repository</id>
          <url>http://repository.jboss.com/maven2/</url>
        </repository>
        <repository>
            <id>Java.Net</id>
            <url>http://download.java.net/maven/2/</url>
        </repository>
      </repositories>
      <dependencies>
    <!-- Javaee API -->
<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>6.0</version>
</dependency>
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.31</version>
</dependency> 
<!-- Hibernate core -->
<dependency>
    <groupId>hibernate</groupId>
    <artifactId>hibernate3</artifactId>
    <version>3.2.3.GA</version>
</dependency>

<!-- Hibernate annotation -->
<dependency>
    <groupId>hibernate-annotations</groupId>
    <artifactId>hibernate-annotations</artifactId>
    <version>3.3.0.GA</version>
</dependency>

<dependency>
    <groupId>hibernate-commons-annotations</groupId>
    <artifactId>hibernate-commons-annotations</artifactId>
    <version>3.0.0.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>

有人可以指出我错了吗,或者应该怎么做才能使我的第一个项目运行? 提前非常感谢:)

最后,以下命令解决了该问题。 mvn eclipse:eclipse -DdownloadSource = true

我是从下面的链接http://w3facility.org/question/javax-persistence-sources-where/找到的

希望它将对以后的人有所帮助:)

编辑:在另一个项目中,我只需右键单击错误导入语句,然后单击修复项目设置。 它建议我在M2_REPO中将buildpath添加到javaee-api6.0.jar中,从而解决了该问题。

暂无
暂无

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

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