这是我的第一个问题。
我使用以下说明创建了Xtend的独立编译器。
内置蚂蚁和常春藤
目录是:lib /,build /
“ xtend-compiler.jar”将在build /上输出
库下载到lib /
Jar文件包含依赖库
主类是org.eclipse.xtend.core.compiler.batch.Main
build.xml:
<project name="xtend-compiler" default="jar-run" basedir="." xmlns:ivy="antlib:org.apache.ivy.ant">
<property name="lib.dir" value="lib" />
<property name="build.dir" value="build" />
<path id="lib.path.id">
<fileset dir="${lib.dir}"/>
</path>
<!-- resolve -->
<target name="resolve">
<mkdir dir="${lib.dir}"/>
<ivy:retrieve pattern="${lib.dir}/[artifact].[ext]"/>
</target>
<!-- jar -->
<target name="jar">
<delete dir="${build.dir}"/>
<copy file="${lib.dir}/org.eclipse.xtend.standalone.jar" tofile="${build.dir}/xtend-compiler.jar"/>
<jar update="true" destfile="${build.dir}/xtend-compiler.jar">
<zipgroupfileset dir="${lib.dir}" includes="**/*.jar" excludes="org.eclipse.xtend.standalone.jar"/>
<manifest>
<attribute name="Main-Class" value="org.eclipse.xtend.core.compiler.batch.Main"/>
</manifest>
</jar>
</target>
<!-- run -->
<target name="run">
<java jar="${build.dir}/xtend-compiler.jar" fork="true">
</java>
</target>
<target name="jar-run" depends="jar,run">
</target>
</project>
ivy.xml:
<ivy-module version="2.0">
<info organisation="" module="xtend-compiler"/>
<configurations>
<conf name="web"/>
</configurations>
<dependencies>
<dependency org="org.eclipse.xtend" name="org.eclipse.xtend.standalone" rev="2.4.3" conf="web->default"/>
</dependencies>
</ivy-module>
构建Jar文件后,我尝试运行
java -jar build/xtend-compiler.jar
由此可见:
Usage: Main <options> <source directories>
where possible options include:
-d <directory> Specify where to place generated xtend files
-tp <path> Temp directory to hold generated stubs and classes
-cp <path> Specify where to find user class files
-encoding <encoding> Specify character encoding used by source files
-useCurrentClassLoader Use current classloader as parent classloader
然后我要编译HelloWorld.xtend:
class HelloWorld {
def static void main(String[] args) {
System.out.println("Hello World")
}
}
但是我做不到例如:
java -jar build/xtend-compiler.jar HelloWorld.xtend
Exception in thread "main" java.lang.NullPointerException
at java.io.File.<init>(File.java:277)
at org.eclipse.xtend.core.compiler.batch.XtendBatchCompiler.configureWorkspace(XtendBatchCompiler.java:258)
at org.eclipse.xtend.core.compiler.batch.XtendBatchCompiler.compile(XtendBatchCompiler.java:273)
at org.eclipse.xtend.core.compiler.batch.Main.main(Main.java:48)
源文件位于资源目录中。
怎么编译呢?
补充
我找到了org.eclipse.xtend.core.compiler.batch.Main的来源:
https://github.com/eclipse/xtext/blob/master/plugins/org.eclipse.xtend.core/src/org/eclipse/xtend/core/compiler/batch/Main.java
我正在阅读它,但是现在我不明白要为参数添加什么。
最佳答案
我自己解决了。
java -jar build/xtend-compiler.jar -cp build/xtend-compiler.jar resource -d .
# 0 [main] INFO e.compiler.batch.XtendBatchCompiler - Compiling 1 source file to .
# 0 [main] INFO org.eclipse.xtend.core.compiler.batch.XtendBatchCompiler - Compiling 1 source file to .
javac -cp build/xtend-compiler.jar:. HelloWorld.java
java -cp build/xtend-compiler.jar:. HelloWorld
# Hello World
关于java - 如何使用独立编译器编译Xtend源代码?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25883483/