B4J Question Deployment of B4J Websocket apps

B4JExplorer

Active Member
Licensed User
Longtime User
Hi,

I've moved to a VPS server, and am confused about the setup, especially in terms of folder structure.


As a test for deployment, say I created an application called b4jwebsocketstest, embedded in a b4jwebsocketstest.jar.
The domain e.g. is b4jwebsocketstest.com


My questions are regarding deployment. I have a VPS server, and have installed Java 8.

The development folders on my local PC, and some of the files, are as follows:
../B4J/b4jwebsocketstest
../B4J/b4jwebsocketstest/objects/ b4jwebsocketstest.jar
../B4J/b4jwebsocketstest/objects/www
../B4J/b4jwebsocketstest/objects/www/index.html
../B4J/b4jwebsocketstest/objects/www/b4j_ws.js
, etc.

, and I use this in the code, to map to the test form
srvr.AddWebSocket( "/ws", "frm_b4jwebsocketstest" )


I’ve opened up a port for the app on the server, incoming and outgoing. Same as the server port, referenced in the application.

Everything works fine in localhost.

The root folder for my app is, e.g. /home/myapp, so we have

/home/myapp
/home/myapp/logs
/home/myapp/public_html
/home/myapp/public_ftp
/home/myapp/etc
/home/myapp/tmp,

etc.

Command line that I’m using (unsuccessfully, so far), for running the app:

nohup /usr/java8/jre1.8.0_121/bin/java -jar b4jwebsocketstest.jar > nohup.out &


These are the questions:

1. I’m not sure where to put the jar. Erel, you mentioned to put it in any folder, but not to put it in /home/ myapp /public_html, because then it would be visible, along with any subfolders. That’s fine, but the index.html has to go in /home/ myapp /public_html, because I want the app to be visible at www.b4jwebsocketstest.com. But if we do that, then the b4jwebsocketstest.jar, is no longer in the same relative position with the main index.html, as in Dev (../objects/ b4jwebsocketstest.jar, and ../objects/www/index.html).

1a. If I put b4jwebsocketstest.jar in some random folder, e.g. /home/myapp/jettyapp in a different relative position from index.html than the development projects, then it won’t be able to locate index.html and other files (I think).

1b. Instead of explaining, can you list a sample folder structure for the .jar and associated js, css, and html files?


2. Do we need to install jetty on the server? Or is the entire jetty code, embedded in the B4J app, so Jetty doesn't need to be installed on the server? It was mentioned in https://www.b4x.com/android/forum/threads/server-run-a-server-on-a-vps.60378/#content, that the developer installed Jetty, along with Java.


3. If I have to install Jetty on the server, where is the link for Jetty? Should it be downloaded from here: http://www.eclipse.org/jetty/download.html?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Erel, you mentioned to put it in any folder, but not to put it in /home/ myapp /public_html, because then it would be visible, along with any subfolders.
You must be more accurate. Otherwise it is impossible to help you.

1. I said not to put it under public_html. I never said not to put it under /home.
2. The short tutorial says that you don't need to install anything. Just to copy Java JRE to the server.
3. You should trust me that if there was any other component required then the tutorial would have said so.

Compile your app in release mode. The jar file will be created in the Objects folder. Take the jar file and the www folder and copy them to your server.

The structure is:

www folder
YourJar.Jar
 
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
" I said not to put it under public_html. I never said not to put it under /home."

I think you're misunderstanding me.

Public_html is under home/(user)/public_html, on the VPS they gave me. (It's also under root, of course) And that's the only folder I can put the index.html file, so that the form will be visible directly under www.b4jwebsocketstest.com from a browser. But if I put that index.html file under public_html (as opposed to under www), then the directory relationship with the .jar can't be mirrored anymore.

I'm just asking for a sample folder structure on the server, Erel. There's obviously some misunderstanding here, so it would be easier to have a concrete sample of the server folder structure, based on the b4jwebsocketstest.com, and home/myapp subfolders. Is that possible?

"The short tutorial says that you don't need to install anything. Just to copy Java JRE to the server."

Ok, that's fine. I was just going by what the developer said:

"Hi all, Erel

Hope this is the right place. I have setup a VPS - Linux, I have installed Jetty and Java."

C'mon, I'm not making this up. I'm sincerely confused, and I've tried several configurations. This is after leaving a host which explicitly supported Jetty applications, but couldn't get mine working, and starting messing with the js libraries. I actually paid them for a year of hosting, and have to take that as a loss. I've moved to a VPS now, and am trying to get this thing up and running, so people can freely use it.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm just asking for a sample folder structure on the server, Erel
This is the structure (as written in the previous post):
yourjar.jar
www folder


I think that you are confused with the relationship between the B4J server and the apache server. There is none. The B4J server listens to a different port (not 80). It has nothing to do with public_html.
 
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
This is the structure (as written in the previous post):
"yourjar.jar
www folder"

Yes, that is the folder structure, on the localhost.


I think that you are confused with the relationship between the B4J server and the apache server. There is none. The B4J server listens to a different port (not 80). It has nothing to do with public_html.

Yes, I am confused. If I put the index.html file in the www folder, then how will it be visible from www.b4jwebsocketstest.com? Won't the browser have to point to www.b4jwebsocketstest.com/www? (I think that the answer to THIS question, will probably clear up my confusion).

Erel, I'm really sorry. But my experience with php, made use of tools that already provided a folder structure, and had detailed documentation for deployment. And I've always had someone to help me deploy Groovy apps, so those weren't a problem. But I'm missing something fundamental, about where files are supposed to be, and how you get them to appear from the root of your website in the browser.

I'll upload the test project, per alwaysbusy suggestion, and then get their exact folder structure, and try to mirror it.
 
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
Can you upload your test project? I'll try to mimic it on our VPS and post you my findings.

Alwaysbusy,

There's nothing special about the project (I think). It's just some misunderstanding I have, about deployment, folders and handlers.

If you get this working, can you forward the exact server structure you used? And anything you did, with the configuration?

Thanks, chief.
 

Attachments

  • jettytest.zip
    125.2 KB · Views: 228
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
Just uploaded it to our VPS and I don't see anything strange happening:

I've put it now just in our root of our vps:

upload_2017-1-23_14-47-42.png


upload_2017-1-23_14-48-13.png


In the browser, I go to our server, using port 12612 (the one you've set):
upload_2017-1-23_14-48-56.png
 
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
Huh. So you're actually putting it in the root. The support person for my VPS, insisted (in a support chat, unrelated to the topic), that everything needed to be put in home/(user)/public_html and subfolders. He said not to put it anywhere in root or its subfolders.

In fact, when I place the index.html file in home/(user)/public_html, that's the only time it shows up (I've tested and confirmed this). Nothing is visible from the browser, if the files are placed anywhere in the root or subfolders.

Ok, I gotta think about this, thanks VeryBusy (Correction, Alwaysbusy). Maybe I just need to bite the bullet, and recode this in php or groovy. I can just forward the main application jar to people I've promised it to, and explain how to run it in their localhost.


If you have any more suggestions, please let me know, thanks.



Just uploaded it to our VPS and I don't see anything strange happening:

I've put it now just in our root of our vps:

View attachment 52261
View attachment 52262

In the browser, I go to our server, using port 12612 (the one you've set):
View attachment 52263
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
The support person for my VPS, insisted (in a support chat, unrelated to the topic), that everything needed to be put in home/(user)/public_html
He is probably thinking in 'apache' terms, but B4J webapps have nothing to do with this. for normal 'apache' apps, that is probably where you have to put your index.html. For B4J, it doesn't matter where on the server you put it, as long as the port is open.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi,
maybe I found where the miserunderstandig comes from.
When you type "www.b4jwebsocketstest.com" as the browser's URL you fundamentally ask to find content from port 80 (standard http) and the program responding on that port is Apache (which will look for index.html in your /home/(user)/public_html folder). BTW, if you don't need it you can turn it off.
If you type "www.b4jwebsocketstest.com:12612" the program responding will be your b4j's server and it will take its index.html page from its www directory.

To comply with Erel's advice, deploy your app in a folder like:
/home/b4japps/myapp (this is where you put your b4jwebsocketstest.jar
and
/home/b4japps/myapp/www (this is where you will put your index.html to be served by your app

Note: I introduced an extra folder (b4japps) because for sure you will deploy a few more b4j servers (each running on its specific port).

In conclusion, structure your folders as suggested and just add the port reference to your browser's URL.
 
Last edited:
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
Hi,
maybe I found where the miserunderstandig comes from.
When you type "www.b4jwebsocketstest.com" as the browser's URL you fundamentally ask to find content from port 80 (standard http) and the program responding on that port is Apache (which will look for index.html in your /home/(user)/public_html folder). BTW, if you don't need it you can turn it off.
If you type "www.b4jwebsocketstest.com:12612" the program responding will be your b4j's server and it will take its index.html page from its www directory.

To comply with Erel's advice, deploy your app in a folder like:
/home/b4japps/myapp (this is where you put your b4jwebsocketstest.jar
and
/home/b4japps/myapp/www (this is where you will put your index.html to be served by your app

Note: I introduced an extra folder (b4japps) because for sure you will deploy a few more b4j servers (each running on its specific port).

In conclusion, structure your folders as suggested and just add the port reference to your browser's URL.


"If you type "www.b4jwebsocketstest.com:12612" the program responding will be your b4j's server and it will take its index.html page from its www directory."

Yeeeeessss! That's correct. I tested the button, and the _click event activated and executed correctly.

I located this video, which clears up some of the confusion for me, regarding public_html, at the very beginning:

"To comply with Erel's advice, deploy your app in a folder like:
/home/b4japps/myapp (this is where you put your b4jwebsocketstest.jar
and
/home/b4japps/myapp/www (this is where you will put your index.html to be served by your app"

I did the simplest, in order to get it working, with the 12612 added -

/home/(user) - jar
/home/(user)/www - index.html, etc.


"Note: I introduced an extra folder (b4japps) because for sure you will deploy a few more b4j servers (each running on its specific port)."

Yep, understand, I'll take care of this, after getting the main application tested. (I understand it's defaulting to 80, and that using the (user) root has to be temporary).

"In conclusion, structure your folders as suggested and just add the port reference to your browser's URL."

So I guess the final question is, how do you avoid putting in the port? Is there something in cpanel, that will default www.website.com, to www.website.com:12612?

Soooo close, finally. Thanks, man.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
I fear that to avoid the port number in the URL you need to turn off Apache and program your b4j server to listen on port 80 instead of 12612 or whatever port it currently uses.
Or eventually configuring Apache to listen on a non standard port different from 80 (and 443 if needed).


udg
 
Last edited:
Upvote 0

mindful

Active Member
Licensed User
Or you can keep your apache running on port 80 and configure it to run as a reverse proxy. It will accept connections on port 80 (or whatever port you have setup and redirect them to you b4j app that is running on 12612).

You could search on google how to setup apache as a reverse proxy with websockets or maybe try to talk with the guys from your vps support to set this up. This way you keep apache running (maybe you need it to run other webapps or websites) and you can run many b4j server apps on the same vps (they will be listening on different ports) it will look something like:

www.website.com -> app1:12612
www.website.com/otherapp -> app2:21612

And you can even use virtual hosts from apache and map many domains to the same server:

www.website2.com -> app3:31612

Also ngix server does this too (runs as a reverse proxy) ...

Or you can follow @udg advice and stop the apache from listening on 80 and setup your b4j app to listen to that port!
 
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
Or you can keep your apache running on port 80 and configure it to run as a reverse proxy. It will accept connections on port 80 (or whatever port you have setup and redirect them to you b4j app that is running on 12612).

You could search on google how to setup apache as a reverse proxy with websockets or maybe try to talk with the guys from your vps support to set this up. This way you keep apache running (maybe you need it to run other webapps or websites) and you can run many b4j server apps on the same vps (they will be listening on different ports) it will look something like:

www.website.com -> app1:12612
www.website.com/otherapp -> app2:21612

And you can even use virtual hosts from apache and map many domains to the same server:

www.website2.com -> app3:31612

Also ngix server does this too (runs as a reverse proxy) ...

Or you can follow @udg advice and stop the apache from listening on 80 and setup your b4j app to listen to that port!

It's definitely doable, according to the hosting service, although they can't support it.

Not really worried much about it, right now. Now that the main application is up and running and production-testable (Can't thank you enough, udg), I can focus on improving the interface, and add to the functionality.
 
  • Like
Reactions: udg
Upvote 0
Top