Community
Participate
Working Groups
When I run headless and execute the following code, a NullPointerException is thrown by JavaCore.getDefaultOptions() via the call to AST.parseCompilationUnit (). public static void main(String[] args) throws Exception { String line = null; StringBuffer buffer = new StringBuffer(); BufferedReader bufferedReader = new BufferedReader(new FileReader("C:\\Projects5.1 \\JDTParser\\ClassToParse.java")); while((line = bufferedReader.readLine()) != null) { buffer.append(line); } try { AST.parseCompilationUnit(buffer.toString().toCharArray()); } catch(Exception e) { e.printStackTrace(); } } Here is the output from execution: C:\Projects5.1\JDTParser>runant -buildfile example.xml C:\Projects5.1\JDTParser>echo off C:\Projects5.1\JDTParser>"C:\Program Files\IBM\WebSphere Studio\Application Deve loper\v5.1.1\eclipse\jre\bin\java" -cp "C:\Program Files\IBM\WebSphere Studio\A pplication Developer\v5.1.1\eclipse\startup.jar" org.eclipse.core.launcher.Main -application com.ibm.etools.j2ee.ant.RunAnt -data c:\projects5.1\jdtparser -buil dfile example.xml HeadlessWorkspaceSettings: INITIAL autoBuild=true maxFile=1048576 HeadlessWorkspaceSettings: TEMP autoBuild=false maxFile=-1 HeadlessWebProjectSettings: HeadlessWebProjectSettings save bypassed (no project s in workspace) Buildfile: example.xml RunTestClass: [java] java.lang.NullPointerException [java] at org.eclipse.jdt.core.JavaCore.getDefaultOptions(JavaCore.java :1545) [java] at org.eclipse.jdt.core.dom.AST.<init>(AST.java:90) [java] at org.eclipse.jdt.core.dom.AST.parseCompilationUnit(AST.java:53 6) [java] at TestClass.main(TestClass.java:44) [java] at java.lang.reflect.Method.invoke(Native Method) [java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.jav a:208) [java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava .java:150) [java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:443) [java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:163) [java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108) [java] at org.apache.tools.ant.Task.perform(Task.java:341) [java] at org.apache.tools.ant.Target.execute(Target.java:309) [java] at org.apache.tools.ant.Target.performTasks(Target.java:336) [java] at org.apache.tools.ant.Project.executeTarget(Project.java:1339) [java] at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(Inter nalAntRunner.java:571) [java] at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(Inter nalAntRunner.java:493) [java] at java.lang.reflect.Method.invoke(Native Method) [java] at org.eclipse.ant.core.AntRunner.run(AntRunner.java:464) [java] at com.ibm.ant.extras.RunAnt.run(RunAnt.java:27) [java] at org.eclipse.core.internal.boot.InternalBootLoader.run(Interna lBootLoader.java:858) [java] at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461) [java] at java.lang.reflect.Method.invoke(Native Method) [java] at org.eclipse.core.launcher.Main.basicRun(Main.java:291) [java] at org.eclipse.core.launcher.Main.run(Main.java:747) [java] at org.eclipse.core.launcher.Main.main(Main.java:583) BUILD SUCCESSFUL BUILD SUCCESSFUL Total time: 3 seconds HeadlessWebProjectSettings: HeadlessWebProjectSettings restore bypassed (linksBu ilderCommand was never saved)
*** This bug has been marked as a duplicate of 75969 ***
As now you're running in headless mode this is obviously not a duplicate, I've read it too quickly, sorry for that. In fact it would have been less confusing to reopen bug 75969...
I think you need to define a plugin that requires jdt.core. Move to Platform/Ant for comments.
Running a simple Java program via Ant through headless Eclipse will not correctly configure the JDT core plugin. JDT is not initialized or even used except by your code in this case. The plugin lifecycle methods will not be called and result in the NullPointerException. One way to succeed is to create an Ant task. In the execute() method of your Ant task have the code you currently have in main(String[]) Create a plugin that requires JDT Core and contribute your Ant task using the Ant core extension points. Add your plugin to the Eclipse set of plugins (use - clean to have the new plugin discovered). Modify your build file to execute your task.