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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:03:38+00:00 2026-05-12T17:03:38+00:00

I use the class javax.tools.JavaCompiler (jdk6) to compile a source file, but the source

  • 0

I use the class javax.tools.JavaCompiler (jdk6) to compile a source file, but the source file depends on some jar file. How to set the classpath of the javax.tools.JavaCompiler?

  • 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-12T17:03:38+00:00Added an answer on May 12, 2026 at 5:03 pm

    The javax.tools.JavaCompiler#getTask() method takes an options parameter that allows to set compiler options. The following message describes an easy way to set them in order to access the calling program’s classpath:

    You need to configure the standard
    java file manager to know about the
    jar files(s) – you use the compiler
    options argument to do that.

    By default the java compiler object
    only seems to know about the default
    locations for bootclasspath, extdirs
    and endorseddirs directories in terms
    of its classpath.

    You need to add the calling program’s
    current classpath to the java compiler
    instance’s which gets passed on the
    the standard file manager, which will
    then find classes in the jar files.

    Here’s how I do it in the compiler
    wrapper I wrote

    List<String> optionList = new ArrayList<String>();
    // set compiler's classpath to be same as the runtime's
    optionList.addAll(Arrays.asList("-classpath",System.getProperty("java.class.path")));
    
    // any other options you want
    optionList.addAll(Arrays.asList(options));
    
    JavaCompiler.CompilationTask task = compiler.getTask(out,jfm,diagnostics,optionList,null,jfos);
    

    All you’ll need then is to get the proper classpath set when running the calling program.

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

Sidebar

Related Questions

In Java, I use a class in which some fields can be null .
I need a byte buffer class in Java for single-threaded use. I should be
In java a class can implement Iterable which lets you use the foreach() statement
It is good practice to use the main method to test a java/.net class?
Every class that wants to use java.util.logging generally needs to declare a logger like
Is there any tricky way to use Java reserved words as variable, method, class,
I'm trying to use class names to change the color of a link after
Can anyone recommend a ready-to-use class/library compatible with C/C++/MFC/ATL that would parse iCal/vCal/Google calendar
Is it better practice to use class variables, or the session cache in ASP.NET?
Does anybody use the Class Designer much in Visual Studio? I have downloaded the

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.