First, you're right that Jython is Python running in the JVM. And it's not just running in the JVM, it can interact with it in pretty much all the ways you want—use Java classes as Python classes, implement Java interfaces in a Python class and pass it to Java code, etc.

However, unlike some of the other JVM languages, Jython doesn't make any attempt to be semantically equivalent to Java (or to a superset of it). And of course Python and Java have very different idiomatic styles.

So, in short, just about anything is possible, but not everything is pleasant, as Marcin says.

For specifics about how Spring works with Jython, a quick Google search turned up See how Spring Python works with Jython. And in fact, it's part of a blog called "Spring Python", which is part of a site also called "Spring Python". It seems like this may be a port of Spring to Python rather than about using Jython with Spring. ("This project takes the concepts of Spring and applies it to the language and environment of Python. This includes pragmatic libraries and useful abstractions that quickly gets you back to working on the code that makes you money.") So, that might be another alternative for you.

The next search result was Jython Spring MVC Controllers.

And there were half a dozen other promising results. So, I think you'll have no problem finding information and examples.

Answer from abarnert on Stack Overflow
🌐
GitHub
github.com › amemifra › Spring-Jython
GitHub - amemifra/Spring-Jython: Java integration of Python script and classes into a Spring Boot Web Application. Powered by Jython · GitHub
Java integration of Python script and classes into a Spring Boot Web Application. Powered by Jython - amemifra/Spring-Jython
Starred by 12 users
Forked by 11 users
Languages   Python 99.3% | Java 0.7%
🌐
Dreamix
dreamix.eu › home › insights › tech › how to use jython with spring boot
How to use Jython with Spring Boot - Dreamix
July 16, 2024 - Whatever the reason, there is an easy way to achieve that by using Jython – the JVM implementation for the python language. It fully covers the python language and has the pip module manager. From my experience working in an bespoke development company, Spring is the de facto standard for enterprise applications in the recent years and by using interfaces and dependency injection we can seamlessly integrate our code with the existing java codebase.
Discussions

java - Including Python Script in Spring Boot Application with Jython fails - module not found - Stack Overflow
I am trying to get used to python+java ... script from my Spring Boot Application. That script is located in the (relative from the .java-file) path /scripts_py/getStockPrice.py that contains the getStockPrice-method (see code below). So I integrated jython and tried to execute ... More on stackoverflow.com
🌐 stackoverflow.com
April 26, 2020
jetty - Jython module not found when packaged with Spring Boot? - Stack Overflow
I am working on a side project using Spring Boot, Jython and Pygments with Maven and am getting an odd error when trying to launch the application after the Maven packaging step. Launching within... More on stackoverflow.com
🌐 stackoverflow.com
Simplifying Web Development: Jython, Spring and Velocity
There has been a lot of discussion around the points: "Web development is unnecessarily verbose with Java throughout", and "Scripting languages are more applicable for some of this development". Thomas Risberg shows us his experiment with Jython, Spring, and Velocity. More on theserverside.com
🌐 theserverside.com
jython 2.7 - Where to put python module in spring boot application using Jython2.7? - Stack Overflow
I am using the Spring boot for an Java application and I want to put a python module my_module.py in the the app. I am trying to import the module like interpretor.exec("import my_impodule") But I... More on stackoverflow.com
🌐 stackoverflow.com
April 28, 2016
Top answer
1 of 1
2

I was able to run your program partially using Jython - I couldn't get the stock process from yahoo which is internally depends on numpy and looks like Jython doesn't support numpy as it being cpython library.

private void initScript() { 
    PythonInterpreter interpreter = new PythonInterpreter(); 
    String fileUrlPath = "/users/sagar/demo/src/main/resources/python"; 
    interpreter.exec("import sys"); 
    interpreter.exec("sys.path.append('" + fileUrlPath + "')"); 
    interpreter.exec("from getStockPrice import *"); this.func_getPriceForTicker = 
    interpreter.get("getStockPrice", PyFunction.class); 
    interpreter.close(); 
}

You will be able to get past your error but you will see error

Missing required dependencies ['numpy'] 

So I tried using another java python library jep and made changes as follow

@SpringBootApplication
@EnableScheduling
public class DemoApplication  {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    private final Logger logger = LoggerFactory.getLogger(DemoApplication.class);

    //call every 5 sec
    @Scheduled(fixedRate = 5000)
    public void initStockPriceAPICall() throws JepException {
        this.getStockPrice("NFLX");
    }

    private void getStockPrice(String ticker) throws JepException {
        try (Interpreter interp = new SharedInterpreter()) {
            String fileUrlPath = "/users/sagar/demo/src/main/resources/python";
            interp.exec("import sys");
            interp.exec("sys.path.append('" + fileUrlPath + "')");
            interp.exec("from getStockPrice import *");
            interp.set("ticker", ticker);
            interp.exec("price = getStockPrice(ticker)");
            Object result = interp.getValue("price");
            logger.info("Price is " + result);
        }
    }
}

pom.xml

<dependency>
    <groupId>black.ninia</groupId>
    <artifactId>jep</artifactId>
    <version>3.9.0</version>
</dependency>

Make sure to install jep module - it has native library

pip install jeb

Add java library path to load native library

-Djava.library.path=/usr/local/lib/python2.7/site-packages/jep

Reference - https://github.com/ninia/jep/wiki/Getting-Started

🌐
GitHub
github.com › amemifra › Spring-Jython › blob › master › pom.xml
Spring-Jython/pom.xml at master · amemifra/Spring-Jython
Java integration of Python script and classes into a Spring Boot Web Application. Powered by Jython - Spring-Jython/pom.xml at master · amemifra/Spring-Jython
Author   amemifra
Top answer
1 of 2
5

Spring boot already has a mechanism for this: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html#howto-extract-specific-libraries-when-an-executable-jar-runs

84.6 Extract specific libraries when an executable jar runs Most nested libraries in an executable jar do not need to be unpacked in order to run, however, certain libraries can have problems. For example, JRuby includes its own nested jar support which assumes that the jruby-complete.jar is always directly available as a file in its own right.

To deal with any problematic libraries, you can flag that specific nested jars should be automatically unpacked to the ‘temp folder’ when the executable jar first runs.

For example, to indicate that JRuby should be flagged for unpack using the Maven Plugin you would add the following configuration:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <requiresUnpack>
                    <dependency>
                        <groupId>org.jruby</groupId>
                        <artifactId>jruby-complete</artifactId>
                    </dependency>
                </requiresUnpack>
            </configuration>
        </plugin>
    </plugins>
</build>

And to do that same with Gradle:

springBoot  {
    requiresUnpack = ['org.jruby:jruby-complete']
}

In the case of jython you will use org.python:jython-standalone

2 of 2
0

I have had similar problem and this is how I have solved it in a not so elegant way. First of all I packaged jython distribution's python libraries ( Lib directory ) as a zip-file into my project into the resources.

In spring class I reference it:

private org.springframework.core.io.Resource jython = new ClassPathResource("lib.zip");

And then in the code write it out from the spring boot jar into a temp zipfile:

    Path jythonTempFile = Files.createTempFile(null, "lib.zip");
    jythonTempFile.toFile().deleteOnExit();

    InputStream jythonInputStream = jython.getInputStream();
    Files.copy(jythonInputStream, jythonTempFile, StandardCopyOption.REPLACE_EXISTING);

    String jythonPath = jythonTempFile.toFile().getAbsolutePath();

Then path to that tempfile is used when setting up the Python interpreter:

    PythonInterpreter interp = new PythonInterpreter();
    interp.exec("sys.path.append('" + jythonPath + "')");

This way you can also add other classes and python libraries into your Jython interpreter.

Why is this not elegant? Now those libraries are twice inside the spring boot application, once in the jython.jar and once as a zip.

I did not have time to figure out way to get a reference into the jython libraries inside boot in bullet proof way otherwise.

🌐
GitHub
github.com › amemifra › Spring-Jython › blob › master › README.md
Spring-Jython/README.md at master · amemifra/Spring-Jython
Java integration of Python script and classes into a Spring Boot Web Application. Powered by Jython - amemifra/Spring-Jython
Author   amemifra
🌐
Quora
quora.com › How-do-you-use-Jython-with-Spring-Boot
How to use Jython with Spring Boot - Quora
Answer: using execFile from PythonInterpreter class HelloService { @Override public HelloService getObject() throws Exception { //The python classpath is usually set by environment variable //or included in the java project classpath but it can also be set // programmatically. Here I hard co...
Find elsewhere
🌐
Baeldung
baeldung.com › home › java › how to call python from java
How to Call Python From Java | Baeldung
August 27, 2025 - We then use the getEngineByName method of the ScriptEngineManager class to look up and create a ScriptEngine for a given short name. In our case, we can pass python or jython which are the two short names associated with this engine.
🌐
TheServerSide
theserverside.com › discussions › thread › 25373.html
Simplifying Web Development: Jython, Spring and Velocity
So I figured out how to load a WebApplicationContext using a Jython servlet. Then I added Velocity to handle the view part. This combination makes for pretty easy coding for the controller and this would be extremely helpful for applications that are not terribly complex. The nice thing with using Spring for the data access layer is that there is no need to manage any database connections in your scripts.
🌐
GitHub
github.com › rotsenmarcello › jython-annotation-tools
GitHub - rotsenmarcello/jython-annotation-tools: Jython Annotation Tools is a library that enables the use of native Java annotations in Jython scripts and SpringFramework integration for Jython object instances.
Jython Annotation Tools is a JAVA-Library that enables the use of native Java annotations in Jython scripts and, additionally, offers some basic support for integration of Jython objects as beans in a SpringFramework context.
Author   rotsenmarcello
🌐
Jython
jython.org
Home | Jython
The Jython project provides implementations of Python in Java, providing to Python the benefits of running on the JVM and access to classes written in Java. The current release (a Jython 2.7.x) only supports Python 2 (sorry). There is work towards a Python 3 in the project’s GitHub repository ...
🌐
DZone
dzone.com › coding › java › embed jython to your java codebase
Embed Jython to Your Java Codebase
October 20, 2016 - group 'com.gkatzioura' version '1.0-SNAPSHOT' apply plugin: 'java' sourceCompatibility = 1.5 repositories { mavenCentral() } dependencies { testCompile group: 'junit', name: 'junit', version: '4.11' compile group: 'org.python', name: 'jython-standalone', version: '2.7.0' }
🌐
Reddit
reddit.com › r/javahelp › running python script with webapp with spring boot backend
r/javahelp on Reddit: Running Python Script with WebApp with Spring Boot Backend
December 4, 2024 -

Hello everyone.. i want to ask is it possible to add a python script like this?

I have a functional spring boot + react app for users and they already using it. But they have a new change request to add a button to download the file as an excel with templates and data was fetch from the db. My friend help me by building a python script to generate this file (since we think python is good for working with data)

Is it possible to add a button in my react front end to run the python script and download the data as excel?

Top answer
1 of 2
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2 of 2
1
JYthon is a Java implementation of python 2.7. Beyond that, you're into executing an external process from your Spring backend. https://www.baeldung.com/java-process-api Either way is probably a lot more hassle than simply re-writing that Python in Java. I guess a third approach would be to turn that python script into a web app using Flask or something, and have your Spring backend call it. But it's all a lot of fuss, with you now having to manage failure modes which simply wouldn't happen if it was all done in-process. Having some Java do it natively in the Spring backend is far simpler. Apache POI makes working with Excel easier, and I think there are other libraries around.
🌐
GitHub
github.com › topics › jython
jython · GitHub Topics · GitHub
JPyxie is a Java integration for executing Python scripts efficiently, with support for REST, gRPC, Process API, JEP, Jython, and GraalPy. The project goal is to make Python integration as easy as it is able to be. Also, there is integration with the Spring ecosystem.
🌐
ITNEXT
itnext.io › how-to-integrate-spring-boot-with-numpy-python-using-graalpy-abced925a6b8
How to Integrate Spring Boot with NumPy (Python) Using GraalPy | by Ivan Franchin | ITNEXT
June 4, 2025 - Jython is a well-known project, but it only supports Python 2.7 and doesn’t work with modern Python libraries like NumPy, which require Python 3 and native code support. That’s why GraalPy is a game-changer — it lets you use up-to-date Python libraries directly in your Java application. In this tutorial, we will demonstrate, step by step, how to create a REST endpoint in a Spring Boot application that receives two matrices.
🌐
GitHub
github.com › maksymuimanov › jpyxie
GitHub - maksymuimanov/jpyxie: JPyxie is a Java integration for executing Python scripts efficiently, with support for REST, gRPC, Process API, JEP, Jython, and GraalPy. The project goal is to make Python integration as easy as it is able to be. Also, there is integration with the Spring ecosystem. · GitHub
JPyxie is a Java integration for executing Python scripts efficiently, with support for REST, gRPC, Process API, JEP, Jython, and GraalPy. The project goal is to make Python integration as easy as it is able to be. Also, there is integration with the Spring ecosystem. - maksymuimanov/jpyxie
Author   maksymuimanov
🌐
GitHub
github.com › h4ck3rm1k3 › spring-batch-jython
GitHub - h4ck3rm1k3/spring-batch-jython: be able to implement a spring batch job in python
be able to implement a spring batch job in python. Contribute to h4ck3rm1k3/spring-batch-jython development by creating an account on GitHub.
Forked by 3 users
Languages   Java 55.7% | XML 19.8% | Python 12.5% | Makefile 12.0% | Java 55.7% | XML 19.8% | Python 12.5% | Makefile 12.0%