English 中文(简体)
如何在IntelliJ IDEA中的应用程序运行配置文件中将目录添加到类路径?
原标题:
  • 时间:2009-05-12 18:51:03
  •  标签:

I m trying to add a directory to the classpath of an application run profile

If I override by using -cp x:target/classes in the VM settings, I get the following error:

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

如何为我的项目添加一个目录到类路径上有什么想法吗?

最佳回答

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

  1. 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
  2. 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)
  3. click on the dependencies tab
  4. Click the "+" button on the right and select "Jars or directories..."
  5. Find your path and click OK
  6. In the dialog with "Choose Categories of Selected File", choose Classes (even if it s properties), press OK and OK again
  7. You can now run your application and it will have the selected path in the class path
问题回答

看起来 IntelliJ 11 更改了该方法,并且对我来说,已经无法使用已检查的答案。如果有人通过搜索引擎到达这里,请看我是如何在 IntelliJ 11 中解决它的:

  1. Go to the Project Structure, click on Modules, and click on your Module
  2. Choose the "Dependencies" tab
  3. Click the "+" button on the right-hand side and select "Jars or directories..."
  4. Add the directory(ies) you want (note you can multi-select) and click OK
  5. In the dialog that comes up, select "classes" and NOT "jar directory"
  6. Make sure you re using that Module in your run target

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

You can try -Xbootclasspath/a:path option of java application launcher. By description it specifies "a colon-separated path of directires, JAR archives, and ZIP archives to append to the default bootstrap class path."

Set "VM options" like: "-cp $Classpath$;your_classpath"

VM options

I am using Idea 8. in your module dependancies tab (in the project structure dialog). Add a "Module Library". There you can select a Jar Directory to add. Then make sure the run profile is using the Classpath and JDK of the correct module when it runs (this is in the run config dialog.

Simply check that the directory/package of the class is marked as "Sources Root". I believe the package should be application or execution in your case.

要这样做,请右键单击软件包,并选择“标记目录为 ->源根”。

请将此翻译成中文:1 无法翻译,因为这只是一个图片链接,没有文字。

You need not specify the classes folder. Intellij should be able to load it. You will get this error if "Project Compiler output" is blank.

Just make sure that below value is set: Project Settings -> Project -> Project Compiler output to your projectDir/out folder

  • Open Settings
  • Under project Settings, select "project settings (1)"
  • On the left, select "modules"
  • Select the desired module
  • Select the "Sources" tab
  • In the tree structure, find the directory you want to add. Then either add as a source or test source.




相关问题
热门标签