Add commons-math3 dependency to xtext maven project

I have xtext language server project configured to build with maven. With the default dependencies, the project build is working fine with

mvn clean install -U -Dmaven.test.skip=true

But now I need to add commons-math3 as a dependency. I have added the following to xtext’s pom.xml

    <dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-math3</artifactId>
            <version>3.6.1</version>
            <scope>import</scope>
        </dependency>
    </dependencies>

When I run the above maven command, I see that the jar files are downloaded in ~/.m2/repositories folder

./org/apache/commons/commons-math3
./org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.pom
./org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.jar.sha1
./org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.pom.sha1
./org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.jar

But when I try to use it in my code, the imports are not resolved:

import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
import org.apache.commons.math3.geometry.euclidean.threed.RotationOrder;
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;

I need to “search repositories “org.apache.commons.math3.geometry.euclidean.threed'” and select the found artifact to the target platform (though I am not sure what does this actually do — git status does not show changes in any of the files).
enter image description here

After this, I need to add the package to MANIFEST.MF file

Require-Bundle: org.apache.commons.math3;bundle-version="3.6.1"
...
Import-Package: org.apache.commons.math3;bundle-version="3.6.1"

After this I am able to run the IDE project from Eclipse with “run as Eclipse application”, and everything works as expected. But at this stage if I run the maven command, I get the error:

[ERROR] Cannot resolve project dependencies:
[ERROR]   Software being installed: com.example.xtext 1.0.0.qualifier
[ERROR]   Missing requirement: org.example.xtext 1.0.0.qualifier requires 'osgi.bundle; org.apache.commons.math3 3.6.1' but it could not be found

Do I need to add <repository> in pom.xml? But the jar is downloaded, meaning it has been properly located. Or am I missing something in the <build> stage in pom.xml?

Edit 1: If I start with a clean maven project (without xtext), adding the dependency works without any additional steps. So some configuration in xtext is not allowing the dependency to be found.

Edit 2: In some old project I found that the external dependencies have be installed in ~/.m2/repository/p2/osgi/bundle/ folder. Is that the only way for a dependency to be found?

  • 1

    You should not use <scope>import</scope> you should remove that simply.

    – 

  • sorry I was just fooling around. Even after removing it I get the same error

    – 

  • Am I right assuming the nature of your project is an OSGI bundle? My experiences with OSGI are limited and I never found out how Maven and OSGI go well together. I remember that besides adding a dependency to the MANIFEST the JAR itself has to be added to a specific directory. Check whether you find that directory and try adding your JAR to this directory. If this works maybe you’ll find a mechanism that this happens automatically.

    – 




  • if you want to use maven artifacts in eclipse code you need to do this one: läubisoft.gmbh/en/articles/…

    – 

  • but as commons math is already there: download.eclipse.org/tools/orbit/simrel/orbit-aggregation/… you can use that one in your target directly

    – 

Leave a Comment