Java 将默认字符集更改为UTF-8
我有一个用java编写的maven builder项目。现在我需要支持UTF-8字符集。我不知道为什么默认字符集(Java 将默认字符集更改为UTF-8,java,maven,utf-8,character-encoding,Java,Maven,Utf 8,Character Encoding,我有一个用java编写的maven builder项目。现在我需要支持UTF-8字符集。我不知道为什么默认字符集(charset.defaultCharset())总是US-ASCII。 我将Pom.xml配置更改为UTF-8(用于编码),并设置-Dfile.encoding=UTF-8 但是对于Unicode的字符,输出总是“?”(例如,“Việt Nam“=>Vi?t Nam) 我已经在Ant buidler上检查过了,它和UTF-8的字符一样正确 这是我的Pom.xml <build
charset.defaultCharset()
)总是US-ASCII。
我将Pom.xml配置更改为UTF-8(用于编码),并设置-Dfile.encoding=UTF-8
但是对于Unicode的字符,输出总是“?
”(例如,“Việt Nam“
=>Vi?t Nam
)
我已经在Ant buidler上检查过了,它和UTF-8的字符一样正确
这是我的Pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<outputEncoding>UTF-8</outputEncoding>
<argLine>-Dfile.encoding=UTF-8</argLine>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>cucumber</id>
<phase>test</phase>
<configuration>
<executable>src/scripts/cucumber.sh</executable>
<commandlineArgs>${host} ${port} ${profile}</commandlineArgs>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
org.apache.maven.plugins
maven编译器插件
2.3.2
1.7
1.7
UTF-8
-文件编码=UTF-8
${project.build.sourceEncoding}
org.codehaus.mojo
execmaven插件
1.2.1
黄瓜
测试
src/scripts/cucumber.sh
${host}${port}${profile}
执行官
UTF-8
UTF-8
多谢各位
更新
我的系统是
NetBeans 7.3.1
JDK1.7
Mac OS 10.9.1
更新
我已将IDE更改为Intelij IDEA,问题已经解决,但我不知道原因。在尝试此操作之前
...
UTF-8
UTF-8
我不确定您的问题是否正确,但似乎您对maven和源代码没有问题,而是对运行的程序和用户输入有问题,对吗
如果是这样,您应该在运行您的程序的JVM上设置-Dfile.encoding=UTF-8
,而不是在运行maven的JVM上设置来编译您的程序。粘贴的配置仅确保maven和javac
将源文件解释为UTF-8编码
有关问题的更多详细信息,请参见
嗯,,
-马丁这件事替我解决了。将以下内容添加到html或jsp中
<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html lang="en">
...
...
我曾尝试将UTF-8
添加到属性中,但未发生任何更改。谢谢,我已尝试,但未发生任何变化。我通过将IDE从Netbeans更改为IDEA解决了我的问题。
<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html lang="en">
...