Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6041243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:37:59+00:00 2026-05-23T06:37:59+00:00

I wanted to boot up a Jython interpreter inside the plugin, then execute files

  • 0

I wanted to boot up a Jython interpreter inside the plugin, then execute files inside the interpreter.

package com.jakob.jython;

import org.bukkit.plugin.java.JavaPlugin;
import org.python.core.PyObject;
import org.python.util.PythonInterpreter;

import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Logger;

public class EmbeddedJython extends JavaPlugin {

    private static final Logger log = Logger.getLogger("Minecraft");
    private PythonInterpreter interpreter;
    private PyObject plugin;


    public void onEnable() {
        log.info("JythonTest enabled");
        this.interpreter = new PythonInterpreter();
        log.info("Jython interpreter fired up and cooking on gas");

        log.info("Loading Python Plugin");

        InputStream pythonScript = EmbeddedJython.class.getResourceAsStream("MyPlugin.py");
        this.interpreter.execfile(pythonScript, "MyPlugin.py");

        log.info("Getting plg method.");
        this.plugin = this.interpreter.get("plg");
        log.info("Plugin loaded");
        log.info(plugin.invoke("onEnable").toString());
    }

    public void onDisable() {
        log.info(plugin.invoke("onDisable").toString());
        log.info("Jython disabled");
    }

}

In other tests I can get the Jython interpreter up and running strings I hand it but when I use the above snippet I end up with an exception that looks something like this:

11:03:38 [SEVERE] Error occurred while enabling JythonTest v0.12 (Is it up to da
te?): null
java.io.IOException: Stream closed
        at java.io.BufferedInputStream.getInIfOpen(Unknown Source)
        at java.io.BufferedInputStream.fill(Unknown Source)
        at java.io.BufferedInputStream.read(Unknown Source)
        at org.python.core.ParserFacade.adjustForBOM(ParserFacade.java:371)
        at org.python.core.ParserFacade.prepBufReader(ParserFacade.java:298)
        at org.python.core.ParserFacade.prepBufReader(ParserFacade.java:288)
        at org.python.core.ParserFacade.parse(ParserFacade.java:183)
        at org.python.core.Py.compile_flags(Py.java:1717)
        at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:235
)
        at com.jakob.jython.EmbeddedJython.onEnable(EmbeddedJython.java:26)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:125)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
.java:750)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
r.java:253)
        at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:132)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:110)
        at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:218)
        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:205)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:145)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:265)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:394)

java.io.IOException: java.io.IOException: Stream closed

        at org.python.core.PyException.fillInStackTrace(PyException.java:70)
        at java.lang.Throwable.<init>(Throwable.java:181)
        at java.lang.Exception.<init>(Unknown Source)
        at java.lang.RuntimeException.<init>(Unknown Source)
        at org.python.core.PyException.<init>(PyException.java:46)
        at org.python.core.PyException.<init>(PyException.java:43)
        at org.python.core.Py.JavaError(Py.java:481)
        at org.python.core.ParserFacade.fixParseError(ParserFacade.java:104)
        at org.python.core.ParserFacade.parse(ParserFacade.java:186)
        at org.python.core.Py.compile_flags(Py.java:1717)
        at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:235
)
        at com.jakob.jython.EmbeddedJython.onEnable(EmbeddedJython.java:26)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:125)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
.java:750)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
r.java:253)
        at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:132)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:110)
        at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:218)
        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:205)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:145)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:265)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:394)
Caused by: java.io.IOException: Stream closed
        at java.io.BufferedInputStream.getInIfOpen(Unknown Source)
        at java.io.BufferedInputStream.fill(Unknown Source)
        at java.io.BufferedInputStream.read(Unknown Source)
        at org.python.core.ParserFacade.adjustForBOM(ParserFacade.java:371)
        at org.python.core.ParserFacade.prepBufReader(ParserFacade.java:298)
        at org.python.core.ParserFacade.prepBufReader(ParserFacade.java:288)
        at org.python.core.ParserFacade.parse(ParserFacade.java:183)
        ... 13 more

Could it be I’m using execfile wrong?
Or is it an error or something I’m missing in how InputStream works?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:38:00+00:00Added an answer on May 23, 2026 at 6:38 am

    Are you sure that EmbeddedJython.class.getResourceAsStream("MyPlugin.py"); is finding the resource?

    If it can’t find the resource, getResourceAsStream will return a null, and it is possible that the Jython interpreter will treat that as an empty (closed) stream.

    Your application should probably check this, rather than assuming that getResourceAsStream has succeeded.


    If I private File pythonFile = new File('MyScirpt.py'); and then hand getResourceAsStream(pythonFile.getAbsolutePath());

    That won’t work. The getResourceAsStream method looks for resources on the classloader’s classpath, and expects a path that can be resolved relative to some entry on the classpath.

    You probably want to do this:

    private File pythonFile = new File('MyScirpt.py');
    InputStream is = new FileInputStream(pythonFile);
    

    and pass the is to the interpreter. You also need to arrange that the stream is always closed when the interpreter has finished … by whatever mechanism that happens.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to show the users Name Address (see www.ipchicken.com ), but the only
Is there any dialog that running inside a TTY or x-terminal ? I wanted
I wanted to include the facebook login inside my application. This is the sample
I wanted to update my layout from <?xml version=1.0 encoding=utf-8?> <TextView xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent
wanted a solution on how to access the javascript variable inside the java scope.
I wanted to inquire what the difference was between the default.properties and project.properties files
Wanted to convert <br/> <br/> <br/> <br/> <br/> into <br/>
Wanted to get some consensus around a UI feature I'm working on right now.
Wanted to know if someone had a suggestion on code or maybe there's a
I wanted some of those spiffy rounded corners for a web project that I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.