如何使用“自定义jar”在IntelliJ IDEA? [英] How to use a "custom jar" in IntelliJ IDEA?

查看:904
本文介绍了如何使用“自定义jar”在IntelliJ IDEA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图设置IntelliJ IDEA - 尝试12和13 - Mac使用Java类包括我的Java应用程序的jar文件。

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.

我已通过以下过程将jar设置为模块依赖

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


  • 从项目窗口开始;

  • 选择我的主要Java模块;

  • 项目结构;

  • 在项目设置中,选择模块,然后在中间窗口中选择我的Java应用程序作为感兴趣的模块;

  • 右键,选择依赖关系选项卡,然后按+并选择Jars或目录并导航到jar文件,添加选择它以使自定义jar文件作为新条目添加到窗口中,检查导出复选框和将范围下拉菜单设置为编译;

  • 按确定。

  • 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.

这在我的Java应用程序中的Java类文件中,如果我使用在自定义jar文件中定义的类,它仍然提示我无法解析符号'SomeClass'。

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?

编辑:

>

>

BTW,库和全局库都是空的。我试图设置两个jar在那里(单独),并将它们添加为Java应用程序的依赖项,没有运气,所以我从Libraries和全局库中删除它们。上面的设置是直接使用添加模块依赖作为文件(没有先将它们注册为库),这仍然不起作用。

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.

推荐答案

将所有内容放在默认的未命名包中解决了问题。

Putting everything in the default unnamed package solved the issue.

这篇关于如何使用“自定义jar”在IntelliJ IDEA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆