0

I have been asked to create a project in vb.net which needs to integrate a java class created by Apple (Autoingestion.class) to pull sales records and so on.

I found out a couple of questions here on stackoverflow but none of the answers given worked for me when trying to integrate this java class in my .net application.

For example this question seemed to be what I really needed but when trying to compile this java class (I decompiled it first using Java Decompiler), it generally throws some errors.

All I need is to use this class in my application to invoke a method. Does anyone know how to pull this out without much ninja-ing?

EDIT: Here is the decompiled code from Autoingestion.class

Community
  • 1
  • 1
Hallaghan
  • 1,910
  • 6
  • 32
  • 47
  • Did you use ikvm as described in the accepted _answer_? It does not mention decompiling at all. – Oded Apr 13 '12 at 11:04
  • Oded, the file I received is a compiled java class, so the file extention is .class. In order to create a .jar out of it, I needed to decompile the code so I could create a new java project with it and eventually create the .jar to pass to the ikvm. So, as I mentioned, the code decompiled doesn't even run. I can post the code here to exemplify. Also, I tried to create a .jar out of the compiled Autoingestion.class file and when integrating the .dll created by ikvm, my .net app couldn't access any members of this dll. – Hallaghan Apr 13 '12 at 11:06
  • [the jar command](http://docs.oracle.com/javase/tutorial/deployment/jar/build.htm) takes files and/or directories as input and does not compile java source (that is javac). You do not need to decompile/recompile your classes to add them to a jar file. In the end a jar file is just a zip file with some extra meta-data content. – krock Apr 13 '12 at 11:16
  • @krock, I tried to compile a .jar with the compiled java class and passed it through ikvm as suggested but the generated dll didn't expose any methods to my .net application. – Hallaghan Apr 13 '12 at 11:18
  • Looking at the decompiled source all it seems to do is make a post over https, with some params that are given on the command line and then reads back the response and saves it to a file. IMO you may as well just rewrite that in .Net by hand. – krock Apr 13 '12 at 11:27
  • That's what I'd rather do but I was asked not to and to maintain the code as it is right now. – Hallaghan Apr 13 '12 at 11:32

1 Answers1

2

The simplest solution here (other than rewriting the java code in .Net -see above comments) is to simply execute the existing java code from .Net since the class concerned contains a main method. i.e. something like this assuming the java class is in the working dir of your .Net app (and java is on your path):

Shell("java Autoingestion <options>")

this keeps original functionality and is uses similar commands you currently do.

krock
  • 28,904
  • 13
  • 79
  • 85
  • Krock, thanks for your solution, I will mark it as the answer. I already managed to use the dll in .net. Apparently, what I was doing wrong was that I had to rename the main method to something else and then use ikvm again. This time I was able to get it working. Kudos to the developer of ikvm, it's an amazing app. – Hallaghan Apr 13 '12 at 13:38
  • In the end I preferred your solution to save myself the hassle of having to generate a dll everytime Apple updates that file. Thanks again. – Hallaghan Apr 16 '12 at 10:48