3

Is there any way for me to get the version of an assembly or application in Java?

For example, I have a .NET .dll file located in Program Files. I normally call `loadLibrary' on this .dll so I can invoke JNI methods in C++.

System.loadLibrary("MyJniAssembly");

Can someone point me in the right direction? Thanks.

Jens Björnhager
  • 5,632
  • 3
  • 27
  • 47
gwin003
  • 7,432
  • 5
  • 38
  • 59
  • Do you have control over the Java code? – Fildor Apr 25 '13 at 15:28
  • are you looking for sth. like this: http://stackoverflow.com/questions/8273630/checking-java-assembly – Barış Akkurt Apr 25 '13 at 15:32
  • @Fildor: Yes I have control over the Java code. @Barış: Not exactly. I want to look at my DLL and get its version number, i.e. `1.0.0.0` – gwin003 Apr 25 '13 at 15:32
  • Sorry, I misunderstood at first. Of course you are in java and calling via jni ... Haven't heard of a standardized way to do this. – Fildor Apr 25 '13 at 15:38

1 Answers1

2

The simplest way would be to expose that information in another native method implemented in the assembly. If you can't do it there, you'd have to create a new assembly with such a method but one that takes a parameter indicating the assembly or type you are interested in.

Tom Blodget
  • 20,260
  • 3
  • 39
  • 72
  • So if I understand you correctly, the easiest way would be to create a new native method to call into a C++ dll, then get the assembly versions there? The C++ dll calls another C# dll, so should I create another new dll that simply returns the version of my C++ or C# dll I am interested in? – gwin003 Apr 25 '13 at 15:40
  • Yes. The method could return the version of any one assembly or return a list of all assemblies loaded at the point in time. Where such a method is implemented depends on which assemblies you can change and if you can call `System.loadLibrary` for a new assembly. – Tom Blodget Apr 25 '13 at 15:47
  • Of the assemblies I need to check the version of, I have control over all but one. So I am thinking I will implement a new native method in JNI, then the C++ code will return the version numbers of the dll's I am interested in. Does this sound correct? – gwin003 Apr 25 '13 at 15:54
  • Yes. The only caveat is that the method should be called only after the assemblies you are interested in are loaded. – Tom Blodget Apr 25 '13 at 15:58
  • Ok, I will try this later this afternoon or tomorrow and report back if I have any issues. Thanks for the help Tom. – gwin003 Apr 25 '13 at 16:09