How to add directory to classpath in an application run profile in IntelliJ IDEA?
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
Any idea on how to add a directory to the classpath for my project?
In Intellij 13, it looks it's slightly different again. Here are the instructions for 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
It appears that IntelliJ 11 has changed the method, and the checked answer no longer works for me. In case anyone else arrives here via a search engine, here's how I solved it in IntelliJ 11:
- Go to the Project Structure, click on Modules, and click on your Module
- Choose the "Dependencies" tab
- Click the "+" button on the right-hand side and select "Jars or directories..."
- Add the directory(ies) you want (note you can multi-select) and click OK
- In the dialog that comes up, select "classes" and NOT "jar directory"
- Make sure you're using that Module in your run target
Note that step 5 seems to be the key difference. If you select "jar directory" it will look exactly the same in the IDE but won't include the path at runtime. There appears to be no way to determine whether you've previously selected "classes" or "jar directory" after the fact.
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."
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.