Search code examples
javajarserversocket

ServerSocket not accepting connection from jar


I've written a Server-Client program that sends strings from the client to the server. I use these strings to move the mouse around the screen.

My issue lies in connecting to the ServerSocket when the program is packaged into a jar file.

It will work if I:

1) Run the code directly from NetBeans.

OR

2) Execute the jar using java -jar jarname.jar.

It will not work if I execute the jar by double clicking it. I display a GUI window for this program, which will appear though, so I know that the program is being executed. However, when I try to connect to the ServerSocket in the exact same way, nothing happens. No exceptions are thrown either.

I wrote this program several months ago, and it used to work then if I ran the jar by double clicking it. Nothing about my jar has changed. This leads me to believe that an update to java is causing this issue.

If possible, I'd like to know if there's a workaround that does not involve downgrading Java on my computer since I'd like to distribute this program to users later.


Solution

  • It may not be executing or may be breaking before your GUI opens. If there is a conflict due to java version, I would suggest you to generate and executable (exe) for your jar and use the same. You can use any open source software e.g. Launch4J