maven中文乱码问题——编译错误
生活随笔
收集整理的這篇文章主要介紹了
maven中文乱码问题——编译错误
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
新建了個web應用,用maven配置的。 Java源代碼采用了utf-8編碼格式。 本地編譯打包,報錯誤。 由于系統(tǒng)默認編碼是GBK,因此需要采用utf-8來編譯。 采用如下方式: 在pom中添加如下: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId>? <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration>? <plugin> ? 添加這個之后,發(fā)現(xiàn)還是不行。依然報錯。 折騰了好久,從http://jd.benow.ca/?下載了jd-gui這個軟件,查看編譯后的class文件,發(fā)現(xiàn)中文還是亂碼。 可見編譯依然沒有采用utf-8編碼。 檢查pom文件中,compile插件的配置。擦,竟然把這個plugin配置在<pluginManagement>里面去了,如下: <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration>
? ? ? ? ? ? ? ? <target>1.6</target>? <encoding>utf-8</encoding> </configuration> </plugin> ...... </plugins> <build> 其實,類似的錯誤還有,denpendencies 和dependencyManagement里的denpendencies的區(qū)別。
? ? ? ? ? ? ? ? <source>1.6</source>?
? ? ? ? ? ? ? ? ?<target>1.6</target>?
<encoding>utf-8</encoding> </configuration> </plugin> ...... </plugins> <pluginManagement> 而其實正確的做法應該是: <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> ? ? ? ? ? ? ? ? <source>1.6</source>?? ? ? ? ? ? ? ? <target>1.6</target>? <encoding>utf-8</encoding> </configuration> </plugin> ...... </plugins> <build> 其實,類似的錯誤還有,denpendencies 和dependencyManagement里的denpendencies的區(qū)別。
轉(zhuǎn)載于:https://www.cnblogs.com/gaojing/p/3922555.html
總結(jié)
以上是生活随笔為你收集整理的maven中文乱码问题——编译错误的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python代码制作configure文
- 下一篇: Scala in depth 6 Sca