我怎样才能在运行时调试jar? [英] how can I debug a jar at runtime?

查看:345
本文介绍了我怎样才能在运行时调试jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我处于一个非常奇怪的位置(从我的java-newbie观点来看):

I'm into a quite strange position (from my java-newbie point of view):


  1. 使用Eclipse I写了一个java程序(一些带有类的.java文件),它基本上(批处理)读取文本* .csv文件,评估其内容,并将结果写入* _out.csv文本文件。要找到输入文件,它使用文件选择器(从此处获取示例: http:// docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html

我调试了所有代码,并使用调试器,工作正常

I debugged all the code and, using the debugger, it works.

我运行了代码(主类,按顺序调用所有其他代码)和它在Eclipse中运行

I ran the code (the main class, which calls all the other in sequence) and it works, while in Eclipse.

我将所有项目的内容导出到runnable jar文件中。

I exported all the project's contents into a "runnable jar" file.

请注意,文件选择器除外,这主要是一个批处理,它可以读写:几乎没有用户界面一点都不在Eclipse中,我使用类似 if(debug)System.out.print(要打印的东西)的内容显示了一些内部结果; 提供设置 debug 调试时为TRUE,在生产环境中为FALSE。

Notice that, file chooser apart, this is mainly a "batch" which reads and writes: nearly no User Interface at all. While into Eclipse I shown some internal results using something like "if(debug) System.out.print("something to print");" providing to set "debug" TRUE while debugging and FALSE while in production environment.

以上所有均有效!

现在,启动runnable jar(双击jar文件,在Win / XP中),我可以看到文件选择器,我可以使用它,但是在选择输入文件之后。 .. 没有更多 :(没有用户界面)我不知道文件是否被读取,我没有看到任何生成的输出文件,我甚至没有控制台列出任何中间调试消息,看看jar是否正常工作,即使我将调试变量设置为TRUE重新导出它。

Now, starting the runnable jar (double-click on the jar file, in Win/XP), I can see the file chooser and I can use it but, after choosing the input file... nothing more: (having no user interface) I don't know if the file was read, I don't see any generated output file, and I've even no "console" to list any intermediate debug message, to see if the jar is working, even if I re-export it with the debug variable set to TRUE.

有没有办法运行时调试正在运行的jar(比如VB的MsgBox,还是其他的东西)?某种日志文件我可以启用或查看? (显然,由于我的jar不是写结果文件,我也不能尝试写一个* .log)
我还要说我只是不能安装除了Eclipse在我的机器上(幸运的是它运行),所以没有通常的开发人员的工具,实用程序和其他有用的东西。

Is there a way to "runtime debug" the running jar (like VB's MsgBox, or something other)? some kind of "log file" I can "enable" or look into? (obviously, as my jar is not writing the result file, I just can't try writing a *.log too) I have also to say I just can't install other than Eclipse on my machine (and just been lucky it ran), so no usual developer's tools, utilities and other useful things.

推荐答案

即使它是一个可运行的jar,你仍然可以从控制台运行它 - 打开一个终端窗口,导航到包含jar的目录,然后输入java -jar yourJar.jar。它将在该终端窗口中运行,并且sysout和syserr输出将出现在那里,包括来自未捕获异常的堆栈跟踪。确保将调试设置为true。祝你好运。

Even though it is a runnable jar, you can still run it from a console -- open a terminal window, navigate to the directory containing the jar, and enter "java -jar yourJar.jar". It will run in that terminal window, and sysout and syserr output will appear there, including stack traces from uncaught exceptions. Be sure to have your debug set to true. And good luck.

想到别的东西 - 如果你使用的是Win7,它通常会出现权限问题用户应用程序将文件写入特定目录。确保您编写输出文件的目录是您拥有权限的目录。

Just thought of something else -- if you're on Win7, it often has permission problems with user applications writing files to specific directories. Make sure the directory to which you are writing your output file is one for which you have permissions.

在未来的项目中,如果它足够大,您可以使用其中一个'debug'输出的标准日志记录工具;然后将它重定向到文件而不是依赖于控制台将很容易(ier)。但对于像这样的小工作,这应该没问题。

In a future project, if it's big enough, you can use one of the standard logging facilities for 'debug' output; then it will be easy(ier) to redirect it to a file instead of depending on having a console. But for a smaller job like this, this should be fine.

这篇关于我怎样才能在运行时调试jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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