Submit a problem

In order to provide you the best help possible to analyze and debug your problems please provide us some information about your environment.
When you submit a problem, please indicate:
- The Version, Build Id, Core Id, System and Architecture (You can get these information in the Help/About menu entry)
- The Modelio Edition (Modelio Open Source or Modelio by Modeliosoft)
- Your Operating System

check maven build error with custom jar files

2 weeks 5 days ago - 2 weeks 4 days ago #4620 by bbinder
[sorry, i posted this to general Help on accident. re-posting it here.]
Hello everybody,

I am building a Modelio Plugin and am encountering a problem during the build which i cannot fix. I have some C# code which I have bridged to Java using jni4net. Basically, this outputs two jar-files and four dlls. With the standard maven archetype, i can build this project just fine. But when i try to instantiate the classes exposed by the jar-files in Modelio itself (after adding the module), i get a ClassDefNotFound exception.

Then i checked out the jmdac and realized the jars and dlls were not added to the /lib folder. I extended the assembly.xml file to package those files alongside commons-lang3-3.1.jar in the lib folder.
<!--  Copy the jni4net dependencies -->
<fileSet>
    <directory>${project.basedir}</directory>
    <outputDirectory>${project.name}/lib</outputDirectory>
    <includes>
        <include>*.jar</include>
        <include>*.dll</include>
    </includes>
</fileSet>

A quick build shows correct packaging. Still, i thought i have to add those files to the ClassPath in the module.xml. First, I added the jni4net standard jar:
<ClassPath>
    <PathEntry path="lib/${project.artifactId}-${project.version}.jar"/>
    <PathEntry path="lib/jni4net.j-0.8.8.0.jar"/>
    <PathEntry path="lib/commons-lang3-3.1.jar"/>
</ClassPath>

It still builds without a problem. However, when i add the other jar, it suddenly doesn't build anymore:
<ClassPath>
    <PathEntry path="lib/${project.artifactId}-${project.version}.jar"/>
    <PathEntry path="lib/jni4net.j-0.8.8.0.jar"/>
    <PathEntry path="lib/commons-lang3-3.1.jar"/>
    <PathEntry path="lib/SysMLDataModel.j4n.jar"/>
</ClassPath>

and mvn install -X will throw an Exception and show the following error:
[INFO] Updating content of [...]\src\main\conf\module.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.715 s
[INFO] Finished at: 2017-09-04T10:38:12+02:00
[INFO] Final Memory: 7M/17M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.modelio:modelio-maven-plugin:3.6.1.00:module-configuration (ResourceManagement) on project [TEST]: Execution ResourceManagement of goal org.modelio:modelio-maven-plugin:3.6.1.00:module-configuration failed: String index out of range: -1 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.modelio:modelio-maven-plugin:3.6.1.00:module-configuration (ResourceManagement) on project [TEST]: Execution ResourceManagement of goal org.modelio:modelio-maven-plugin:3.6.1.00:module-configuration failed: String index out of range: -1

This seems to happen because during build, the jar-files and the dlls cannot be associated. But i am stuck as to when exactly and where exactly the module configureation goal searches for the files. maybe i have to copy them to the correct location?

Any help would be appreciated.

Please Log in or Create an account to join the conversation.

2 weeks 4 days ago - 2 weeks 4 days ago #4626 by bbinder
Hello,

in the meantime I found the solution. I'm posting it here in case someone needs it in the future. This solution does not only apply to using jni4net in the maven project but also to other applications of jar-files in the maven project.

This answer assumes, the jars and dlls are located at the project root.

First, we need to add the jars as system scope dependencies. Open pom.xml add your dependencies to the dependencies node:
<dependency>
    <groupId>net.sf</groupId>
    <artifactId>jni4net.j</artifactId>
    <version>0.8.8.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/jni4net.j-0.8.8.0.jar</systemPath>
</dependency>
		
<dependency>
    <groupId>org.[yourorganization]</groupId>
    <artifactId>[jni4net output].j4n</artifactId>
    <version>0.0.0.1</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/[jni4net output].j4n.jar</systemPath>
</dependency>

The jni4net proxygenerator produces one jar file for your .NET application. you also need the jar file containing the jni4net bridge itself. Furthermore, you need the .NET application dlls and the jni4net dlls. Please check the jni4net github wiki to see the ones you need.

The dlls can't be added as dependencies. But since those are loaded at runtime, we only have to make sure they're available in the same unzip folder as the jars. Go to your assembly.xml and add add the following node to your fileSets node.
<fileSet>
    <directory>${project.basedir}</directory>
    <outputDirectory>${project.name}/lib</outputDirectory>
    <includes>
        <include>*.dll</include>
    </includes>
</fileSet>

And they will be zipped up together. Even more interesting, the PathEntry nodes in the module.xml file will be automatically added. Great.

And that's it. Run the maven install and it will work.

DISCLAIMER: I've only ran it in debug mode so far. still have to try out the actual deployed module.

Please Log in or Create an account to join the conversation.

Moderators: tmachmaab
Time to create page: 0.049 seconds
^ Back to Top