Howto add a directory to the classpath?

Answered

How could I add some directories to the existing classpath of a junit configuration? I cannot at -cp ... to the VM parameters because it will override the existing classpath .

6 comments
Comment actions Permalink

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.

If the directory you want to is not within your project structure, typically you would create a library and attach the jars & classes desired.

0
Comment actions Permalink

First, I'd like to say that the directory (let's call it directory H) I want to add to the classpath doesn't contain any class. Actually, it contains some files like log4j.properties ....

My java files will be compiled and put in a jar file, then this jar file will be run on another machine where there is the directory H already.

If I do like this
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. ]]>
then the jar file will contains my directory H. And that is not what I want. I'm lazy enough to write an Ant script to compile my stuff and put it in a jar file without the directory H (what I usually do is going to the `out' directory of the project, zip everything and rename the zip file to jar and send out the jar file).

0
Comment actions Permalink

So I tried the solution described, apparently it only works if I set it as class. But now the files don't appear when I search, so two things:
This should be managed on run config level.
I do think that they should appear in my search as they are part of my project.

So I will say that this does not work as expected out of the box (or simply is a downgrade from eclipse, which is free)

0
Comment actions Permalink

I found another issue, if I need to have multiple environments depending on the classpath I have to change the project configuration too. This is not acceptable, I should be able to have n configurations with the only difference being the classpath.

There should be a way to add to the classpath in the run configuration. So, is there a viable way to do what I'm describing with intellij?

0
Comment actions Permalink

You can create several modules with just classpath entries in the dependencies (https://www.jetbrains.com/help/idea/creating-and-managing-modules.html#working-with-module-dependencies), then in the run/debug configuration specify which module classpath to use.

0
Comment actions Permalink

this seems like a viable option, will check later, also, now I'm able to search the class lib by marking the folder as source.

Would it be an issue that the module that I use to run is a maven module?

0

Please sign in to leave a comment.