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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:51:45+00:00 2026-06-08T23:51:45+00:00

I am making software that will need to dynamically create java bytecode, and possibly

  • 0

I am making software that will need to dynamically create java bytecode, and possibly even make it a runnable jar.

My current idea is to create a new .java file and compile it at runtime. I can create the file, but I’m not sure how to compile it at runtime, and make it a runnable jar. Any help would be greatly appreciated.

public static String generate(String filePath) {
    try {
        File file = new File("Test.java");
        if(!file.exists())file.createNewFile();
        FileWriter write = new FileWriter(filePath+".java");
        BufferedWriter out = new BufferedWriter(write);
        out.write(
                "public class Test {\n\t" +
                    "public static void main(String[] args){\n\t\t"+
                        "System.out.println(\"Working\");\n\t"+
                    "}\n" +
                "}"

                );
        out.close();

    } catch (Exception e) {// Catch exception if any
        return "Error: " + e.getMessage();
    }
    return "Test.java created!";
}
  • 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-08T23:51:48+00:00Added an answer on June 8, 2026 at 11:51 pm

    To compile Java code, you can use the Java Compiler API.

    To generate byte code directly, you can use tools like ASM.

    To generate an executable JAR, create a JarOutputStream with a manifest that declares the main class.

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

Sidebar

Related Questions

I need to create a porting software that will convert Java code to C#
I am making a software that will move files from the downloads folder to
I am currently making a piece of software that will allow the user to
I'm looking into making some software that makes the keyboard function like a piano
I'm looking into making some software that makes the keyboard function like a piano
I'm making a software that tries to restore a database to sql server, but
So I am making a piece of software in WPF, and I want to
I'm making a customer administration software. There are several JPanels with much content on
I'm currently making a front end to display license information for my companies software
Making an adobe flex ui in which data that is calculated must use proprietary

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.