From: Werner F. <wer...@gm...> - 2025-03-09 08:24:45
|
Jython scripts occasionally require access to JAR files from Maven Central. Unlike Groovy, Jython lacks a built-in mechanism to resolve these dependencies. However, one can bootstrap a Jython script along with its Maven dependencies using JBang. This technique ensures that your Jython scripts can seamlessly access the necessary dependencies from Maven Central. See https://www.jbang.dev/ for information about JBang. <Step 1> - create file *Jython.java* with JBang support and required Maven dependencies. ---------- ///usr/bin/env jbang "$0" "$@" ; exit $? //DEPS org.python:jython-standalone:2.7.4 //DEPS io.leego:banana:2.1.0 import org.python.util.jython; public class Jython { public static void main(String... args) { jython.main(args); } } ---------- <Step 2> - create a Jython script (*test.py*) ---------- from __future__ import print_function import io.leego.banana.BananaUtils as BananaUtils import io.leego.banana.Font as Font text0 = "Jython 2.7" text1 = BananaUtils.bananaify(text0, Font.STANDARD) print(text1) ---------- <Step 3> -run the Jython script $ jbang run Jython.java test.py [jbang] Resolving dependencies... [jbang] org.python:jython-standalone:2.7.4 [jbang] io.leego:banana:2.1.0 [jbang] Dependencies resolved [jbang] Building jar for Jython.java... Jython 2.7 # Displayed as banner text Happy Jython scripting! -- Werner Fouché |