How to use a “custom jar” in IntelliJ IDEA?

懵懂的女人 提交于 2019-12-12 16:25:04

问题


I'm trying to set up IntelliJ IDEA -- tried 12 and 13 -- Mac to use a Java class included a jar file for my Java application.

I've set the jar as a module dependency by the following procedure

  • Start from the "project window";
  • Select my main Java module;
  • Use menu File | Project Structure;
  • In Project Settings, select Modules, and select my Java application as interested module in the middle window;
  • On the window to the right, select "Dependencies" tab, and press "+" and select "Jars or directories" and navigate to the jar file, add select it so the custom jar file is added as a new entry in the window, check the Export checkbox and set Scope pulldown set as "Compile";
  • Press OK.

However, after setting this, in a Java class file in my Java application, if I use a class defined in the custom jar file, it still prompts me "Cannot resolve symbol 'SomeClass'".

Any idea what I'm doing wrong and how to fix this?

Edit:

my settings:

BTW, the Libraries and Global libraries are both empty. I tried to set the two jars there (separately) and add them as dependencies for the Java app, and had no luck, so I deleted them from Libraries and Global libraries. The above setting is using add module dependency as files directly (without first registering them as libraries), which still does not work.


回答1:


Putting everything in the default unnamed package solved the issue.



来源:https://stackoverflow.com/questions/22671848/how-to-use-a-custom-jar-in-intellij-idea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!