IDEA创建maven在main运行代码出现编译乱码问题

maven项目与IDEA2020.1版本存在一些问题,在运行main时会自动默认插件代理运行

编译时出现乱码。

我换了2019.3版本的完成不存在这个问题,2017、2021好像也可以,没有测试过。

当然如果不想换版本,也有解决办法。

原因分析

maven项目,执行main函数的时候需要两个插件:
maven-compiler-plugin:用来编译Java文件,指定JDK版本等
exec-maven-plugin:用来执行class文件,其中插件配置中需指明执行类的路径。

**方法一:setting **

在setting->maven->Runner->VM Options一栏中填入 -Dfile.encoding=gb2312
在这里插入图片描述

方法二:pom.xml
<properties>
	<!-- 文件拷贝时的编码 -->
	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
	<!-- 编译时的编码 -->
    <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
</properties>
方法三:

如果要使用main函数执行,那就在maven引入办法提到的两个插件即可。

<build>
            <plugins>
                    <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>exec-maven-plugin</artifactId>
                            <version>1.2.1</version>
                            <executions>
                                    <execution>
                                            <goals>
                                                    <goal>java</goal>
                                            </goals>
                                    </execution>
                            </executions>
                            <configuration>
                                    <mainClass>pl.stasiak.pytel.SnmpClientApplication</mainClass>
                            </configuration>
                    </plugin>
            </plugins>
    </build>

<build>
     <plugins>
         <plugin>
             <groupId>org.codehaus.mojo</groupId>
             <artifactId>exec-maven-plugin</artifactId>
             <version>1.6.0</version>
             <executions>
                 <execution>
                     <goals>
                         <goal>java</goal>
                     </goals>
                 </execution>
             </executions>
             <configuration>
                 <classpathScope>test</classpathScope>
             </configuration>
         </plugin>
     </plugins>
</build>

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程小栈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值