How to add directory to classpath in an application run profile in IntelliJ IDEA?
If I override by using -cp x:target/classes in the VM settings, I get the following error:
Any idea on how to add a directory to the classpath for my project?
![]()
![]()
8 Answers 8
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.
Module dependencies
Modules can depend on SDKs, JAR files (libraries) or other modules within a project. When you compile or run your code, the list of module dependencies is used to form the classpath for the compiler or the JVM.
This information is valid for projects that are built with the native IntelliJ IDEA builder. If you’re using a build tool, such as Maven or Gradle, make all changes using the build file.
Add a new dependency
From the main menu, select File | Project Structure Ctrl+Alt+Shift+S and click Modules | Dependencies .
Click Alt+Insert and select a dependency type:
JARs or directories : select a Java archive or a directory from files on your computer.
Library : select an existing library or create a new one and then add it to the list of dependencies.
Module Dependency : select another module in the project.
Remove a dependency
Before removing a dependency, make sure that it is not used in other modules in the project. To do so, select the necessary dependency and press Alt+F7 . You can also use the Find Usages option of the context menu.
Select the dependency that you want to remove and click or press Alt+Delete .
Analyze dependencies
If you want to check whether a dependency still exists in your project, and find its exact usages, you can run dependency analysis:
From the main menu, select File | Project Structure Ctrl+Alt+Shift+S and click Modules | Dependencies .
Right-click the necessary dependency and select Analyze This Dependency .
You can analyze several dependencies one by one without closing the dialog. The result of each analysis will be opened in a separate tab of the Dependency Viewer tool window. After you analyze all necessary dependencies, you can close the Project Structure dialog and view the results.
If IntelliJ IDEA finds no dependency usages in the project, you will be prompted to remove this dependency.

Configure a dependency scope
Specify a dependency scope
Specifying a dependency scope allows you to control at which step of the build the dependency should be used. The classpath may be different when your sources are compiled, your test sources are compiled, your compiled sources are run, your tests are run.
From the main menu, select File | Project Structure Ctrl+Alt+Shift+S and click Modules | Dependencies .
Select the necessary scope from the list in the Scope column:
Compile : required to build, test, and run a project (the default scope).
Test : required to compile and run unit tests.
Runtime : included in the classpath for your sources and test sources but only at the run phase.
Provided : used for building and testing a project.
The Export option lets you control the compilation classpath for the modules that depend on this one: the marked items will be included in the compilation classpath of the dependent module.
IntelliJ IDEA processes dependencies for test sources differently from other build tools (for example, Gradle and Maven).
If your module (say, module A) depends on another module (module B), IntelliJ IDEA assumes that the test sources in A depend not only on the sources in B but also on its own test sources. Consequently, the test sources of B are also included in the corresponding classpaths.
The following table summarizes the classpath information for the possible dependency scopes.
Как добавить каталог в classpath в профиле запуска приложения в IntelliJ IDEA?
если я переопределяю с помощью -cp x:target/classes в настройках виртуальной машины я получаю следующую ошибку:
есть идеи о том, как добавить каталог в путь к классам для моего проекта?
5 ответов
в Intellij 13 это выглядит немного по-другому. Вот инструкции для Intellij 13:
- нажмите на вид проекта или отобразить его, нажав на кнопку «1: проект» на левой границе окна или нажав Alt + 1
- найдите свой проект или суб-модуль и нажмите на него, чтобы выделить его, затем нажмите F4 или щелкните правой кнопкой мыши и выберите «Открыть Настройки модуля» (на IntelliJ 14 он стал F12)
- нажмите на зависимости tab
- Нажмите кнопку «+» справа и выберите «банки и каталоги. «
- найдите свой путь и нажмите OK
- в диалоговом окне «Выбор категорий выбранного файла» выберите Classes (даже если это свойства), нажмите OK и OK еще раз
- теперь вы можете запустить приложение, и оно будет иметь выбранный путь в пути класса
похоже, что IntelliJ 11 изменил метод, и проверенный ответ больше не работает для меня. Если кто-то еще прибывает сюда через поисковую систему, вот как я решил это в IntelliJ 11:
- перейдите в структуру проекта, щелкните по модулям и нажмите на Модуль
- выберите вкладку «зависимости»
- Нажмите кнопку » + «с правой стороны и выберите» банки или каталоги. «
- Добавить папку(ы) вы хотите (Примечание вы можете выбрать несколько) и нажмите OK
- в появившемся диалоговом окне выберите «классы», а не»каталог jar»
- убедитесь, что вы используете этот модуль в запустить элемент
обратите внимание, что Шаг 5, похоже, является ключевым отличием. Если вы выберете «каталог jar», он будет выглядеть точно так же в среде IDE, но не будет включать путь во время выполнения. Кажется, нет способа определить, были ли вы ранее выбраны «классы» или «каталог jar» после факт.
вы можете попробовать — Xbootclasspath / a:path опция запуска приложений java. По описанию он указывает » разделенный двоеточием путь directires, jar-архивов и ZIP-архивов для добавления к пути класса начальной загрузки по умолчанию.»
Я использую идею 8. на вкладке зависимости модуля (в диалоговом окне структура проекта). Добавьте «библиотеку модулей». Там вы можете выбрать каталог Jar для добавления. Затем убедитесь, что профиль run использует Classpath и JDK правильного модуля при его запуске (это находится в диалоговом окне run config.