B4J Tutorial Remote debugging with B4J-Bridge

Erel

Administrator
Staff member
Licensed User
B4J v1.80 adds support for remote debugging using B4J-Bridge, a tool similar to the beloved B4A-Bridge.

The purpose of B4J-Bridge is to allow you to connect the IDE to a remote machine such as a Mac computer or a Raspberry Pi board and to easily debug your app on the remote machine. The connection is done over the network (usually the local network).

Instructions
  • Download b4j_bridge.jar to the remote machine: www.b4x.com/b4j/files/b4j-bridge.jar
    Note that you can download it with this command:
    B4X:
    wget www.b4x.com/b4j/files/b4j-bridge.jar
    Tip: delete the previous version before download: rm b4j-bridge.jar
  • Make sure that Java 8+ is installed on the remote machine.
  • Open a terminal and run java -jar b4j-bridge.jar:



    If you are running it on a raspberry pi together with the jPi4J library then you need to run it with:
    B4X:
    sudo java -jar b4j-bridge.jar
  • Choose Tools -> B4J-Bridge -> Connect and enter the remote machine IP address:


  • The status icon should change to:


  • Now you can run your app in Release or Debug mode and debug it directly on the target machine:

You can disconnect with Shift + F2 and later reconnect with F2.
Note that the jar is copied to the target machine and deployed under a folder named tempjars.

If the debugger fails to connect to the remote machine then you should open the following ports for incoming connections:
59812, 8937 and 8938

Updates

v1.44 - Adds support for Java versions above Java 11.
 
Last edited:

billzhan

Active Member
Licensed User
I have tested it .

Works on Winxp sp2 (Jre 1.7,UI and NonUI).

When it comes to Debian 7.2 on VmWare(openjdk-7-jre), NonUI programmes work fine.
It seems SUN Java is needed for UI programmes accroding to the tutorial B4J on Linux, still working on it.

It is really nice to have this.

Bill
 

Kevin L. Johnson

Member
Licensed User
Hello,
I just thought that I'd point out some useful, pertinent, relavent info found in one of Erel's other posts ...
http://www.basic4ppc.com/android/forum/threads/jpi4j-raspberry-pi-gpio-controller.37493/
where he states ...

B4J-Bridge is very useful when working with this board: http://www.basic4ppc.com/android/forum/threads/remote-debugging-with-b4j-bridge.38804/
You can download it to the board with this command:
B4X:
wget http://www.basic4ppc.com/b4j/files/b4j-bridge.jar
Then run it as root:
B4X:
sudo <path to java> -jar b4j-bridge.jar
Enjoy! And Thanks for a great product!
Kevin
 

HARRY

Active Member
Licensed User
"Make sure that Java 7+ is installed on the remote machine." What version of java should be installed on the remote machine when that is a Raspberry? JDK 7 for ARM??

Harry
 
Hi.Erel I am Running B4J Error like this "
Exception in Application constructor
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.javafx.main.Main.launchApp(Main.java:698)
at com.javafx.main.Main.main(Main.java:871)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at anywheresoftware.b4a.keywords.Common.main(Common.java:32)
Caused by: java.lang.RuntimeException: Unable to construct Application instance: class b4j.example.main
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.access$000(Unknown Source)
at com.sun.javafx.application.LauncherImpl$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
... 4 more
Caused by: java.lang.RuntimeException: java.lang.NoClassDefFoundError: javafx/scene/control/Dialog
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at b4j.example.main.<clinit>(main.java:17)
... 8 more
Caused by: java.lang.NoClassDefFoundError: javafx/scene/control/Dialog
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:499)
at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:486)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:243)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
... 10 more
Caused by: java.lang.ClassNotFoundException: javafx.scene.control.Dialog
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 21 more

" in fact IDE B4J Connect With Bridge.jar?
 

Dominik H

Member
Licensed User
You need to use Java 8u40+ to run UI applications.
I've currently got the latest Java installed on both machines, I try to open B4j-Bridge but it doesn't load anything, it's as if nothing happens but a process does start up. I tried to connect to the IP from my other computer to test if it works nonetheless, and no success. Is there anything I can do?

I have windows 10 on both machines, if that helps.
 

Erel

Administrator
Staff member
Licensed User
You should run it from the command line. B4J-Bridge is a non-ui app.
 

Dominik H

Member
Licensed User
You should run it from the command line. B4J-Bridge is a non-ui app.
Oh, fair enough. Thanks!

EDIT: I tried it, the text showed in the command line, however, it showed me the wrong IP. My second PC didn't connect to that IP, however I checked ipconfig and it was a completely different IP there. Is this my computer's IP settings messed up or why is it showing a different IP on the command line?

EDIT 2: I found out i had multiple network adapters. I got rid of them all. But I am receiving an error when using B4J-Bridge on either of my PC's, first when I add the IP it says "Ping failed" but I add it anyway and it shows that the devices connected. But when I try to debug the program I get this error:

B4X:
Program started.
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at anywheresoftware.b4a.DynamicBuilder.build(DynamicBuilder.java:16)
    at anywheresoftware.b4j.objects.LayoutBuilder.loadLayoutHeader(LayoutBuilder.java:113)
    at anywheresoftware.b4j.objects.LayoutBuilder.loadLayoutHeader(LayoutBuilder.java:154)
    at anywheresoftware.b4j.objects.LayoutBuilder.loadLayout(LayoutBuilder.java:77)
    at anywheresoftware.b4j.objects.PaneWrapper.LoadLayout(PaneWrapper.java:76)
    at b4j.example.main._appstart(main.java:264)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:593)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
    at b4j.example.main.start(main.java:36)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Metho
d)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: Asset file not found: Rank.png
    at anywheresoftware.b4a.objects.streams.File.GetUri(File.java:158)
    at anywheresoftware.b4j.objects.NodeWrapper.getImageUri(NodeWrapper.java:616)
    at anywheresoftware.b4j.objects.NodeWrapper.buildDrawable(NodeWrapper.java:554)
    at anywheresoftware.b4j.objects.NodeWrapper.build(NodeWrapper.java:405)
    at anywheresoftware.b4j.objects.ImageViewWrapper.build(ImageViewWrapper.java:103)
    ... 34 more
Error occurred on line: 146 (Main)
java.lang.RuntimeException: Object should first be initialized (ImageView).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:32)
    at anywheresoftware.b4j.objects.NodeWrapper.innerInitialize(NodeWrapper.java:79)
    at anywheresoftware.b4j.objects.ImageViewWrapper.innerInitialize(ImageViewWrapper.java:39)
    at anywheresoftware.b4j.objects.LayoutBuilder.loadLayoutHeader(LayoutBuilder.java:136)
    at anywheresoftware.b4j.objects.LayoutBuilder.loadLayoutHeader(LayoutBuilder.java:154)
    at anywheresoftware.b4j.objects.LayoutBuilder.loadLayout(LayoutBuilder.java:77)
    at anywheresoftware.b4j.objects.PaneWrapper.LoadLayout(PaneWrapper.java:76)
    at b4j.example.main._appstart(main.java:264)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.ja
va:593)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
    at b4j.example.main.start(main.java:36)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
    at com.sun.glass.ui.In
vokeLaterDispatcher$Future.run(Unknown Source)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

I have Java 8u72 on both machines. What is the cause of this?
 
Last edited:

Erel

Administrator
Staff member
Licensed User
This issue is not related to B4J-Bridge. Please start a new thread in the questions forum.
 

Lyndon Bermoy

Member
Licensed User
Sir still there's no Bluetooth for the B4a-bridge? Because I have no wi-fi connection sometimes and I cant connect my phone thru USB Debugging mode. So my other way is to connect it thru Bluetooth
 

jcohedman

Member
Licensed User
Hi, my problem with RPI and b4j-bridge.jar:

B4X:
i@raspberrypi:~/b4jbridge $ java -jar b4j-bridge.jar
B4J-Bridge v1.00
Waiting for connections (port=6790)...
My IP address is: 192.168.0.11
Connected!
java.io.FileNotFoundException: /home/pi/b4jbridge/tempjars/AsyncInput1 (Permission denied)
    at java.io.FileOutputStream.open0(Native Method)
    at java.io.FileOutputStream.open(FileOutputStream.java:270)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
    at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:345)
    at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.run(AsyncStreams.java:219)
    at java.lang.Thread.run(Thread.java:745)
Error: (FileNotFoundException) java.io.FileNotFoundException: /home/pi/b4jbridge/tempjars/AsyncInput1 (Permission denied)
Waiting for connections (port=6790)...
My IP address is: 192.168.0.11
Connected!
B4X:
pi@raspberrypi:~ $ java -version
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) Client VM (build 25.101-b13, mixed mode)
pi@raspberrypi:~ $ javac -version
javac 1.8.0_101
pi@raspberrypi:~ $ ^C
pi@raspberrypi:~ $
can anybody help me?
 
Top