I've recently returned to Java development since a very long time, and I'm trying to upgrade an old project to a newer Java version. This project uses the EJML library, but I can't seem to get rid of the error messages in Visual Studio Code. I've distilled the problem that I'm facing into a minimal working example exhibiting the issue.
This example consists of three files:
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mwe</groupId>
<artifactId>mwe</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.17</maven.compiler.source>
<maven.compiler.target>1.17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.ejml</groupId>
<artifactId>ejml-all</artifactId>
<version>0.43.1</version>
</dependency>
<dependency>
<groupId>org.ejml</groupId>
<artifactId>ejml-core</artifactId>
<version>0.43.1</version>
</dependency>
<dependency>
<groupId>org.ejml</groupId>
<artifactId>ejml-cdense</artifactId>
<version>0.43.1</version>
</dependency>
<dependency>
<groupId>org.ejml</groupId>
<artifactId>ejml-ddense</artifactId>
<version>0.43.1</version>
</dependency>
<dependency>
<groupId>org.ejml</groupId>
<artifactId>ejml-fdense</artifactId>
<version>0.43.1</version>
</dependency>
<dependency>
<groupId>org.ejml</groupId>
<artifactId>ejml-zdense</artifactId>
<version>0.43.1</version>
</dependency>
<dependency>
<groupId>org.ejml</groupId>
<artifactId>ejml-simple</artifactId>
<version>0.43.1</version>
</dependency>
</dependencies>
</project>
src/main/java/module-info.java
module mwe {
requires ejml.all;
requires ejml.core;
requires ejml.cdense;
requires ejml.ddense;
requires ejml.fdense;
requires ejml.zdense;
requires ejml.simple;
exports mwe;
}
src/main/java/mwe/Main.java
package mwe;
import org.ejml.data.DenseMatrix64F;
import org.ejml.ops.CommonOps;
public class Main {
public static void main(String[] args) {
double[][] aArray = new double[][] {
{1, 1},
{1, 2}
};
DenseMatrix64F a = new DenseMatrix64F(aArray);
DenseMatrix64F t = new DenseMatrix64F(2, 2);
CommonOps.invert(a, t);
}
}
The error messages that I can't get rid of start by stating that the imports cannot be resolved, and as a consequence I also get error messages on the lines where I use this classes stating that they cannot be resolved to a type.
I've tried various variants (e.g. only having ejml-all
as a dependecy), but the error messages remain. I don't even know if this is actually fixable without rebuilding the library to include module info, but since I am not the owner of EJML, I don't think that is the ideal way to solve this.
Am I missing something? Is there an easy solution? Is this merely an issue of using Visual Studio Code, or will this also be the case with other editors?
I haven't used ejml. I think you don't have to create the module-info.java. And the ejml replaced DenseMatrix64F with DMatrixRMaj. You can try like this:
double[][] aArray = new double[][]{
{1, 1},
{1, 2}
};
DMatrixRMaj a = new DMatrixRMaj(aArray);
DMatrixRMaj b = new DMatrixRMaj(2, 2);
CommonOps_DDRM.invert(a, b);