Ant Java构建:编译问题 - 将字符设置从ISO-8859-1更改为UTF-8



有点新的字符集编码格式。我有一个蚂蚁构建脚本,该脚本以ISO-8859-1格式编译我的Java代码。它正常工作。

阅读了几篇文章后:如何在Java中的ISO-8859-1和UTF-8之间转换?

我已将字符集格式更改为UTF-8,从那以后开始编译问题。

抛出的错误是:

[javac] TestEncoding.java (at line 11)
[javac] case '?' :
[javac] ^^^^^^^^

我的构建脚本如下:

<javac compiler="org.eclipse.jdt.core.JDTCompilerAdapter"
destdir="bin" debug="true" deprecation="on" encoding="iso-8859-1"
source="1.6" target="1.6"
debuglevel="lines,source" failonerror="false" errorProperty="buildFailed">
<compilerarg line="-warn:+raw" />
<compilerarg line="-warn:-serial" />
<compilerarg line="-log source/testapp/compileLog.xml" />
<src path="testapp" />
<classpath refid="application.classpath" />
</javac>

我的班级之一,有问题的遵循代码:

public class TestEncoding {
public static final String filterAccent(String s) {
    StringBuffer sb = new StringBuffer();
    int n = s.length();
    for (int i = 0; i < n; i++) {
        char c = s.charAt(i);
        switch (c) {
        case 'á':
            sb.append("a");
            break;
        case 'à':
            sb.append("a");
            break;
        case 'ã':
            sb.append("a");
            break;
        case 'À':
            sb.append("A");
            break;
        case 'â':
            sb.append("a");
            break;
        case 'Â':
            sb.append("A");
            break;
        case 'ä':
            sb.append("a");
            break;
        case 'Ä':
            sb.append("A");
            break;
        case 'å':
            sb.append("a");
            break;
        case 'Å':
            sb.append("A");
            break;
        case 'ç':
            sb.append("c");
            break;
        case 'Ç':
            sb.append("C");
            break;
        case 'é':
            sb.append("e");
            break;
        case 'É':
            sb.append("E");
            break;
        case 'è':
            sb.append("e");
            break;
        case 'È':
            sb.append("E");
            break;
        case 'ê':
            sb.append("e");
            break;
        case 'Ê':
            sb.append("E");
            break;
        case 'ë':
            sb.append("e");
            break;
        case 'Ë':
            sb.append("E");
            break;
        case 'í':
            sb.append("i");
            break;
        case 'ì':
            sb.append("i");
            break;
        case 'ï':
            sb.append("i");
            break;
        case 'î':
            sb.append("i");
            break;
        case 'Ï':
            sb.append("I");
            break;
        default:
            sb.append(c);
            break;
        }
    }
    return sb.toString();
   }
}

我也试图将字符集更改为UTF-16,但是这一次它引发了不同的错误:

build.xml:152: com.ibm.team.repository.common.validation.PropertyConstraintException: Validation errors for item: type = CompilePackage, itemId = [UUID _ORXiULV3Eea3M7KtSY0KHw]
    Value of attribute "compileSources.errors.sourceText" is 67854 bytes, which is greater than the allowed encoded length of 32768 bytes.
    Value of attribute "compileSources.errors.sourceText" is 58296 bytes, which is greater than the allowed encoded length of 32768 bytes.
    Value of attribute "compileSources.errors.sourceText" is 36105 bytes, which is greater than the allowed encoded length of 32768 bytes.
    Value of attribute "compileSources.errors.sourceText" is 127899 bytes, which is greater than the allowed encoded length of 32768 bytes.
    Value of attribute "compileSources.errors.sourceText" is 155844 bytes, which is greater than the allowed encoded length of 32768 bytes.
    Value of attribute "compileSources.errors.sourceText" is 120795 bytes, which is greater than the allowed encoded length of 32768 bytes.
    Value of attribute "compileSources.errors.sourceText" is 81561 bytes, which is greater than the allowed encoded length of 32768 bytes.
    Value of attribute "compileSources.errors.sourceText" is 33264 bytes, which is greater than the allowed encoded length of 32768 bytes.
    Value of attribute "compileSources.errors.sourceText" is 35163 bytes, which is greater than the allowed encoded length of 32768 bytes.
    Value of attribute "compileSources.errors.sourceText" is 96396 bytes, which is greater than the allowed encoded length of 32768 bytes.
    at com.ibm.team.repository.service.internal.RdbRepositoryDataMediator.failIfNecessary(RdbRepositoryDataMediator.java:456)
    at com.ibm.team.repository.service.internal.RdbRepositoryDataMediator.validateItem(RdbRepositoryDataMediator.java:405)

有人可以为此提供帮助吗?

谢谢,问候

Vijay Reddy。

我在编码级别上尝试了多件事。什么都没有。

最后,我尝试了Berger建议,将源代码编码格式更改为UTF-8,然后使用UTF-8构建一切都很好。我唯一必须保持关注的是对项目中使用的特殊字符。一旦更改了项目级别的编码,就会更改为特殊字符?符号。我需要转换所有这些?到实际特殊字符。这是我唯一需要花费的努力。对于开发人员而言,这可能是一个混乱的情况,但是由于这是开发人员的一次性活动/每个项目应该可以。

感谢Berger的建议。

最新更新