首页 \ 问答 \ Ant Java build:编译问题 - 将字符集从ISO-8859-1更改为UTF-8(Ant Java build: Compilation issue - Change of character set from ISO-8859-1 to UTF-8)

Ant Java build:编译问题 - 将字符集从ISO-8859-1更改为UTF-8(Ant Java build: Compilation issue - Change of character set from ISO-8859-1 to UTF-8)

位新的字符集编码格式。 我有一个ant构建脚本,它以ISO-8859-1格式编译我的java代码。 它工作正常。

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

我已经将characterSet格式更改为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)

有人可以帮忙吗?

感谢致敬,

维杰雷迪。


Bit new to character set encoding formats. I have a ant build script, that compiles my java code in ISO-8859-1 format. It was working fine.

After reading couple of articles: How do I convert between ISO-8859-1 and UTF-8 in Java?

I have changed the characterSet format to UTF-8, since then the compilation issues started.

Error thrown is:

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

My Build script has follows:

<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>

One of my class that is having problems has following code in it:

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();
   }
}

I have also tried to change the characterset to UTF-16, but this time it has thrown different errors:

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)

Can someone help on this?

Thanks and Regards,

Vijay Reddy.


原文:https://stackoverflow.com/questions/40848154
更新时间:2019-11-08 02:39

最满意答案

我同意谢尔盖的评论,但你可以这样做:

var content = new List<List<string>>
        {
            new List<string>{ "book", "code", "columnToSum" },
            new List<string>{ "abc", "1", "10" },
            new List<string>{ "abc", "1", "5" },
            new List<string>{ "cde", "1", "6" },
        };

var headers = content.First();
var result = content.Skip(1)
    .GroupBy(s => new { Code = s[headers.IndexOf("code")], Book = s[headers.IndexOf("book")]})
    .Select(g => new
             {
                 Book = g.Key.Book,
                 Code = g.Key.Code,
                 Total = g.Select(s => int.Parse(s[headers.IndexOf("columnToSum")])).Sum()
             });

哪个回报:

{ Book = abc, Code = 1, Total = 15 }
{ Book = cde, Code = 1, Total = 6 }

I agree with Sergey's comment but You could do something like this:

var content = new List<List<string>>
        {
            new List<string>{ "book", "code", "columnToSum" },
            new List<string>{ "abc", "1", "10" },
            new List<string>{ "abc", "1", "5" },
            new List<string>{ "cde", "1", "6" },
        };

var headers = content.First();
var result = content.Skip(1)
    .GroupBy(s => new { Code = s[headers.IndexOf("code")], Book = s[headers.IndexOf("book")]})
    .Select(g => new
             {
                 Book = g.Key.Book,
                 Code = g.Key.Code,
                 Total = g.Select(s => int.Parse(s[headers.IndexOf("columnToSum")])).Sum()
             });

Which returns:

{ Book = abc, Code = 1, Total = 15 }
{ Book = cde, Code = 1, Total = 6 }

相关问答

更多
  • 我同意谢尔盖的评论,但你可以这样做: var content = new List> { new List{ "book", "code", "columnToSum" }, new List{ "abc", "1", "10" }, new List{ "abc", "1", "5" }, new List ...
  • 我不明白第一个“示例数据的结果”来自哪里,但控制台应用程序中的问题是您正在使用SelectMany来查看每个组中的每个项目 。 我想你只是想要: List result = Lines .GroupBy(l => l.ProductCode) .Select(cl => new ResultLine { ProductName = cl.First().Name, Quantity ...
  • 这对我有用(在LINQPad中): void Main() { var data = new List { new Info(){ Book=1, Chapter=1, Paragraph=1, TimesRead=3}, new Info(){ Book=1, Chapter=1, Paragraph=2, TimesRead=3}, new Info(){ Book=1, Chapter=1, Paragraph=3, Time ...
  • 如果我正确地阅读了这个问题,你可能会找到这样的东西: var los = new List(); string sumField = "Value1"; var result = los .Where(lo => lo.string2 == "June") .GroupBy(lo => lo.string1) .Select(g => new { Key = g.Key, Total = g .Wher ...
  • 您可以删除中间选择,只需按总和对组进行排序,然后选择产品。 var list = List.GroupBy(t => t.ParentProduct) .OrderBy(group => group.Sum(t => t.NumberOfOrders)) .Select(group => group.Key); You could remove the middle select and just order the groups by the ...
  • 你想要的东西像: var counts = contacts .Where(c => c.State != string.Empty) .GroupBy(i => i.Address.State, StringComparer.OrdinalIgnoreCase) .Select(grp => new { State = grp.Key, Count = grp.Count()); GroupBy返回IEnumerable> 。 由 ...
  • 它不是很清楚你想要什么 - 这样的事情? var Rows = allData.SelectMany(u => u._rows.Select(t => new { OA = t[4], CD = t[5], PD = t[0], DS = Convert.ToInt32(t[9]), CS = Convert.ToInt32(t[10]) })) // group by the combination of CD, OA, and PD .GroupBy(x => new { x.CD, ...
  • 我想你看这个: var data = Model.Where(x => x.Start.Date == DateTime.UtcNow.Date) .GroupBy(x => new { x.Start, x.Field2 }) .Select(g=>g.ToList()).ToList(); 添加一个Select呼叫以获得每个组的列表 I think you are looking this: var data = Model.Where( ...
  • .GroupBy(category => category.ItemCategory); 返回一个可枚举的IGrouping对象,其中每个IGrouping的键是一个不同的ItemCategory值,该值是MoneySpent对象的列表。 因此,您无法像现在这样将这些分组简单地放入ObservableCollection中。 相反,您可能希望将每个分组结果选择为新的MoneySpent对象: var finalQuery = boughtItemsToday .GroupBy(category => ...
  • 这应该做你想做的事情: var orders = br.CustOrderList .GroupBy(x => x.ZipCode) .Select(g => new { ZipCode = g.Key, Orders = g.SelectMany(x => x.OrderList) }); This should do what you want: var orders = br.CustOrderList .GroupBy(x = ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)