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 8153855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:09:13+00:00 2026-06-06T16:09:13+00:00

I am a novice programmer in (Java/C++/C#) and I also know Python. I am

  • 0

I am a novice programmer in (Java/C++/C#) and I also know Python. I am trying to create a GameEngine in Java that can call Jython scripts, that have access to methods in the Java engine.

I am clueless as to how to approach this. I have already done weeks of research and nothing has answered my question ; that is:

How can I call methods in my Parent class, from my JythonScript, which is executed by my Parent class?

———————————–UPDATE—————————————————

Okay, The answer here helped me understand some things, but it didn’t solve my problem.
What I was wondering if something such as this would work:

class MyJavaClass
{
    Public MyJavaClass()
    {
        PythonInterpreter interp = new PythonInterpreter;
        interp.execfile("MyJythonScript.py");
        interp.exec("InGameCommand");
    }

    public void SpawnPlayer()
    {}

    public void KillPlayer()
    {}

}

MyJythonScript.py

Def InGameCommand():
    SpawnPlayer()
    KillPlayer()

Is this even possible? There a way to do this?

———————————–UPDATE—————————————————

Location to Jython: “C:\jython2.7a2\jython.jar”
Location to my work: “C:\Documents and Settings\PC\Desktop\Jython*.java”
Location to my local JtyhonJar: “C:\Documents and Settings\PC\Desktop\Jython\jython.jar”

my compiler I wrote:
“@echo off”
“javac -classpath C:\jython2.7a2\jython.jar *.java”
“echo done”
“pause >nul”

now it doesn’t even compile… (I’ve changed little things in my code to see if it changed and it hasn’t!)

  • 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-06-06T16:09:15+00:00Added an answer on June 6, 2026 at 4:09 pm

    Yes, this way is fine, but you can not run python script in constructor method, if so, it will be dead recursive at your code. please see the following code. you run PythonScriptTest class, it will run python script first, then python script will invoke PythonScriptTest.SpawnPlayer() method.

    java code:

    package com.xxx.jython;
    import org.python.core.PyFunction;
    import org.python.util.PythonInterpreter;
    
    public class PythonScriptTest {
    
        public static void main(String[] args) {
            PythonScriptTest f = new PythonScriptTest();
            f.executePythonScript();
        }
    
        public PythonScriptTest(){
        }
    
        public void executePythonScript() {
                PythonInterpreter interpreter = new PythonInterpreter();
                interpreter.execfile("/home/XXX/XXX/util.py");
                PyFunction pyFuntion = (PyFunction) interpreter.get("InGameCommand", PyFunction.class);
    
                pyFuntion.__call__();
        }
    
        public void SpawnPlayer() {
                System.out.println("Run SpawnPlayer method ##################");
        }
    }
    

    Python scripts, named util.py:

    import sys.path as path
    # the following path is eclipse output class dir
    # does not contain java class package path.
    path.append("/home/XXX/XXX/Test/bin")
    from com.xxx.jython import PythonScriptTest
    
    def add(a, b):  
        return a + b  
    
    def InGameCommand():
        myJava = PythonScriptTest()
        myJava.SpawnPlayer()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As a very novice Java programmer, I probably should not mess with that kind
I am a novice programmer when it comes to Java, I have Java:How To
I'm a novice programmer with basic Java experience, and currently learning Python. I've stumbled
I am a novice programmer who mainly uses Java. Recently I have become interested
I am novice PHP programmer and I have created a function that changes an
This is not homework. I am a beginner (novice) java programmer, trying to read
I am a novice programmer in Java. I would like to know how important
I am a novice programmer (I only have been using Java and Matlab for
I am a novice programmer in python. I'm currently constructing a class that parses
I am a novice programmer at best, but I am trying to play a

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.