简体   繁体   中英

How to add and use a jar library in IntelliJ IDEA?

I created a new Java app from scratch in IntelliJ IDEA. Now I want to use a jar library, eg OpenJPA. I added the library using Project Structure -> Libraries like this:

在此处输入图片说明

then I tried to use annotations from that library in my Java code, but I don't get the option to import these classes. It looks like IntelliJ IDEA is not known about my library yet:

在此处输入图片说明

What am I doing wrong when adding this library? Is there anything more that I have to do to get it working?


After adding this library, it looks like it is automatically added to "Modules":

在此处输入图片说明

You have created a library, but you haven't said IntelliJ that the module must use it. Click *Modulesµ in the project structure, then select the module you want to add this library to, go to the Dependencies tab, and add the library.

EDIT:

It's simply that the annotation is not part of the jar. You need to add the jpa api jar, not only openjpa.jar

您必须将库添加到模块依赖项,请在此处检查: 配置模块依赖项和库

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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