depresolve - command line tool which helps to manage Java dependencies in your local Maven repository.
You can think of depresolve as something similar to "apt" command for Debian packages (or "pip" command for Python packages). Example:
Resolving artifact org.openpnp:opencv:jar:4.7.0-0 Downloading artifact org.openpnp:opencv:jar:4.7.0-0 from central (https://repo.maven.apache.org/maven2/, default, releases+snapshots) ... /home/ubuntu/.m2/repository/org/openpnp/opencv/4.7.0-0/opencv-4.7.0-0.jar
Supported functionality:
depresolve may be useful for Java scripting (see examples below) as it allows you to use any Java libraries from the Maven Central repository. You don't need to create Maven (or Gradle) project or define pom.xml (or build.gradle). Instead you can focus on writing Java scripts right away.
You can download depresolve from here
Java 11
Download depresolve package and extract it to some folder.
Follow instructions below based on OS you are using. Please note DEPRESOLVE_INSTALL_DIR it is full path to extracted depresolve directory.
Run following command if you use bash:
Or in case you use zsh:
Run cmd.exe and execute following command:
depresolve [ -cp | -classpath ] [ --repo-home <REPO_FOLDER> ] [ --output|--output-links <OUTPUT_FOLDER> ] [--scope <test|compile> ] <ARTIFACT_NAME> [ ... [--scope <test|compile> ] <ARTIFACT_NAME> ]
By default depresolve resolves ARTIFACT_NAME including all its dependencies and downloads them into your Maven local repository.
<groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>
Please note: when using "classifier" the "extension" IS REQUIRED.
Example: "org.apache.maven.resolver:maven-resolver-impl:1.6.2"
With classifier: "com.badlogicgames.gdx:gdx-platform:jar:natives-desktop:1.9.14", since "extension" field is required when using "classifier" here we specify "jar" extension.
/home/ubuntu/.m2/repository/org/apache/commons/commons-lang3/3.8.1/commons-lang3-3.8.1.jar:/home/ ubuntu/.m2/repository/org/apache/maven/resolver/maven-resolver-api/1.6.2/maven-resolver-api-1.6.2.jar: /home/ubuntu/.m2/repository/org/apache/maven/resolver/maven-resolver-impl/1.6.2/maven-resolver-impl-1. 6.2.jar:/home/ubuntu/.m2/repository/org/apache/maven/resolver/maven-resolver-spi/1.6.2/maven-resolver- spi-1.6.2.jar:/home/ubuntu/.m2/repository/org/apache/maven/resolver/maven-resolver-util/1.6.2/maven-re solver-util-1.6.2.jar:/home/ubuntu/.m2/repository/org/slf4j/slf4j-api/1.7.30/slf4j-api-1.7.30.jar
Starting from Java 11 you can activate source-file mode which allows to run single source files without compiling them:
It is a very useful feature which allows you to write scripts in Java.
Let's try to write some scripts which will depend on external libraries (JavaFX and LIBGDX) and see how depresolve can help to manage these dependecies.
This example demonstrates how you can use depresolve to run a Java script which has a dependency on JavaFX without downloading it or creating pom.xml (or build.gradle) files.
Copy script below to the file javafx-demo.java and save it.
import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.shape.Circle; import javafx.stage.Stage; public class MyApp extends Application { public void start(Stage stage) { Circle circ = new Circle(40, 40, 30); Group root = new Group(circ); Scene scene = new Scene(root, 400, 300); stage.setTitle("My JavaFX Application"); stage.setScene(scene); stage.show(); } public static void main(String[] args) { Application.launch(MyApp.class, args); } }
This script is taken from JavaFX documentation.
Now you can run it like:
As you see we call depresolve with option -cp which will resolve all JavaFX packages from your local repository to the classpath string. If some of the packages are missing then it will download them from Central repository to your local one.
In Windows command line you cannot use $() expression so it will not work. There are 2 ways how to overcome it:
and copy its output to CLASSPATH variable manually:
Now let's create Java script for LibGDX sample code. The steps are similar except here we will need to specify a classifier in the name of the gdx-platform artifact to chose the platform where we will run the script (in our case it is desktop).
Copy script below to the file libgdx.java and save it.
import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; public class DesktopLauncher { public static void main (String[] arg) { LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); new LwjglApplication(new HelloWorld(), config); } } public class HelloWorld extends ApplicationAdapter { ShapeRenderer shapeRenderer; @Override public void create () { shapeRenderer = new ShapeRenderer(); } @Override public void render () { Gdx.gl.glClearColor(.25f, .25f, .25f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); shapeRenderer.setColor(0, 1, 0, 1); shapeRenderer.circle(200, 100, 75); shapeRenderer.end(); } @Override public void dispose () { shapeRenderer.dispose(); } }
If you running Linux:
If you running Windows:
You should see something like:
In this example we will run jshell (Java interactive code evaluator) and call some APIs from Deep Java Library without installing or downloading it manually.
In particular we will create NDArray with 2x2 dimension.
| Welcome to JShell -- Version 11.0.2 | For an introduction type: /help intro jshell> import ai.djl.ndarray.*; jshell> import ai.djl.ndarray.types.*; jshell> var a = NDManager.newBaseManager().create(new Shape(2,2)); SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. a ==> ND: (2, 2) cpu() float32 [[-1.08421872e-19, 4.56 ... e-19, 4.56921390e-41], ] jshell> System.out.println(a) ND: (2, 2) cpu() float32 [[-1.08421872e-19, 4.56921390e-41], [-1.08421872e-19, 4.56921390e-41], ] jshell>
First use depresolve to get a classpath string:
Copy it to CLASSPATH variable:
And run jshell:
| Welcome to JShell -- Version 11.0.2 | For an introduction type: /help intro jshell> import ai.djl.ndarray.*; jshell> import ai.djl.ndarray.types.*; jshell> var a = NDManager.newBaseManager().create(new Shape(2,2)); SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. a ==> ND: (2, 2) cpu() float32 [[ 1.63227305e+22, 1.2 ... 31, -5.23924592e+16], ] jshell> System.out.println(a) ND: (2, 2) cpu() float32 [[ 1.63227305e+22, 1.23936011e+33], [-1.89369072e-31, -5.23924592e+16], ]
This will download following artifacts:
with all their dependencies to djl folder:
api-0.10.0.jar jna-5.3.0.jar xz-1.8.jar commons-compress-1.20.jar mxnet-engine-0.10.0.jar zstd-jni-1.4.4-7.jar dec-0.1.2.jar mxnet-native-auto-1.7.0-b.jar gson-2.8.6.jar slf4j-api-1.7.30.jar