0

I am using JavaCompiler to compile Java code at runtime. For most part, it works well. There are no exceptions during compiling, it works well. I require it to compile a class with @Entity annotation. However, I keep getting "Error in line 3 - class, interface, or enum expected".

This is my entity class:

@Entity
public class Contact {
    @Getter @Setter
    private String FirstName;

    @Getter @Setter
    private String LastName;
}

This is how I am using JavaCompiler to compile it:

List<String> optionList = new ArrayList<String>();
            optionList.add("-classpath");
            optionList.add(System.getProperty("java.class.path"));

Iterable<? extends JavaFileObject> compilationUnit
                    = fileManager.getJavaFileObjectsFromFiles(Arrays.asList(newClassFile));
JavaCompiler.CompilationTask task = compiler.getTask(
                    null,
                    fileManager,
                    diagnostics,
                    optionList,
                    null,
                    compilationUnit);
2

1 Answer 1

0

Solved. Looks like I just had to add the persistence api jar while building.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.