B4J Question packaged java program closes on Serial port Open

nibelugen

Member
Licensed User
I authored a B4J program, that compiles and runs fine as a jar file. I tried packaging it using the self contained installer as detailed here,
https://www.b4x.com/android/forum/threads/ui-apps-packaging-self-contained-installers.56854/

The packager executes fine, and I end up with an installable program. I installed the packaged program on three different computers, two Windows 10, and 1 Windows 7. When running the program the first thing the end user must do is select a COM serial port. On the Windows 10 systems, immediately when the port is selected, and the program line
Serial1.Open(cmbPort.Value) is encountered, the program closes. If I run the compiled jar program in the same installed program app subdirectory, it runs fine. In the log file, it shows that COM1 is selected as the value - and I even tried to manually select it in the program with Serial1.Open("COM1"), but it immediately closes with the packaged and installed executable, but works fine as the jar file. I am out of ideas. Here are the lines of code that are terminating the installed program,

astream.Close
Serial1.Close
Serial1.Initialize("")
Log("<" & cmbPort.Value & ">")
Serial1.Open(cmbPort.Value)

Please help, as I can't distribute the program. Thanks.
 

nibelugen

Member
Licensed User
Fantastic! I did not have a copy of javapackager in my x86 jdk! I'm going to later this evening, uninstall my existing x86 java and newly install jdk1.8.0_144. I then expect to find x86 javapackager there, and most certainly can then compile and package completely now 32bit. Excellent! I will report back.

As for JDK-9, the problem is not exactly a moot point - the issue I have been complaining about is running Serial Port as a native exe, but in all of my testing I was able to run Chat in the IDE release, IDE Debug, and .jar compiled without a problem - and much of that testing was 64bit. It always worked. With JDK-9, it now crashes on SO in the IDE release, IDE Debug, and .jar compiled. That is a new problem manifested, yet temptingly similar to the existing.
 
Upvote 0

OliverA

Expert
Licensed User
With JDK-9, it now crashes on SO in the IDE release, IDE Debug, and .jar compiled. That is a new problem manifested, yet temptingly similar to the existing.
upload_2017-10-6_13-43-10.png


As can be seen in the screenshot, the last time the Java Simple Serial Connector (JSSC) was updated was 4+ years ago. The compiled libraries included are just as old. This was before the Windows 10 release and before JDK 9 and even JDK 8. The Windows libraries were most likely compiled and tested under Windows 7. It's a slight miracle that the libraries worked for this long under newer JDK's / operating systems, since they deal with low level interfaces that are usually prone to change. There is probably some change in Windows 10 regarding serial port handling that is breaking JSSC and it may be as simple as recompiling JSSC under Windows 10 or as complex as to modifying a portion of the source code to deal with whatever changed in Windows 10.
 
Upvote 0

nibelugen

Member
Licensed User
It Works! The x86 32 bit compile circumvented the Serial Port open crashing problem! I tested it with both Chat.jar and my own program, and they both work now as installed native executable!

As I had indicated, I uninstalled existing x86 java. Then I downloaded from the Oracle website the Windows x86 version of java, jdk-8u144-windows-i586.exe, and installed it. I opened B4J and set the javac.exe path to C:\Program Files (x86)\Java\jdk1.8.0_144\bin\javac.exe. I opened the Chat program, and then later my own program and compiled them both. I tested them individually as compiled jar, and they both worked as expected. I then opened the B4J Packager utility available on the B4J website that I had previously downloaded, and ran it in the IDE. I filled in the javapackager text field, setting it to C:\Program Files (x86)\Java\jdk1.8.0_144\bin\javapackager.exe. I filled in the Jar file path field to the newly compiled programs, Chat.jar and then later my own. I filled in the few other fields, and then built the bundled installer programs. They averaged each about 45M in size, which was expected. I ran these and installed the Chat program and then my own program on a Windows 10 computer. They installed as expected in directory - Program Files (x86). I tested them by clicking on the installer created desktop icon, and they both ran perfectly and as expected, and no crashing now on Serial Port Open! Wonderful!

Thank you OliverA for help in guiding through the diagnostic process to satisfying conclusion; Thank you Erel for your knowledgeable help in the diagnostics! Together, along with my own determined effort, helped to resolve the issue to a satisfying conclusion!
 
Upvote 0

DavideV

Active Member
Licensed User
Confirmed the same problem with serial ports on windows 10 and JDK9+ and also the new JDK10.
The problem can be seen also compiling in the ide using javac from JDK9+ : as soon as i try to open a serial port the program crashes.
It works using the JDK 1.8.xxx both in IDE and compiled Jar.

I can choose to compile with javac from 1.8.xxx to run the app in the ide, but as soon as i run the standalone created Jar (in object folder) it crashes because windows uses the last version of Java. It would be nice if i can point windows to use one of the old versions, but i don't know how.
Immagine.png
 
Upvote 0
Top