Home >Java >javaTutorial >How to Add a Directory to the Classpath for Application Runtime Configuration in IntelliJ IDEA?

How to Add a Directory to the Classpath for Application Runtime Configuration in IntelliJ IDEA?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-08 04:41:02563browse

How to Add a Directory to the Classpath for Application Runtime Configuration in IntelliJ IDEA?

How to Incorporate a Directory into the Classpath for an Application Runtime Configuration in IntelliJ IDEA?

Many developers encounter the need to add a directory to the classpath of an application run profile in IntelliJ IDEA. However, attempting to override this setting using "-cp x:target/classes" in the VM preferences often results in a "java.lang.NoClassDefFoundError: com/intellij/rt/execution/application/AppMain" error.

Solution:

To resolve this issue and successfully add a directory to the classpath for your project in IntelliJ IDEA 13 or later, follow these steps:

  1. Initiate the Project view by clicking on "1: Project" on the left side of the interface, or use the keyboard shortcut Alt 1.
  2. Highlight your project or its submodule by clicking on it. Then, press F4, or right-click and select "Open Module Settings" (F12 in IntelliJ 14).
  3. Navigate to the "Dependencies" tab.
  4. Click the " " button on the right and choose "Jars or directories..."
  5. Select the desired path and click "OK."
  6. In the subsequent "Choose Categories of Selected File" dialog, choose "Classes" (even for properties), and press "OK" twice.

By completing these steps, you have successfully incorporated the specified path into the classpath of your project. When running your application, it will now have access to the selected directory.

The above is the detailed content of How to Add a Directory to the Classpath for Application Runtime Configuration in IntelliJ IDEA?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn