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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:43:48+00:00 2026-06-15T07:43:48+00:00

So, java has a built in library dedicated for compiling java source code into

  • 0

So, java has a built in library dedicated for compiling java source code into .class files, and it is in javax.tools. So, I was wondering how exactly you get it to work. I’ve read through the javadoc, and it gives some examples in there, but when I use those examples, I get errors.

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);

That is the example oracle gives in order to get an instance of the StandardJavaFileManager class from which you can do much more. However, I’m having some issues with the very first line of that code. When I attempt to do ToolProvider.getSystemJavaCompiler();, it always returns null. In the javadocs for that method, it says, “returns the compiler provided with this platform or null if no compiler is provided.” But they never show any other way of getting an instance of a JavaCompiler. I’ve tried many other ways, such as using a ServiceLoader to find any reference of it that I could, but to no prevail. How might I go about getting this to work?

  • 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-15T07:43:49+00:00Added an answer on June 15, 2026 at 7:43 am

    Chances are you’re running Java from a JRE directory instead of a JDK directory – you need to run a version which “knows” where the Java compiler is.

    So for example, on my Windows boxing, running a tiny test app like this:

    import javax.tools.*;
    
    class Test {
        public static void main(String[] args) {
            JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
            System.out.println(compiler);
        }
    }
    

    The results are:

    c:\Users\Jon\Test>"\Program Files\Java\jdk1.7.0_09"\bin\java Test
    com.sun.tools.javac.api.JavacTool@1e0f2f6
    
    c:\Users\Jon\Test>"\Program Files\Java\jre7\bin\java" Test
    null
    

    As you can see, it’s fine when I specifically run the JDK version, but I get null when running the JRE version. Check how you’re starting Java.

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

Sidebar

Related Questions

Does java has library exception class which means actually not an error, but good
Has Java always maintained source-code backward compatibility during its development? More precisely: given two
I have two classes: MyApplication Library The Library has already been compiled into Library.class
My Leopard system has dtrace built in. I also have Java 6 installed, using
I have built a Java application that has some dependencies (~10). I would like
Which static analysis tools for Java has easiest extension mechanism. I checked PMD But
I'm using a Java class library that is in many ways incomplete: there are
I currently have a Java testing library which is built with Maven, and distributed
I use a Java library that has a .xml file embedded, and uses this
During the past few months, I built an open-source tweening engine in Java (

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.