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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:56:07+00:00 2026-06-11T05:56:07+00:00

I am trying to get used to the JavaCompiler and trying to compile programs

  • 0

I am trying to get used to the JavaCompiler and trying to compile programs with it, I can successfully compile programs that comprises of single file but when im trying to compile projects with multiple files. I get errors on compiling files that implement other classes and where ever the class uses a method from the implemented class.

Here is the code that I am using to compile the java code

private final String  directoryForBin = "C:/TempBINfolder/bin";

public List doCompilation(String sourceCode, String locationOfFile) {
   List<String> compile = new ArrayList<>();

    SimpleJavaFileObject fileObject = new DynamicJavaSourceCodeObject(locationOfFile, sourceCode);
    JavaFileObject javaFileObjects[] = new JavaFileObject[]{fileObject};

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

    StandardJavaFileManager stdFileManager = compiler.getStandardFileManager(null, Locale.getDefault(), null);

    Iterable<? extends JavaFileObject> compilationUnits = Arrays.asList(javaFileObjects);

    // creates a Temp BIN foler on the C: drive to add .class files for compiling      
    new File(directoryForBin).mkdirs();

    String[] compileOptions = new String[]{"-d", directoryForBin, "-classpath", System.getProperty("java.class.path")};
    Iterable<String> compilationOptions = Arrays.asList(compileOptions);

    DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();

    CompilationTask compilerTask = compiler.getTask(null, stdFileManager, diagnostics, compilationOptions, null, compilationUnits);

    boolean status = compilerTask.call();

    if (!status) {//If compilation error occurs 
        // Iterate through each compilation problem and print it
        for (Diagnostic diagnostic : diagnostics.getDiagnostics()) { 
            compile.add(diagnostic.getKind().toString()+" on line  "+ diagnostic.getLineNumber() +"\nIn file:  \n"+ diagnostic.toString()+"\n\n");
        }
    }
    try {
        stdFileManager.close();//Close the file manager
    } catch (IOException e) {
        e.printStackTrace();
    }

    return compile;
}

Here is a sample of one of the classes I am trying to compile

    public class IntegerComparator 
             implements Comparator<Integer>
{
   public IntegerComparator(){}

   public int compare(Integer a, Integer b)
   {  int aValue = a.intValue();
      int bValue = b.intValue();
      return (aValue - bValue);
   }

}

Does anybody know what is going wrong here and why my code is not finding the implemented class even though it is in the same folder as that of the class implementing it?

Is it because the package is not located at the top of the program?

EDIT: This is the output error for the above example

ERROR on line  8
In file:  
/projects/Compiler/Studentfilestotest/LAB3/aroc1/a3/IntegerComparator.java:8: error: cannot find symbol
             implements Comparator<Integer>
                        ^
  symbol: class Comparator

This is what System.getProperty("java.class.path") is returning

C:\projects\Compiler\Compiler\Jar Files\jsyntaxpane-0.9.5-b29.jar;
C:\projects\Compiler\Compiler\Jar Files\jtar-1.1.jar;
C:\projects\Compiler\Compiler\Jar Files\sqlitejdbc-v056.jar;
C:\Program Files\NetBeans 7.1.2\java\modules\ext\beansbinding-1.2.1.jar;
C:\Program Files\NetBeans 7.1.2\java\modules\ext\AbsoluteLayout.jar;
C:\projects\Compiler\Compiler\Jar Files\junit-4.11-SNAPSHOT-20120416-1530.jar;
C:\projects\Compiler\Compiler\Jar Files\commons-io-2.4-bin.zip;
C:\projects\Compiler\Compiler\Jar Files\commons-io-2.4\commons-io-2.4.jar;
C:\projects\Compiler\Compiler\Jar Files\poi-3.8\poi-3.8-20120326.jar;
C:\projects\Compiler\Compiler\Jar Files\javamail-1.4.5\mail.jar;
C:\projects\Compiler\Compiler\build\classes
  • 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-11T05:56:08+00:00Added an answer on June 11, 2026 at 5:56 am

    Most likely, this has nothing to do with the compiler. My guess is that this is because of an error in the source file. Did you remember to import the appropriate classes and interfaces?

    Your IntegerComparator.java file needs to contain the import:

    import java.util.Comparator; // <--- Import!
    
    public class IntegerComparator 
          implements Comparator<Integer>{
    
       public IntegerComparator(){}
    
       public int compare(Integer a, Integer b){
          int aValue = a.intValue();
          int bValue = b.intValue();
          return (aValue - bValue);
       }
    }
    

    Forgetting to import appropriate classes often results in the “cannot find symbol” error messages.

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

Sidebar

Related Questions

I am trying to get used to writing object oriented, but often I get
I'm trying to get used to Ember.js and Handlebars, but one problem is puzzling
I am trying to get used to web development and one thing that eluded
That is my question. More specifically, I'm trying to get used to Eclipse's debugger
I normally use scp to copy stuff, but now I'm trying to get used
Trying to get the number of available comports. Used the following code: HKEY hKey;
well iam trying to get version of IE used by user by using $.browser.version
We are trying to get the Model-View-Presenter pattern used on (virtually) all new dev
I am trying to get the likes from a company pages (coca-cola) I used
I'm very new to Scala and I'm still trying to get used to 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.