我试图将一个目录添加到应用程序运行概要文件的类路径

如果在虚拟机设置中使用-cp x:target/classes进行覆盖,会得到以下错误:

java.lang.NoClassDefFoundError: com/intellij/rt/execution/application/AppMain

关于如何将目录添加到我的项目的类路径有任何想法吗?


当前回答

IntelliJ 11似乎改变了方法,选中的答案不再适用于我。以防其他人通过搜索引擎来到这里,下面是我在IntelliJ 11中解决它的方法:

转到项目结构,点击模块,然后点击你的 模块 选择“Dependencies”选项卡 点击右边的“+”按钮,选择“Jars or directories…” 添加您想要的目录(注意您可以多选),然后单击确定 在弹出的对话框中,选择“classes”而不是“jar directory” 确保在运行目标中使用该模块

注意,第5步似乎是关键的区别。如果你选择“jar目录”,它在IDE中看起来完全相同,但在运行时不包括路径。似乎没有办法确定您之前选择的是“类”还是“jar目录”。

其他回答

在Intellij 13中,它看起来又略有不同。以下是Intellij 13的使用说明:

click on the Project view or unhide it by clicking on the "1: Project" button on the left border of the window or by pressing Alt + 1 find your project or sub-module and click on it to highlight it, then press F4, or right click and choose "Open Module Settings" (on IntelliJ 14 it became F12) click on the dependencies tab Click the "+" button on the right and select "Jars or directories..." Find your path and click OK In the dialog with "Choose Categories of Selected File", choose Classes (even if it's properties), press OK and OK again You can now run your application and it will have the selected path in the class path

IntelliJ 11似乎改变了方法,选中的答案不再适用于我。以防其他人通过搜索引擎来到这里,下面是我在IntelliJ 11中解决它的方法:

转到项目结构,点击模块,然后点击你的 模块 选择“Dependencies”选项卡 点击右边的“+”按钮,选择“Jars or directories…” 添加您想要的目录(注意您可以多选),然后单击确定 在弹出的对话框中,选择“classes”而不是“jar directory” 确保在运行目标中使用该模块

注意,第5步似乎是关键的区别。如果你选择“jar目录”,它在IDE中看起来完全相同,但在运行时不包括路径。似乎没有办法确定您之前选择的是“类”还是“jar目录”。

我用的是Idea 8。 在模块依赖项选项卡中(在项目结构对话框中)。添加“模块库”。然后确保运行概要文件在运行时使用正确模块的Classpath和JDK(这是在运行配置对话框中)。

只需检查类的目录/包是否标记为“Sources Root”。我认为在你的情况下,软件包应该是应用程序或执行。

为此,右键单击包,并选择将目录标记为->Sources Root。

您可以尝试java应用程序启动器的-Xbootclasspath/a:path选项。通过描述,它指定了“一个以冒号分隔的目录、JAR存档和ZIP存档的路径,要附加到默认引导类路径中。”