incaseoftrouble
incaseoftrouble

Reputation: 373

IntelliJ with Maven: Add classpath entry without copying the resources

I'm using IntelliJ together with maven. I want to create an external configuration folder (i.e. not included in the jar) containing things like logback.groovy and some property files. This folder is added to the classpath by maven (via the maven-jar-plugin, see Maven - how can I add an arbitrary classpath entry to a jar? ). But if I run the project from inside IntelliJ, this classpath entry is not added and the contents in the corresponding folder is not found. Adding the folder as runtime-module-dependency fixes the problem but does not seem very clean. Is there any way I can configure maven such that classpath entries are added to the IntelliJ run too. If thats not possible, can I somehow add a classpath entry to the execution without resorting to dependencies etc.? In eclipse I could add arbitrary classpath entries to the run configuration, I'm sure I'm just missing some menu in IntelliJ.

Note that marking the folder as resource (in either maven or IntelliJ) is not an option, as the folder contents then get copied to target/classes and bundled into the jar.

EDIT: Rationale for why a separate folder: External libraries (like for example logback) load their dependencies directly from the classpath without much possibilities of intervention (as far as I understood it). I highly dislike putting loads of configuration files all over the place and instead want them to be as centralized as possible.

Follow-Up question: Am I misusing the concept of classpath here?

Upvotes: 0

Views: 1641

Answers (1)

arghtype
arghtype

Reputation: 4534

I'm not sure what your configuration looks like, but you could try one of the following:

  1. You could update class path via -cp flag in Run Configuration > JDK Settings > VM Options. Seems like it's not allowed to use env variables there, which makes this way too difficult: it's required to provide both your application cp and cp entries for idea runner.

  2. You could actually run Maven instead of IDEA's make in your configuration. See Run Configuration > Before Launch, you should remove default Make and replace it with maven goals (e.g. clean compile).

Upvotes: 1

Related Questions