I made some changes to elipse.jdt.core
plugin in order to support a language (MaxJ) similar to Java. Changes that I made can be found here:
https://github.com/maxeler/eclipse.jdt.core/tree/MAXJ_4_4_maintenance
Release of my plugin can be found here:
https://github.com/maxeler/eclipse/releases
Everything works fine when I use eclipse in GUI mode but I want to compile different projects from command line (in headless build or using ant) and for that I need to create new ecj.jar
file. I tried building this library:
https://github.com/maxeler/maxpower
According to this article:
jdtCompilerAdapter.jar
can be used instead of ecj.jar
but that didn't work because it doesn't contain compiler classes (like CompilerOptions
etc.).
In build.xml
file I changed the following lines:
<taskdef name="maxjcompiler" classname="org.eclipse.jdt.core.ant.taskdef.MaxjTask" classpath="${env.MAXCOMPILERDIR}/lib/MaxIDE/ecj.jar" onerror="ignore"/>
<taskdef name="maxjdoc" classname="org.eclipse.jdt.core.ant.taskdef.MaxjDocTask" classpath="${env.MAXCOMPILERDIR}/lib/MaxIDE/ecj.jar"/>
with this:
<taskdef name="maxjcompiler" classname="org.eclipse.jdt.core.ant.taskdef.MaxjTask" classpath="/pathToMyJar/jdtCompilerAdapter.jar" onerror="ignore"/>
<taskdef name="maxjdoc" classname="org.eclipse.jdt.core.ant.taskdef.MaxjDocTask" classpath="/home/ikulezic/Desktop/jdtCompilerAdapter.jar"/>
And then I run this command to start build process:
ant
It produces the following error:
Buildfile: /home/ikulezic/Desktop/maxpower/build.xml
[taskdef] Could not load definitions from resource org/jacoco/ant/antlib.xml. It could not be found.
clean:
[delete] Deleting directory /home/ikulezic/Desktop/maxpower/bin
compile:
[echo]
[echo] Using maxeda classpath '/opt/maxcompiler/lib/MaxCompiler.jar'
[echo] (Precedence: 1. $MAXCOMPILERJCP, 2. $MAXCOMPILERDIR)
[echo]
[echo]
[mkdir] Created dir: /home/ikulezic/Desktop/maxpower/bin
BUILD FAILED
/home/ikulezic/Desktop/maxpower/build.xml:66: Could not create type maxjcompiler due to java.lang.NoClassDefFoundError: org/eclipse/jdt/internal/compiler/impl/CompilerOptions
at org.eclipse.jdt.core.ant.taskdef.MaxjTask.<init>(MaxjTask.java:80)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.apache.tools.ant.AntTypeDefinition.innerCreateAndSet(AntTypeDefinition.java:328)
at org.apache.tools.ant.AntTypeDefinition.createAndSet(AntTypeDefinition.java:274)
at org.apache.tools.ant.AntTypeDefinition.icreate(AntTypeDefinition.java:219)
at org.apache.tools.ant.AntTypeDefinition.create(AntTypeDefinition.java:206)
at org.apache.tools.ant.ComponentHelper.createComponent(ComponentHelper.java:285)
at org.apache.tools.ant.ComponentHelper.createComponent(ComponentHelper.java:263)
at org.apache.tools.ant.UnknownElement.makeObject(UnknownElement.java:429)
at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:163)
at org.apache.tools.ant.Task.perform(Task.java:347)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.Main.runBuild(Main.java:851)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.lang.ClassNotFoundException: org.eclipse.jdt.internal.compiler.impl.CompilerOptions
at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1366)
at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1315)
at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1068)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 24 more
Total time: 0 seconds
At the moment it seems like the only option is to build a new ecj.jar
file but I couldn't find a way to do it.
How to build ecj.jar
depends on what build technology you use.
If you have the context configured so that you can build org.eclipse.jdt.core
with Maven/Tycho, then you should adjust the batch-compiler
execution within the project's pom.xml.
Otherwise, a more light-weight approach should be to invoke Ant with scripts/export-ecj.xml
. That file may be a bit out-of-date, but you could take a look at how this is adapted for creating another variant of ecj (for OT/J), see: http://git.eclipse.org/c/objectteams/org.eclipse.objectteams.git/tree/org.eclipse.jdt.core/scripts/export-ecj.xml.
For OT/J this script is invoked from the Ant-based PDE-build process, so for standalone invocation a bunch of properites needs to be configured first.
build.root.dir
set. Otherwise, commenting the section for apt and tool should get you going.buildLabel
to something usefulWith these preparations I can successfully run Ant from within the IDE.