Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Use OpenModelica with Eclipse on Linux

Use OpenModelica with Eclipse on Linux

Hi,

I'm developing a software in Java using Eclipse IDE.
For this application, I need to interface OpenModelica with my Java application.
My computer is running on Linux Debian Squeeze (the last version) and OpenModelica 1.9.0.

To do this, I'm using the Corba interface from the java_modelica.jar library.

I registered the java_modelica.jar library and the $OPENMODELICAHOME environment using the following command

Code:

export OPENMODELICAHOME=/usr

source ~/.bashrc

My problem is the following: when I run OMNotebook, it works like a charm, as suggested in https://www.openmodelica.org/index.php/ … pic?id=137

But when I run my eclipse application, I get the following error:

Code:

Exception in thread "main" org.openmodelica.corba.ConnectException: Environment variable OPENMODELICAHOME not set

    at org.openmodelica.corba.OMCProxy.getOmcBinaryPaths(OMCProxy.java:215)
    at org.openmodelica.corba.OMCProxy.startServer(OMCProxy.java:274)
    at org.openmodelica.corba.OMCProxy.init(OMCProxy.java:419)
    at org.openmodelica.corba.OMCProxy.sendExpression(OMCProxy.java:495)
    at modelica.Modelica.simulateModel(Modelica.java:14)
    at optimizationToolbox.OptimizationToolbox.main(OptimizationToolbox.java:21)

My modelica.Modelica.simulateModel method simply executes the cd() command using the org.openmodelica.corba.sendExpression method. (I created this method to check the Corba interface and the OMC environment using a simple command).

It seems that the System.getenv() method used to check the environment variable does not work on Linux.
Running the command "System.out.println(System.getenv("OPENMODELICAHOME"));" displays "null".

Could you pls tell me how I can solve this problem ?

Thanks in advance.
Regards,

Edited by: dcasner - Mar-20-13 12:42:05

Re: Use OpenModelica with Eclipse on Linux

Eclipse clears the environment so you might need to set it there as well. Or write a small patch for the jar-files to also search the PATH for omc. That way you will never need to set OPENMODELICAHOME.

Re: Use OpenModelica with Eclipse on Linux

Hi,
Thanks for your reply.
I changed the getenv() method to the System.getProperty method, and I set the path with System.setProperty...

Does the OPENMODELICAHOME have any other objective than locate the "omc" executable ?
If so, how can I edit the OMCProxy.java file to simply use the "omc" shell command instead in Linux ?

Re: Use OpenModelica with Eclipse on Linux

Hi,
Thanks for your reply.
I changed the getenv() method to the System.getProperty method, and I set the path with System.setProperty...

Does the OPENMODELICAHOME have any other objective than locate the "omc" executable ?
If so, how can I edit the OMCProxy.java file to simply use the "omc" shell command instead in Linux ?

Best,

Re: Use OpenModelica with Eclipse on Linux

This is what I changed in the getOmcBinaryPaths() method...

Code:

String openModelicaHome = null;

     
    if (os == osType.WINDOWS)
    {
         openModelicaHome = System.getenv("OPENMODELICAHOME");
    }
    else
    {
        openModelicaHome = "/usr";
    }

Re: Use OpenModelica with Eclipse on Linux

That would work on some installations on Linux, but not any on OSX.

This is how OMEdit does it: https://openmodelica.org/svn/OpenModeli … CProxy.cpp

But it gets the configured installation path and can guess where omc is.

Best way would be to rewrite it to look for
OMHOME/bin/omc[.exe]
DEFAULTHOME/bin/omc[.exe]

And if neither file exists... Just call omc.

Changing getBinaryPaths to return only 1 string... Either an absolute path or "omc", then use that.

OPENMODELICAHOME does change more things if it is set when omc is called. In that case we use either OPENMODELICAHOME or the hard-coded path omc thinks it is installed in to find libraries and headers, etc.

Re: Use OpenModelica with Eclipse on Linux

Thanks for your advices...
I changed getOmcBinaryPath() as follows:

Code:

private File[] getOmcBinaryPaths() throws ConnectException

  {
    String binaryName = "omc";

    if (os == osType.WINDOWS)
    {
      binaryName += ".exe";
    }

    File omcBinary = null;
    File omcWorkingDirectory = null;
 
    //String openModelicaHome = System.getenv("OPENMODELICAHOME");
   
    String[] subdirs = { "", "bin", "Compiler" };
       
    File[] Roots = File.listRoots();
    //List the different Roots (C:\, D:\ for Windows, / for UNIX)
   
    for(File file:Roots){
            \\List folders from RootDir

        File[] dir = file.listFiles(new FileFilter() {
            public boolean accept(File f) {
                return f.isDirectory();
            }
        });
   
        for (File sd : dir){
                        //For each directories, I check if ***/bin/omc[.exe] or ***/omc[.exe] or ***/Compiler/omc[.exe] exists

            for(String sdir : subdirs)
            {
                String path = sd.getAbsolutePath() + File.separator;               
                path += sdir + File.separator + binaryName;
                               
                File f = new File(path);
                               
                if (f.exists())
                {
                                     //File exists ==> Set omcBinary and omcWorkingDirectory variables with the given paths
                         omcBinary = f;
                            omcWorkingDirectory = sd;
                         System.out.println(f.getAbsolutePath());
                         break;
                }               
            }
            if(omcBinary != null){
                                //Stops if found
                break;
            }
        }
        if(omcBinary != null){
                        //Stops if found
            break;
        }
    }
   
    if (omcBinary == null)
    {
      logOMCStatus("Could not fine omc-binary on the OPENMODELICAHOME path");
      throw new ConnectException("Unable to start the OpenModelica Compiler, binary not found");
    }

    return new File[] {omcBinary, omcWorkingDirectory};
}

It is working with Windows and Linux... I was unable to check on Mac OS.

Thanks for your help...

There are 0 guests and 0 other users also viewing this topic
You are here: