简体   繁体   English

使用Maven编译Fortran子例程(按平台)并链接到JNA

[英]Use Maven to compile a Fortran subroutine (per-platform) and link to JNA

I have a Java library that needs to call some fortran subroutines ( that are pretty complicated, and should not be re-implemented in java ). 我有一个Java库,需要调用一些fortran子例程( 这很复杂,不应在java中重新实现 )。 The fortran compiler will generate some platform-specific .so files. fortran编译器将生成一些特定于平台的.so文件。 I then want to hook these up to JNA to be able to call them from Java. 然后,我想将它们连接到JNA,以便能够从Java调用它们。

I found this resource on calling fortran from JNA here, which doesn't seem to be too bad: http://www.javaforge.com/wiki/66061 我在这里从JNA调用fortran时发现了该资源,这似乎还不错: http : //www.javaforge.com/wiki/66061

However, my question is whether I can get Maven to compile the subroutines and place the generated library files in target/ or something like that, and be able to pick them up automatically from JNA. 但是,我的问题是我是否可以让Maven编译子例程并将生成的库文件放置在target /或类似的文件中,并能够从JNA中自动提取它们。 I feel like I could do this without too much trouble if I was using a Makefile, but have no idea how I'd get Maven to do it. 我觉得如果使用Makefile,我可以做到这一点而没有太多麻烦,但是不知道如何让Maven做到这一点。

Moreover, I'm using m2e, the maven plugin for eclipse, so it seems that the compatibility of any maven plugins that might work by themselves is even less likely with m2e. 而且,我使用的是m2e,这是Eclipse的maven插件,因此似乎所有可能自己工作的maven插件的兼容性与m2e的可能性甚至更低。

I'm going to focus on the maven-specific approach. 我将专注于特定于Maven的方法。 I don't really know m2e, but if you get the basic maven working, then any ide should just defer to it. 我不太了解m2e,但是如果您能使用基本的maven,那么任何想法都应该遵循它。 Hopefully this is helpful. 希望这会有所帮助。

There is the exec plugin which allows you to execute external programs. exec插件 ,可让您执行外部程序。 So, if you think you can knock it up quickly with a makefile, this might be the easiest way of doing so. 因此,如果您认为可以使用makefile快速将其删除,则这可能是最简单的方法。 You end up relying more on the environment than the plugins, which is not the maven way. 您最终比插件更多地依赖于环境,这不是行之有效的方法。 But it will probably get the job done. 但这可能会完成工作。

Professor Google replied with this article , which looks a little like what you want to do. Google教授回答了这篇文章 ,看起来有点像您想要做的事情。 A lot of the topics are around compiling C libraries for use in Java. 许多主题都围绕编译用于Java的C库。 So it should be somewhat close (even though you're calling out to different compilers, etc). 因此,它应该有点接近(即使您要调用其他编译器等)。 There's been enough people building native libraries that there's a plugin for that , although again it focuses on libraries written in C and not Fortran. 建立本机库的人已经足够了,为此有一个插件 ,尽管它再次侧重于用C而不是Fortran编写的库。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM