是否有Java的“调试”和“发布”的构建模式,如C#? [英] Does Java have 'Debug' and 'Release' build mode like C#?

查看:180
本文介绍了是否有Java的“调试”和“发布”的构建模式,如C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,我们有2个模式,打造项目:调试发布,我不知道Java有一样。我使用的IntelliJ IDEA的Java IDE的,至今我还没有看到任何地方配置的构建模式,就像在VS IDE。

解决方案

 的javac
  -g生成所有调试信息
  -g:没有生成任何调试信息
  -g:{线,增值经销商,源}仅生成一些调试信息
 

您可以选择包括在编译的类调试符号(这是默认的),或者没有这样做。没有太多的好处不这样做。 JAR文件将是<一href="http://stackoverflow.com/questions/218033/is-there-a-performance-difference-between-javac-debug-on-and-off">a稍小一点的,但性能益处是最小的(如果有的话)。如果没有这些符号不再得到堆栈跟踪行号。您也可以选择包括<一个href="http://stackoverflow.com/questions/5746894/javac-with-debugging-information-option-gvars-output-example">additional与局部变量名的符号(默认情况下,只有源文件名和行号)。

 的java
    -ea [:其中,软件包名&GT; ... |:&LT;类名&GT;]
    -enableassertions [:其中,软件包名&GT; ... |:&LT;类名&GT;]
                  启用断言
 

您还可以启用在运行时断言(默认是关闭的),这是开发和测试过程中有时是有用的。这确实有一个性能的影响(如code问题确实利用断言,这是我想到的是罕见)。

无论任何设置时,JVM总是让你附加一个调试器。

什么Java不就是完全不同的code将一些外部设置编译条件编译。你可以得到的最接近的是一样的东西公共静态最终布尔DEBUG_BUILD =真; 放在你的code和使用,在if语句。这实际上使编译器排除code表示不可达,但你必须设置这个常量在源$ C ​​$ C。

In C#, we have 2 modes to build projects : Debug and Release, I wonder if Java has the same thing. I am using IntelliJ IDEA as Java IDE and so far I haven't seen anywhere to configure a build mode like in VS IDE.

解决方案

javac 
  -g                         Generate all debugging info
  -g:none                    Generate no debugging info
  -g:{lines,vars,source}     Generate only some debugging info

You can choose to include debug symbols in the compiled classes (this is the default) or to not do so. There is not much benefit to not doing that. The jar files will be a little smaller, but the performance benefit is minimal (if any). Without these symbols you no longer get line numbers in stack traces. You also have the option to include additional symbols with local variable names (by default there are only source file names and line numbers).

java
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions

You can also enable assertions at run-time (default is off), which is sometimes useful during development and testing. This does have a performance impact (if the code in question did indeed make use of assertions, which I think is uncommon).

Regardless of any of these settings, the JVM always allows you to attach a debugger.

What Java does not have is conditional compilation where completely different code would be compiled based on some external setting. The closest you can get is something like public static final boolean DEBUG_BUILD = true; somewhere in your code and use that in if statements. This will actually make the compiler exclude code that becomes unreachable, but you have to set this constant in the source code.

这篇关于是否有Java的“调试”和“发布”的构建模式,如C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆