1

Ok, so I have been making a chat client in netbeans and I'm pretty much done. I decided to clean and build to test it standalone.

However, when a message is received from the other program using sockets (Connection goes fine), the program closes. This issue never occurred when it was run straight from the IDE.

So, what I am wondering is whether the program behaves differently(well it obviously does, but how?) once it is clean and built into a jar. Is there something extra I must take into account. Such as does an exception mean it will all suddenly cease?

Also, since it only occurs with the built jar I cannot see any exceptions that may have occurred. I am very stumped...

4

3 回答 3

3

主要区别在于运行它的目录、您使用的特定 Java 版本和命令行选项。

其中,最可能导致问题的原因是运行不同版本的 Java。我会检查

java -version

与netbeans中的相同。

我还将从命令行运行您的 JAR,以确保您看到产生的异常/错误。

于 2013-07-30T08:06:11.227 回答
1

问题可能出在编码上。我的 NetBeans IDE 启动 jar 文件

-Dfile.encoding=UTF-8 -Djava.security.policy=applet.policy -classpath -Xmx512M -Xss64M

如您所见,它使用 UTF-8 编码启动 jars。

于 2015-05-06T18:38:08.680 回答
1

不知道你是否找到答案,但问题是我的编码。我正在将一些文件读入 jar,这些文件包含带有土耳其字符的单词。JAR 文件无法读取这些单词,因此程序行为异常。所以,而不是

Reader chars = new InputStreamReader(bytes);

我用了

Reader chars = new InputStreamReader(bytes, "UTF-8");

这解决了我的问题。

干杯!

于 2016-05-29T18:21:17.967 回答