B4J Question Webapp VPS problem....

Zoltan Dinya

Member
Licensed User
Longtime User
Hi! I have a problem with my first Hello World webapp, which is a modification of this: https://www.b4x.com/android/forum/threads/webapp-hello-world-web-app.39808/

On my computer it works fine, without issue. I have an Ubuntu14.04 VPS with installed Java7

I compile .jar file with B4J Compile+Run menuitem, in "Release" mode, #MergeLibraries: true. I uploaded .jar to the VPS /var/www folder and the projects other files (b4j_ws.js, index.htm, index.css) to a /var/www/html folder, and the html side works fine, you can check it: http://82.102.5.102/

misshost02.jpg

The problem is the .jar file. If I want to run it (see screenshot!) it starts, I get a few system message, but then it "freezes" and I don't get back the cursor, independently from the time. The console doesn't react, only a CTRL-ALT-DEL helps, which restarts the VPS. Suspicious? I think, that .jar doesn't run on the VPS. Is the .jar file correctly compiled.....?

And if I don't restart, on the html screen in my Google Chrome (v45.0.24...) the webapps function buttons don't work. In the Chromes console comes "WebSocket connection to 'ws://82.102.5.102/ws' failed: Error during WebSocket handshake: Unexpected response code: 404" message.

Can anybody helps me fix the problem....? Thank you in advance!!
 

billzhan

Active Member
Licensed User
Longtime User
You are running a command line (from chrome) to start your .jar. It doesn't freezes, it's waiting for messages to print, a CTRL-ALT-DEL will stop the app.

Use nohup & to keep it it running in the background. see https://www.b4x.com/android/forum/threads/server-login-system-filters-tutorial.39020/#content.

It seems that you are running a apache server on your VPS (Apache/2.4.7 (Ubuntu) port 80 ), and it directs all http requests to /var/www/html folder. You can use command line ( pgrep apache ) to find process information.

You can try :
After compile your project in release mode, copy the Objects folder( .jar & www folder) to your home folder (Ubuntu: something like /home/yourusername or /root as root user) .
B4X:
cd /home/yourusername/Objects
nohup java -jar helloworld.jar > nohup.out &
All messages will be written to nohup.out file.
You can now access your app by http://82.102.5.102:portno (b4j Port no , apache is using port 80)
 
Upvote 0

Zoltan Dinya

Member
Licensed User
Longtime User
Thank you, Billzhan, I have tried it, but.....

I have copied the whole Object folder of the demoapp to my root directory, I starts the .jar and :

hellow002.jpg

Is this reaction correct from the system?

And the "but" comes now:

hellow001.jpg

82.102.5.102:80 and the damned function buttons doesn't work..... :(

Can I ask you to login to my server (if you send me a mail adress, I can send you the password) to check it......? Thank you very much in advance!!
 
Upvote 0

billzhan

Active Member
Licensed User
Longtime User
View the nohup.out to see the logs to see if it's running.

82.102.5.102:80 is served by apache (port 80 is the default port)

b4j (jetty) server : http://82.102.5.102:51042 .

Your server is working, but the http static files (defualt path /Objects/www) is not found .


I'll pm my email to you.

B4X:
'as root user, your files should locate in /root folder
'copy Objects folder to /root folder
' typo:  nohup java /jar -->  nohup java -jar

cd /root/Objects
nohup java -jar xxx.jar > nohup.out &
 
Last edited:
Upvote 0

billzhan

Active Member
Licensed User
Longtime User
B4X:
# check if apache is running   
root@vps-110:/Objects# pgrep apache
1226
1228
1229
# apache is running  with port 80  ; it will start every time the VPS starts
# if you want to remove apache
# apt-get purge apache2


# check if java is running
root@vps-110:/Objects# pgrep java
1348
# java is running

## START a b4j server  
# first stop java and apache
pkill java
pkill apache

# run the server
cd /Objects
nohup java -jar WebAppHelloWorld.jar > nohup.out &

visit:
http://82.102.5.102:51042/
 
Upvote 0
Top