Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how a Jython script can be run using JBang #1926

Open
wfouche opened this issue Feb 10, 2025 · 0 comments · May be fixed by #1927
Open

Document how a Jython script can be run using JBang #1926

wfouche opened this issue Feb 10, 2025 · 0 comments · May be fixed by #1927

Comments

@wfouche
Copy link
Contributor

wfouche commented Feb 10, 2025

Jython scripts occasionally require JAR files from Maven Central. Unlike Groovy, Jython lacks a built-in mechanism to resolve these dependencies. However, you 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.

Create fiie Jython.java and add all required DEPS to it.

///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);
    }

}

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)

Running test.py

$ jbang run Jython.java test.py

Output

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant