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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:03:02+00:00 2026-05-31T06:03:02+00:00

Today I asked many questions about Jars & JavaCompiler. Because I haven’t been able

  • 0

Today I asked many questions about Jars & JavaCompiler.
Because I haven’t been able to achieve my goal I’ll ask the whole question now:

I want a ProgramOne.jar which compiles a class out of a file and than loads this class.

Somehow I can’t achieve that with the approach which works in Eclipse (the ProgramOne not packed into a Jar).

So the approach which works in eclipse is:

File fRun = new File("someFile.java");
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
Iterable<String> options = Arrays.asList( new String[] { "-d", currentDir+"\\bin\\"} );
Iterable<? extends JavaFileObject> compUnits =  fileManager.getJavaFileObjects(fRun);
Boolean compRes = compiler.getTask(null, fileManager, null, options, null, compUnits).call();           

if(compRes == true){
    System.out.println("Compilation has succeeded");
    fileManager.close();
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Class<?> compiledClass = cl.loadClass(someFile);
    cRun = compiledClass;
}else{
    System.out.println("Compilation error");
    fileManager.close();
    throw new Exception("Compilation Error");
}

This creates the class file in the folder <...>/ProgramOne/bin and then loads the class

How can I achieve that with the packed ProgramOne.jar?

  • 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-31T06:03:03+00:00Added an answer on May 31, 2026 at 6:03 am

    If I understand what you’re trying to do, you’ll need to programmatically recreate your ProgramOne.jar file.

    So:

    java -jar ProgramOne.jar foo.java

    1) ProgramOne.jar compiles foo.java

    2) ProgramOne.jar reassembles itself to include foo.class

    3) ProgramOne.jar executes foo.class

    See here for one example of jar file creation.

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

Sidebar

Related Questions

a client asked me today about having users be able to have their own
I just asked a question earlier today because I wanted to run an executable
Earlier today, I asked a question about the way Python handles certain kinds of
Hi I asked a question today about How to insert different types of objects
I've asked here a ton of questions about WSAAsyncSelect and NET.Few months ago I
I have used try-catch/except-finally variants in many languages for years, today someone asked me
Someone asked about Lazy Binary Searches today. Not knowing what that was, I looked
Earlier today I asked a question about configuring log4net from code and got an
Today I was asked about smart pointers in C++, and I can't find anywhere
I can see this question has been asked many times before, but I just

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.