0

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?

Community
  • 1
  • 1
incaseoftrouble
  • 353
  • 1
  • 13

1 Answers1

1

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).

arghtype
  • 4,376
  • 11
  • 45
  • 60
  • 1. Is not an option (or I just don't see it): `-cp` sets the classpath instead of adding something to it, doesn't it? 2. That's a good suggestion, thanks. – incaseoftrouble Apr 12 '16 at 09:58
  • @Megge, as for cp, you could use good old trick with adding to classpath: CLASSPATH = $CLASSPATH + new_cp_entry. – arghtype Apr 12 '16 at 10:52
  • Just out of curiosity: How exactly would I do that in this case? Sorry if that seems like a bit dumb question, but `$CLASSPATH` isn't resolved when added to the VM options. – incaseoftrouble Apr 12 '16 at 11:06
  • I've tried it in several ways, and honestly can't figure out the solution. Looks like you cannot use environment variables there, and using custom cp will require adding idea libraries there as well, which is not straightforward. I will update answer regarding this issues. – arghtype Apr 12 '16 at 11:31
  • It seems that both maven and intellij intend the class path to be only used for bundled / internal resources. After spending some thought on it I found a pretty trivial solution for my particular problem: I can actually override the system property used by logback to find the configuration file before logback actually is initializes. My goal was to make the run configuration as portable as possible, this is the most portable way in my eyes. – incaseoftrouble Apr 12 '16 at 22:47