سؤال

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...

هل كانت مفيدة؟

المحلول

The main differences will be the directory it is run from, the specific version of Java you use and the command line options.

Of these, the most likely cause of a problem is running a different version of Java. I would check that

java -version

is the same as in netbeans.

I would also run your JAR from the command line to ensure that you see an exceptions/error produced.

نصائح أخرى

The problem might be in encoding. My NetBeans IDE launches jar files with

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

As u see, it launches jars using UTF-8 encoding.

don't know if you find the answer, but the problem was the encoding for me. I was reading some documents into jar, and those documents contained words that had Turkish characters. JAR file was unable to read those words therefore the program acted weirdly. So, instead of

Reader chars = new InputStreamReader(bytes);

I used

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

and that solved my problem.

Cheers!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top