简体   繁体   English

为 javax.persistence 编写 Maven 依赖

[英]Writing Maven Dependency for javax.persistence

Can someone help me write the dependency for javax.persistence .有人可以帮我写javax.persistence的依赖项吗? I have googled it but nothing worked.我用谷歌搜索了它,但没有任何效果。

I bumped into this page that gives some details on how to write the dependency, but yet i am unable to write it.碰到了这个页面,它提供了一些关于如何编写依赖项的细节,但我无法编写它。 Can someone help me out?有人可以帮我吗?

This is the one for javax.persistence : 这是javax.persistence的一个:

<dependency>
   <groupId>javax.persistence</groupId>
   <artifactId>persistence-api</artifactId>
   <version>1.0.2</version>
   <scope>provided</scope>
</dependency>

and this is for the whole Java EE 6 stack: 这适用于整个Java EE 6堆栈:

<dependency>
   <groupId>javax</groupId>
   <artifactId>javaee-api</artifactId>
   <version>6.0</version>
   <scope>provided</scope>
</dependency>

Edit 编辑
Note that I specified a provided scope here, which means that your dependency is available at compile- and test-time, but will not be packaged into your artifacts. 请注意,我在此处指定了一个provided范围,这意味着您的依赖项在编译和测试时可用,但不会打包到您的工件中。 This is usually needed if you want to deploy your artifacts in an application server, since they provide their own implementation of the api. 如果要在工具服务器中部署工件,通常需要这样做,因为它们提供了自己的api实现。

And add this dependency in your pom.xml : 并在pom.xml添加此依赖项:

<dependency>
    <groupId>javax.persistence</groupId>
    <artifactId>persistence-api</artifactId>
    <version>1.0.2</version>
</dependency>

That "Coping with Sun JARs" page might be a little outdated, this JAR is available in the Maven Central Repository “处理Sun JARs”页面可能有点过时,这个JAR可以在Maven Central Repository中找到

Updated link: https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api/2.2 is here.更新链接: https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api/2.2在这里。

and the maven dependency is as below:和 maven 依赖如下:

        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>javax.persistence-api</artifactId>
            <version>2.2</version>
        </dependency>

For the latest versions javax.persistance is not working instead of that we can use jakarta.persistence to create an entity or resolve the error Cannot resolve symbol 'Entity' .对于最新版本javax.persistance不起作用,我们可以使用jakarta.persistence来创建实体或解决错误Cannot resolve symbol 'Entity' For that need to add the dependency为此需要添加依赖项

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>6.1.6.Final</version>
            <type>pom</type>
        </dependency>

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

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