gpt4 book ai didi

java - Xtext- doGenerate 在作为 warfile 运行时返回 xtend 符号

转载 作者:行者123 更新时间:2023-11-28 23:11:38 25 4
gpt4 key购买 nike

我正在开发一个 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)

当 Tomcat 产生时:

#! /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 或...)

关于java - Xtext- doGenerate 在作为 warfile 运行时返回 xtend 符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57226047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com