是否可以从 POM 文件内部一致地将 -Djava.library.path 传递给 Maven 测试?
我有一个外部库,需要与我的 java 项目中的测试动态链接。该项目是使用 maven 设置的,我需要将以下内容添加到 eclipse 中的 vm 参数中才能通过测试:
-Djava.library.path=${env_var:HOME}/.m2/repository/natives/ dist/lib -ea
不幸的是,这意味着使用 mvn test 从 Maven 运行测试总是会失败。
一种解决方法是使用 -DargLine
参数调用 mvn
,如下所示:
mvn test -DargLine="-Djava.library.path=/Users/rob/ .m2/repository/natives/dist/lib -ea"
但是,显然这存在特定于我的机器的问题,因此我无法将其直接放入 pom 文件中。我想我正在寻找的是一种在每台机器上修改该字符串的方法,就像第一行对 Eclipse 所做的那样。
我也很好奇如何将它放入 POM 文件中,我尝试将其放入
标签内,但这似乎不起作用,有什么我' m 缺失:
I have an external library that needs to be dynamically linked with a test in my java project. The project is setup using maven, and I need to add the following to my vm arguments in eclipse for the test to pass:
-Djava.library.path=${env_var:HOME}/.m2/repository/natives/dist/lib -ea
Unfortunately this means that running the test from maven using: mvn test
will always fail.
One work around is to call mvn
with a -DargLine
argument like so:
mvn test -DargLine="-Djava.library.path=/Users/rob/.m2/repository/natives/dist/lib -ea"
However, clearly this has the problem of being specific to my machine, so I can't put it directly in the pom file. I guess what I'm looking for is a way of modifying that string on a per machine basis kinda like the first line does for eclipse.
I'm also curious how I could put it into the POM file, I've tried placing it inside of <argLine>
tags, but that doesn't seems to work, is there something I'm missing:
<argLine>-Djava.library.path=/Users/rob/.m2/repository/natives/dist/lib -ea</argLine>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过一些研究,我发现了解决我的问题的一个不错的方法。
在 maven 的
settings.xml
文件中,您可以定义localRepository
的位置,如果您什么都不设置,这里是默认值:如您所见,这至少与我尝试设置的目录的第一部分匹配:
/Users/rob/.m2
由于动态链接是操作系统具体的,你可以还想为备用路径后缀设置配置文件。您可以在
.pom
中执行此操作,如下所示:然后,您可以在
.pom
中为要测试的项目使用此属性。在插件类别下,您可以添加:现在,maven 可以运行这些测试,而无需用户指定动态链接库的位置。您还可以通过添加另一个配置文件来处理使用不同操作系统的用户。
注意:关于我之前的
问题。我想我只是在错误的.pom
中使用它After some research I've discovered a decent solution to my problem.
In maven your
settings.xml
file, you can define a location for thelocalRepository
here are the defaults if you set nothing:As you can see this matches at least the first part of the directory I was trying to set:
/Users/rob/.m2
Since dynamic linking is OS specific, you may also want to setup a profile for alternate path suffixes. You can do this in a
.pom
like this:You can then use this property in the
.pom
for the project you wish to test. Under the plugins category you can add:Now maven can run those tests without users having to specify the location of the dynamically linked libraries. You can also handle users with different operating systems by just adding another profile.
Note: With regards to my problem with
<argLine>
earlier. I think I was just using it in the wrong.pom