关于maven编译错误的一些经验

在从eclipse转到IDEA的过程中,发现之前在eclipse中的能运行的项目,迁移到IDEA里就无法运行,只要执行maven compile,就会报各种错误,例如找不到符号、找不到程序包等等。
这里需要一提的是,我运行的maven项目有部分源码是错误的,一般是import一个不存在的包,调用一个不存在的方法等。
然而神奇的是居然可以编译通过并正常运行,于是上网搜索总算找到一个比较合理的解释。以下是原文:

Why you should use the Eclipse compiler in Intellij IDEA

If you use Intellij, you should consider using the Eclipse compiler instead of Javac.

The compiler used for your project can be changed in the IDE settings page.

Note that if you are using Java 8, then only Intellij 14 and higher have options to select the Eclipse compiler.

Unlike Javac, the Eclipse compiler is designed to be used first and foremost inside an IDE and thus offers some features that make it ideal for development usage:

  1. Proceed on errors

It is entirely possible that some portion of your source code may contain some compile time errors, however you want to quickly try executing some small test to check if some other part of your code works properly or not.

With the Javac compiler, you won’t have a choice but to fix all those errors before you are allowed to execute anything. The Eclipse compiler however will allow you to execute code regardless. Its aim is to always produce a runnable binary. If your code does hit a line with compile time error in it, it will throw a runtime exception instead.

  1. To enable this feature, you will need to:

  2. Check ’Proceed on errors’ in the Compiler settings page.

Replace the ’Make’ build step of your Run Configuration with ’Make, no error check’.

2 . Incremental Compilation

The Eclipse compiler is designed to run in the background of an IDE and thus natively supports incremental compilation. What this means is that it can compile only the changed blocks of code since the last compile, resulting in very fast build times.

3 . Parallel compilation

Unlike Javac, the Eclipse compiler can use multiple cores to speed up compilation, finally putting all those extra cores in your PC to good use.

Conclusion

As can be seen, there is no good reason to continue using Javac inside an IDE. Hopefully Jetbrains will make it the default compiler in future versions of Intellij IDEA.

大概意思是说,如果是用IDEA,应该考虑使用eclipse编译器而不是javac。
如果使用的是jdk1.8,只有在IDEA 14版本和更高版本才可以选择eclipse编译器。
eclipse编译器提供了一些有用的特性:
1.继续出错
源代码有些部分有可能包含一些编译时错误,但是用户希望快速执行一些小测试检查代码其他部分是否正常工作
如果使用javac,那么你只能将所有错误修复才能编译通过,而eclipse允许你执行代码,生成class文件,如果遇到了编译器错误将会抛出一个运行时异常
throw new Error(“xxxxx”);
2.增量编译
eclipse编译器可以在ide的后台运行,所以支持本地增量编译。这意味它只能编译更改过的代码块,从而缩短构建时间。
3.并行编译
与javac不同,eclipse编译器可以使用多个内核来加速编译,更好的利用你的多核计算机。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值