我正在开发一个Xtext项目,在我的Generator.xtend
中,我制作了一个python脚本。当我在 Eclipse 中运行ServerLaucher.xtend
时,一切正常,但是如果我生成war
文件并在 Tomcat 中运行它,脚本将包含 xtend 符号。这是我生成python脚本的代码:
def compile(Main main)'''
#! /usr/bin/env python
...
«FOR to : main.takeoff»
takeoff = rospy.Publisher('/ardrone/takeoff', Empty, queue_size=1)
while takeoff.get_num_connections() < 1:
rospy.sleep(0.1)
takeoff.publish(empty)
rospy.sleep(5)
«ENDFOR»
'''
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
var result = "";
for(main : resource.allContents.toIterable.filter(Main)) {
result = main.compile.toString;
System.out.println(result);
}
如果在 Eclipse 中运行,则结果包含:
#! /usr/bin/env python
takeoff = rospy.Publisher('/ardrone/takeoff', Empty, queue_size=1)
while takeoff.get_num_connections() < 1:
rospy.sleep(0.1)
takeoff.publish(empty)
rospy.sleep(5)
虽然雄猫生产:
#! /usr/bin/env python
�FOR to : main.takeoff�
takeoff = rospy.Publisher('/ardrone/takeoff', Empty, queue_size=1)
while takeoff.get_num_connections() < 1:
rospy.sleep(0.1)
takeoff.publish(empty)
rospy.sleep(5)
�ENDFOR�
编辑:这是我的主要build.gradle
文件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.xtext:xtext-gradle-plugin:2.0.4'
}
}
subprojects {
ext.xtextVersion = '2.17.0'
repositories {
jcenter()
}
apply plugin: 'java'
dependencies {
compile platform("org.eclipse.xtext:xtext-dev-bom:${xtextVersion}")
}
apply plugin: 'org.xtext.xtend'
apply from: "${rootDir}/gradle/source-layout.gradle"
apply plugin: 'eclipse'
group = 'ic.ac.uk.mydsl'
version = '1.0.0-SNAPSHOT'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
configurations.all {
exclude group: 'asm'
}
}
编辑2:我在其中一个子项目中的build.gradle文件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.xtext:xtext-gradle-plugin:2.0.4'
}
}
subprojects {
ext.xtextVersion = '2.17.0'
repositories {
jcenter()
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
apply plugin: 'java'
dependencies {
compile platform("org.eclipse.xtext:xtext-dev-bom:${xtextVersion}")
}
apply plugin: 'org.xtext.xtend'
apply from: "${rootDir}/gradle/source-layout.gradle"
apply plugin: 'eclipse'
group = 'ic.ac.uk.xdrone'
version = '1.0.0-SNAPSHOT'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
configurations.all {
exclude group: 'asm'
}
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
在 gradle 中,您应该为 JavaTask 设置编码。 然后,Xtend插件应该会选择这个。还要确保文件实际上具有正确的编码
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
(或 ISO-8859-1 或 ...(