The ability to load Java classes into MATLAB based on a Maven <dependency> definition is not available in MATLAB R2020b. You can however actually use Maven itself outside of MATLAB to have it download all dependencies for you or possibly even package the main Java package and all its dependencies into a single JAR-file which can then be added to MATLAB.
Download all dependencies
1. Download/Install Maven (and its dependencies like a supported JDK if needed), see:
https://maven.apache.org/
2. Create a pom.xml file for your "project", for example:
<?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>com.example</groupId>
<artifactId>myProject</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>msal4j</artifactId>
<version>1.8.1</version>
</dependency> </dependencies>
</project>
Where you can further customize the properties of this project itself (although they are not really relevant in this workflow):\n
<groupId>com.example</groupId>
<artifactId>myProject</artifactId>
<version>1.0.0</version>
And you customize the <dependencies> to actually refer to the Java package which you want to load into MATLAB, in this example we refer to Microsoft's MSAL4J package:\n
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>msal4j</artifactId>
<version>1.8.1</version>
</dependency>
3. Now in the directory where you created your pom.xml run Maven's copy-dependencies command of the dependency plugin:\n
mvn dependency:copy-dependencies -DoutputDirectory=deps
Which will download all the dependencies into a directory named "deps". You can now add all the downloaded JAR-files to MATLAB's Java classpath.
Package the Java classes and all its dependencies into a single JAR
1. Download/Install Maven (and its dependencies like a supported JDK if needed), see:
https://maven.apache.org/
2. Create a pom.xml file for your "project", for example:
<?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>com.example</groupId>
<artifactId>msal4j</artifactId>
<version>1.8.1</version>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>msal4j</artifactId>
<version>1.8.1</version>
</dependency> </dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
Where you can further customize the properties of this project itself (this will influence the name of the JAR-file which is produced):\n
<groupId>com.example</groupId>
<artifactId>myProject</artifactId>
<version>1.0.0</version>
And you customize the <dependencies> to actually refer to the Java package which you want to load into MATLAB, in this example we refer to Microsoft's MSAL4J package:\n
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>msal4j</artifactId>
<version>1.8.1</version>
</dependency>
3. Now in the directory where you created your pom.xml run:\n
mvn clean assembly:single
Which will download all the dependencies, clean the project and then assemble all relevant classes into a single JAR-file. You can then add this JAR-file to your MATLAB Java classpath.
Best Answer