Author Topic: Writing an Add-in with Java and IKVM  (Read 6311 times)

Stephane B

  • EA User
  • **
  • Posts: 31
  • Karma: +0/-0
    • View Profile
Writing an Add-in with Java and IKVM
« on: March 27, 2013, 09:09:25 pm »
Hello to the community from a newcomer.

Short story:
What does "Error - Invalid parameter(s)" mean in the Manage Add-ins panel ?

Long story:
I know Java Add-ins are not supposed to be possible, but I didn't want to learn C# just for that purpose.
So I decided to use IKVM to build an COM visible .NET dll from java.

First I made a strongly-named build of IKVM and OpenJDK
Then I created a stub mscorlib.jar from the Windows mscorlib.dll.
Then I wrote the following Java class :

Code: [Select]
package mypkg;

import org.sparx.Repository;
import cli.System.Runtime.InteropServices.*;

@ClassInterfaceAttribute.Annotation(
                ClassInterfaceType.__Enum.AutoDual)
public class MyAddin {

      public String EA_Connect(Repository repository) {
            //this method might be mandatory
            return "";
      }
      
      public String hello(Repository repository) {
            return "hello world";
      }
}

The cli import comes from the mscorlib.jar
The annotation is meant to make the class COM visible.

Then I :
-exported to mypkg.jar
-transformed the EA eaapi.jar to dll with ikvmc (all dlls strongly named)
-transformed the mypkg.jar to dll with ikvmc, using both eaapi.dll and mscorlib.dll as dependencies.
-registered my dll with regasm /codebase mypkg.dll
-created a key in the registry for EAAddins with value mypkg.MyAddin

Result : in the EA Manage Add-ins panel my Add-in is seen, no more "Error - Missing" message, but instead an "Error - Invalid parameter(s)"

So my questions are :
-Has anyone tried it ? (succeded?)
-What does this error mean ? Is it a problem with the dll, with the package, the class or method ?
-Do I need to implement particular methods in my class ? Is the EA_Connect needed ? Should I put a default constructor ?
-Has this method any chance to ever work ? If no, why ?
-What is the right signature for a method to be called via EXEC_ADD_IN ?

By the way, I'm using EA 9.0.906. Company choice. Could get an EA10 trial version to test it...

Thanks.

Stéphane
« Last Edit: March 27, 2013, 09:11:14 pm by StephaneB »

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: Writing an Add-in with Java and IKVM
« Reply #1 on: March 27, 2013, 10:15:58 pm »
Hi Stéphane,

I'm not an expert on this but it seems to me that when you are transforming eaapi.jar to a DLL you are actually creating new COM classes, in particular for the EA 'Repository' class, and that is what why the EA_Connect method fails: EA expects the EA COM classes as parameters. Does that make sense?

best regads,

Paulus

Btw: I have a Java background myself and toyed with the idea of using Java for writing add-ins but quickly abandoned that in favour of .Net. It takes a bit of time but there are good resources that help you along, and it's worth the effort: if you get stuck with .Net chances are somebody will have stumbled on it before you do; and if you also script a lot then using VBScript allows easy covnersion to VB.Net at a later point. ;)

Stephane B

  • EA User
  • **
  • Posts: 31
  • Karma: +0/-0
    • View Profile
Re: Writing an Add-in with Java and IKVM
« Reply #2 on: March 27, 2013, 10:35:10 pm »
Thanks Paulus,

In the EA/Java API directory, there is eaapi.jar, which I transformed to dll with ikvmc. But there is also a SSJavaCOM.dll file.
Instead of dll-ing the jar, maybe I should try to jar-stub the dll.

I will definitely give C# a try though...

Stéphane

Stephane B

  • EA User
  • **
  • Posts: 31
  • Karma: +0/-0
    • View Profile
Re: Writing an Add-in with Java and IKVM
« Reply #3 on: March 27, 2013, 10:41:16 pm »
Quote
But there is also a SSJavaCOM.dll file.
Instead of dll-ing the jar, maybe I should try to jar-stub the dll.

Well my try fell short :
Error : unable to load assembly 'SSJavaCOM.dll'
IKVM.Reflection.BadImageFormatException was raised  >:(

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: Writing an Add-in with Java and IKVM
« Reply #4 on: March 27, 2013, 11:00:18 pm »
... since C# seems an option i would definitely go with that. Using Java for writing EA addins is highly irregular (to say the least).

I can highly recommend the EA navigator tool and tutorial provided by Geert Bellekens (http://geertbellekens.wordpress.com/2011/01/29/tutorial-create-your-first-c-enterprise-architect-addin-in-10-minutes/).

As far as development IDE is concerned take a look at MS Visual Studio express and SharpDevelop (both free).

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13274
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Writing an Add-in with Java and IKVM
« Reply #5 on: March 27, 2013, 11:26:51 pm »
Hi Stephane,

I've never seen anyone succeed in writing an add-in for EA using Java.
In theory it should be possible I guess, but I'm not sure if its worth the hassle.

Besides, if you know Java, then C# will be a breeze.

Geert

Stephane B

  • EA User
  • **
  • Posts: 31
  • Karma: +0/-0
    • View Profile
Re: Writing an Add-in with Java and IKVM
« Reply #6 on: March 27, 2013, 11:38:16 pm »
Thank you Paulus and Geert,

Then C# it will be  ;)

Stéphane

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: Writing an Add-in with Java and IKVM
« Reply #7 on: March 28, 2013, 06:53:10 am »
If you're going to use MS VS Express => know that it is possible to start EA from within the IDE and debug your add-in, but that it requires some manual changes to your project file.

Its explained in http://through-the-interface.typepad.com/through_the_interface/2006/07/debugging_using.html.

Good luck!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8063
  • Karma: +118/-20
    • View Profile
Re: Writing an Add-in with Java and IKVM
« Reply #8 on: March 28, 2013, 08:58:47 am »
I don't know anything about IKVM, but the discussion here is about transforming the eaapi.jar or ssJavaAPI.dll, which is the opposite of what you need to do to get a Java add-in working. These

What you need to is expose your Java code to COM. Effectively a COM class needs to create a JVM, create your class and use reflection to query for available methods which it then exposes to COM through JNI. Trying to write something like would involve a much steeper learning curve than using another language.

On the other hand, I can see similar things available online (eg http://www.nevaobject.com/_docs/_java2com/java2com.htm) although that example would require dropping the Java layer provided by Sparx Systems because it's a two way platform.