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

  • Home
  • SEARCH
  • 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 6033079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:25:52+00:00 2026-05-23T05:25:52+00:00

In the following code I simply execute test.py from java code using jython public

  • 0

In the following code I simply execute test.py from java code using jython

public static void main(String[] args) {
  org.python.util.PythonInterpreter python = new org.python.util.PythonInterpreter();
  python.execfile("test.py");
  ...

My problem is test.py needs to be in same directory from where jar file is run.
I need this test.py bundled inside the jar and still be able to execute it using jython.

Approach suggested in How do you invoke a python script inside a jar file using python? to read the script in string using getResourceAsStream method from ClassLoader class wont work for me as my test.py imports more python scripts all bundled inside the jar.

Being new to java and jython i’m really confused.
Any help will be highly appreciated..!

  • 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-23T05:25:53+00:00Added an answer on May 23, 2026 at 5:25 am

    You can simply put test.py at the root of the jar, with the other scripts organized as they would be on the fs in normal python.
    Then you can do something like that:

    public static void main(String[] args) {
      org.python.util.PythonInterpreter python = new org.python.util.PythonInterpreter();
      python.exec("import test");
      python.exec("test.callsomthing()");
    }
    

    the import in test.py should work as normal, including importing other modules from test.py.

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

Sidebar

Related Questions

Very simply put, I have the following code snippet: FILE* test = fopen(C:\\core.u, w);
I'm trying to execute the following code but I'm getting an error saying expression:string
For some reason the following code fails. You can't simply erase a reverse_iterator by
I have the following bit of code, simply: $(function() { $('a.add-photos-link').live('click', function(e) { $(this).colorbox({
i am using following code to make an httpPost call but it is returning
I'm trying to schedule a job on a remote scheduler using the following code:
I am having an issue with the following code. The execute function executes not
The following code executes a simple insert command. If it is called 2,000 times
I have used following code to create a simple PDF file. It executes fine
The following code has a simple binding which binds the Text of the TextBlock

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.