简体   繁体   中英

Maven project depending on a JAR compiled in a different encoding

If my project is compiled with UTF-8 encoding like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <encoding>UTF-8</encoding>
    </configuration>
</plugin>

and I have a dependency that was compiled with cp1252 encoding, what kind of problems could arise? Consider that besides .java files, also there are resource files.

There shouldn't be any problems, that's just the encoding used when transforming .java files into .class files - once the classes are compiled the strings are all Unicode internally anyway.

And the encoding you configure for the compiler only relates to the .java source files - other resources like .properties or .xml files that get packed into the JAR could be in different character encodings, the important thing is that the code that loads them must use the correct encoding for each file at runtime.

Hopefully none. The compiled jar file is the same no matter what the source encoding for it was. At least for class files. Text resources may be a different matter.

没有任何问题,你有依赖jars而不是src,jar中的类使用一个和相同的字符串文字编码 - 修改UTF-8 http://en.wikipedia.org/wiki/Java_class_file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM