通过 Eclipse 的 Maven 设置 vm 默认参数

发布于 2024-10-07 13:49:14 字数 1006 浏览 0 评论 0原文

我想指定-Djava.library.path=./src/main/resources的vm args,以便自动拾取dll,并且我想在maven中指定这一点,这样其他开发人员就不必手动配置eclipse 。

我在想也许 Maven Eclipse 插件可能会有所帮助,所以我可以做类似的事情

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-eclipse-plugin</artifactId>
  <version>2.7</version>
  <configuration>
    DO MAGIC HERE ???? <<-----
  </configuration>
</plugin>

,但我看不到从插件中添加 VM 参数的方法。

我已经修复了这个问题,以便通过我当前的解决方案在命令行通过 maven 运行我的测试

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.4.3</version>
  <configuration>
    <argLine>-Xmx768m -Xms128m -Djava.library.path=${basedir}/src/main/resources/</argLine>
  </configuration>
</plugin>

,我必须告诉开发人员将其手动添加到 eclipse 中,这看起来不太好。

有没有人对如何解决这个问题有任何想法。

干杯,

大卫。

I want to specify vm args of -Djava.library.path=./src/main/resources so that a dll is picked up automatically, and I want to specify this in maven, so other developers don't have to manually configure eclipse.

I was thinking perhaps the the maven eclipse plugin might help, so I could do something like

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-eclipse-plugin</artifactId>
  <version>2.7</version>
  <configuration>
    DO MAGIC HERE ???? <<-----
  </configuration>
</plugin>

But I can't see a way to add VM args from within the plugin.

I have fixed this for running my tests via maven at the command line by

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.4.3</version>
  <configuration>
    <argLine>-Xmx768m -Xms128m -Djava.library.path=${basedir}/src/main/resources/</argLine>
  </configuration>
</plugin>

My current solution, is that I will have to tell the developers to add this manually to eclipse which doesnt seem very good.

Has anybody got any ideas as to how to solve this.

cheers,

David.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

听,心雨的声音 2024-10-14 13:49:14

也许这应该是一个更普遍的问题:

有没有什么方法可以将 DLL 添加到 VM,而不必通过库路径指定它?

我在某处读到,将 dll 放在应用程序根目录中并在 MANIFEST.MF 中指定 DLL 及其哈希码会触发 VM 自动拾取它。但这可能是完全错误的。

Maybe this should be a more general question:

Is there any way of adding a DLL to the VM without having to specify it through the library path?

I've read somewhere that putting the dll in the application root and specifying the DLL in the MANIFEST.MF with its hashcode triggers the VM to automatically pick it up. That could be completely wrong though.

陌若浮生 2024-10-14 13:49:14

我对你的问题的解释是你的应用程序正在加载一个 DLL,并且该 DLL 位于你的项目的资源文件夹中。正确的?

如果 DLL 位于类路径中的文件夹内,则可以获取 DLL 的完整路径,并使用以下命令加载它:

// assuming dll is located in the default package
URI dllUri = this.getClass().getResource("/mydll.dll").toURI();
File dllFile = new File(dllUri);
System.load(dllFile.getCanonicalPath());

这与 maven 无关。只有两个问题:

  1. 该解决方案与系统无关,因为您在 getResource() 的参数中指定了文件的后缀。
  2. 如果 DLL 位于 JAR 内,则此方法将不起作用。对于本例,我们构建一个 JAR 提取器,它将 DLL 提取到临时文件夹,并使用临时文件夹中的文件调用 System.load()。

My interpretation of your problem is that your application is loading a DLL and this DLL is located in your project in the resources folder. Correct?

You can get the full path of the DLL if the DLL is inside a folder in the class path and load it using:

// assuming dll is located in the default package
URI dllUri = this.getClass().getResource("/mydll.dll").toURI();
File dllFile = new File(dllUri);
System.load(dllFile.getCanonicalPath());

This is independent of maven. There are only two problems:

  1. The solution is not system independent since you specify the suffix of the file in the parameter to getResource()
  2. This won't work if the DLL is inside a JAR. For this case we build a JAR extractor which will extract the DLL to a temp folder and call System.load() with the file in the temp folder.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文