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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:22:37+00:00 2026-06-05T08:22:37+00:00

I am new to java and I am following this tutorial as it is

  • 0

I am new to java and I am following this tutorial as it is very informative and explains everything in great detail. At the bottom of the tutorial it explains how a JavaFileManager can be used to compile multiple java files and gives a few examples of this but i still cant get it to compile multiple files myself

Another problem is that in the example it only ever shows how to compile one java file (which i can already get working) but it is the multiple files that i am having a problem with as i want to be able to compile projects made up of multiple java classes in my own system

This is what i have to the moment:

public static void main(String[] args) throws Exception {
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    // Line 1.
    MyDiagnosticListener listener = new MyDiagnosticListener(); // Line 2.
    StandardJavaFileManager fileManager = compiler.getStandardFileManager(
            listener, null, null); // Line 3.
    String fileToCompile = "test" + File.separator + "ManyErrors.java";
    // Line 4
    Iterable fileObjects = fileManager.getJavaFileObjectsFromStrings(Arrays
            .asList(fileToCompile)); // Line 5
    CompilationTask task = compiler.getTask(null, fileManager, listener,
            null, null, fileObjects); // Line 6
    Boolean result = task.call(); // Line 7
    if (result == true) {
        System.out.println("Compilation has succeeded");
    }
}


class MyDiagnosticListener implements DiagnosticListener {
public void report(Diagnostic diagnostic) {
    System.out.println("Code->" + diagnostic.getCode());
    System.out.println("Column Number->" + diagnostic.getColumnNumber());
    System.out.println("End Position->" + diagnostic.getEndPosition());
    System.out.println("Kind->" + diagnostic.getKind());
    System.out.println("Line Number->" + diagnostic.getLineNumber());
    System.out.println("Message->" + diagnostic.getMessage(Locale.ENGLISH));
    System.out.println("Position->" + diagnostic.getPosition());
    System.out.println("Source" + diagnostic.getSource());
    System.out.println("Start Position->" + diagnostic.getStartPosition());
    System.out.println("\n");
}
  • 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-05T08:22:38+00:00Added an answer on June 5, 2026 at 8:22 am

    getJavaFileObjectsFromStrings from StandardJavaFileManager takes an Iterable<String>.

    This means you can just pass it any iterable collection of strings in order to get an Iterable<? extends JavaFileObject>, which in turn is passed to the getTask method of any class that implements the JavaCompiler interface.


    This is not related to the answer, but I’d like to add that you are probably going down the wrong path, if your goal is to familiarize yourself with Java. Procedural compilation of Java classes is a rather advanced topic, and it doesn’t seem you understood the code you posted fully, because the answer to your question is right within it: the Arrays.asList(fileToCompile) call creates an array of strings with exactly one string in it; even without documentation, it should be easy to deduce getJavaFileObjectsFromStrings takes an array of strings corresponding to filenames. So I really wouldn’t try going down that road, but rather, I’d familiarize myself with Java documentation and simpler concepts first. Especially if you are not familiar with OO concepts.

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

Sidebar

Related Questions

I have been following this tutorial and everything was going nice and easy until
I am following this tutorial, I'm using netbeans 6.5.1 http://www.netbeans.org/kb/docs/java/gui-db-custom.html When I get to
Im new to Android and Java development and am following the Tab Layout tutorial
I am following this tutorial: link text Preferences.java: public class Preferences extends PreferenceActivity{ @Override
I am following this tutorial to build my first Java 3D application. I included
I am fairly new to Java programming and was following a tutorial located here:
I am following a starting tutorial for Threading in Java. The code is very
Following a tutorial on the internet regarding Soap development with Java, I found this
When creating a new Java project in IntelliJ IDEA, the following directories and files
I have the following code adding an ActionListener to a JTextField: chatInput.addMouseListener(new java.awt.event.MouseAdapter() {

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.