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

jackgerrits
  • 791
  • 2
  • 8
  • 20
  • 2
    You can see an exception report if you run it from the console with `java -jar program.jar`. – tbodt Jul 30 '13 at 08:02
  • it shouldn't behave differently after compiling. It could be that it fails somewhere, are you sure you can't see any exceptions? – bas Jul 30 '13 at 08:02
  • 2
    Netbeans uses the same `jar` file you built. There is no change, it is the same file. I wonder if you have set some runtime argument in netbeans and forgot to use them while running from `cmd`? – Jatin Jul 30 '13 at 08:03
  • Well there are some exceptions but that dont cause it to crash in the IDE, but I dont think for this particular bit there are normally any exceptions – jackgerrits Jul 30 '13 at 08:04
  • @Jatin well actually the app can behave differently when run in NetBeans and like standalone. For example hiding password input in the console works for standalone but NetBeans doesn't use the standard console and crashes when using console-specific methods/classes. – Lenymm Jul 30 '13 at 08:05
  • @Lenymm Interesting. Can you please provide some link/example demonstrating it. – Jatin Jul 30 '13 at 08:13
  • Ok, thanks so much for the help. I was able to run it from the console to find the exception that was causing it to crash and handle it. – jackgerrits Jul 30 '13 at 08:17
  • @Jatin following doesn't work in NB but works as standalone: Console console = System.console(); console.printf("Please enter your e-mail: "); Options.login = console.readLine(); console.printf("Please enter your password: "); char[] passwordChars = console.readPassword(); Options.pass = new String(passwordChars); – Lenymm Jul 30 '13 at 08:25

3 Answers3

3

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.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
1

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.

outOfHeap
  • 11
  • 3
1

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!

arikan
  • 893
  • 9
  • 18