本文介绍了IntelliJ with Maven:添加类路径条目而不复制资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将IntelliJ与maven一起使用。我想创建一个外部配置文件夹(即不包含在jar中),其中包含 logback.groovy 和一些属性文件。此文件夹由maven添加到类路径中(通过maven-jar-plugin,请参阅)。但是如果我从IntelliJ内部运行项目,则不会添加此类路径条目,也不会找到相应文件夹中的内容。将文件夹添加为运行时模块依赖项可修复问题,但似乎不是很干净。有没有什么办法可以配置maven,以便类路径条目也被添加到IntelliJ运行中。如果那是不可能的,我可以以某种方式添加类路径条目到执行而不诉诸依赖等。?在eclipse中我可以在运行配置中添加任意类路径条目,我确定我只是缺少IntelliJ中的一些菜单。

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.

请注意将文件夹标记为资源(在maven或IntelliJ中都不是一个选项,因为文件夹内容然后被复制到 target / classes 并捆绑到jar中。

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.

编辑:为什么单独的文件夹的原因:外部库(例如logback)直接从类路径加载它们的依赖项而没有太多的干预可能性(据我所知)。我非常不喜欢将大量的配置文件放在一起,而是希望它们尽可能集中。

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?

推荐答案

我不确定您的配置是什么样的,但您可以尝试以下方法之一:

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


  1. 似乎不允许在那里使用env变量,这使得这太难了:需要为想法运行器提供应用程序cp和cp条目。

您实际上可以在配置中运行Maven而不是IDEA的make。请参阅运行配置>在启动之前,您应该删除默认 Make 并将其替换为maven目标(例如 clean compile )。

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

这篇关于IntelliJ with Maven:添加类路径条目而不复制资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 07:17