Book a Demo

Author Topic: Java Automation: I-Exception reading Repository  (Read 4068 times)

kaimeder

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Java Automation: I-Exception reading Repository
« on: October 02, 2007, 03:06:02 am »
Hello,

im just starting to code java against the automation server:

Code: [Select]

System.out.println("loading EA-API ...");
try {
   System.loadLibrary("SSJavaCOM");
   System.out.println("successfully loaded");
} catch (UnsatisfiedLinkError e) {
   System.out.println("could not load EA-API: " + e.getMessage());
}
System.out.println("opening EA-Repository ...");
try {
   Repository rep = new Repository();
   rep.OpenFile("./test.eap");
   System.out.println("LOADED! processing...");

   try {
       Collection<Package> models = rep.GetModels();
   } catch (Exception e) {
       System.out.println(rep.GetLastError());
       e.printStackTrace();
   }
} catch (Exception e) {
   e.printStackTrace();
   System.out.println("could not load Repository: " +         e.getMessage());
}


getting the models crashes with following output:
Quote
loading EA-API ...
successfully loaded
opening EA-Repository ...
LOADED! processing...
Call FileOpen() or FileOpen2() before accessing other Repository members.
java.lang.Exception: I
at org.sparx.Repository.comGetModels(Native Method)
at org.sparx.Repository.GetModels(Repository.java:570)
at de.innobis.innproc.Starter.main(Starter.java:33)


any hints?

thanks,
kai

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Java Automation: I-Exception reading Repositor
« Reply #1 on: October 02, 2007, 01:02:04 pm »
Try checking the return value of OpenFile.  I suspect that it failed.

Try passing in an absolute file path.
« Last Edit: October 02, 2007, 01:02:28 pm by simonm »

jkorman

  • EA User
  • **
  • Posts: 99
  • Karma: +0/-0
    • View Profile
Re: Java Automation: I-Exception reading Repositor
« Reply #2 on: October 03, 2007, 05:04:26 am »
Since you're getting started consider the following "boiler-plate"
Code: [Select]

Repository rep = null;
File file = new File(filePath);
if(file.exists()) {
 try {
    if((rep = new Repository()) != null) {
       if(rep.OpenFile(filePath)) {
          // do stuff here
       }
    } else {
       System.out.println("Could not create repository");
    }
 } catch(Exception e) {
 }
 finally {
    if(rep != null) {
       rep.CloseFile();
       rep.destroy();
    }
 }
} else {
  System.out.println("File not found");
}

This way any resources you create, get cleaned up.

Jim

kaimeder

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Java Automation: I-Exception reading Repositor
« Reply #3 on: October 03, 2007, 10:07:25 pm »
thanks alot, problem was the absolute filepath, as mentioned.

thanks!
kai