B4J Question VPS .jar error

yfleury

Active Member
Licensed User
Longtime User
Hi all!
After 3 long days to learn and setup a vps. is runing with a sigle web page: index.html
So I can do a static web or dynamic one in php mysql.

but I want to run a java web server with my .jar file.
I have java install on vps
I run my jar with
B4X:
/var/www/vhosts/mydomain.com# java -jar result.jar

But I have this error and I am stuck here. some help needed
B4X:
---------------> main
2023-04-09 01:44:36.663:INFO :cmvl.MLog:MLog-Init-Reporter: MLog clients using slf4j logging.
2023-04-09 01:44:37.141:INFO :cmvc.C3P0Registry:main: Initializing c3p0-0.9.5.2 [built 08-December-2015 22:06:04 -0800; debug? true; trace: 10]
2023-04-09 01:44:37.674:INFO :oejs.Server:main: jetty-11.0.9; built: 2022-03-30T17:44:47.085Z; git: 243a48a658a183130a8c8de353178d154ca04f04; jvm 11.0.18+10-post-Debian-1deb10u1
main._appstart (java line: 142)
java.io.IOException: Failed to bind to 0.0.0.0/0.0.0.0:2100
        at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:344)
        at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:304)
        at org.eclipse.jetty.server.Server.lambda$doStart$0(Server.java:401)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
        at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
        at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
        at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
        at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
        at org.eclipse.jetty.server.Server.doStart(Server.java:397)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:93)
        at anywheresoftware.b4j.object.ServerWrapper.Start(ServerWrapper.java:266)
        at b4j.example.main._appstart(main.java:142)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
        at b4j.example.main.main(main.java:28)
Caused by: java.net.BindException: Address already in use
        at java.base/sun.nio.ch.Net.bind0(Native Method)
        at java.base/sun.nio.ch.Net.bind(Net.java:459)
        at java.base/sun.nio.ch.Net.bind(Net.java:448)
        at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:227)
        at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:339)
        ... 23 more

main.main (java line: 28)
java.lang.RuntimeException: java.io.IOException: Failed to bind to 0.0.0.0/0.0.0.0:2100
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:140)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
        at b4j.example.main.main(main.java:28)
Caused by: java.io.IOException: Failed to bind to 0.0.0.0/0.0.0.0:2100
        at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:344)
        at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:304)
        at org.eclipse.jetty.server.Server.lambda$doStart$0(Server.java:401)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
        at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
        at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
        at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
        at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
        at org.eclipse.jetty.server.Server.doStart(Server.java:397)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:93)
        at anywheresoftware.b4j.object.ServerWrapper.Start(ServerWrapper.java:266)
        at b4j.example.main._appstart(main.java:142)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
        ... 2 more
Caused by: java.net.BindException: Address already in use
        at java.base/sun.nio.ch.Net.bind0(Native Method)
        at java.base/sun.nio.ch.Net.bind(Net.java:459)
        at java.base/sun.nio.ch.Net.bind(Net.java:448)
        at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:227)
        at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:339)
        ... 23 more
 
Solution
I will try that.
From internet, how to access the java web server : mydomain.com:8000 ? Or is it possible to acces it to port 80?

yfleury

Active Member
Licensed User
Longtime User
I will try that.
From internet, how to access the java web server : mydomain.com:8000 ? Or is it possible to acces it to port 80?
 
Upvote 0
Solution

Magma

Expert
Licensed User
Longtime User
I will try that.
From internet, how to access the java web server : mydomain.com:8000 ? Or is it possible to acces it to port 80?
If need port 80.. need to stop,uninstall default web services like apache,nginx, iis for windows... restart and then run yours
 
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
I desactivate Apache and try port 8000 and I get this error
B4X:
java.lang.RuntimeException: java.io.FileNotFoundException: /var/www/vhosts/mydomain.com/www/header.php (No such file or directory)
Then I upload folder www by ftp where is my .jar and it run ok

next test I try port 80
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I desactivate Apache and try port 8000 and I get this error
B4X:
java.lang.RuntimeException: java.io.FileNotFoundException: /var/www/vhosts/mydomain.com/www/header.php (No such file or directory)
Then I upload folder www by ftp where is my .jar and it run ok

next test I try port 80
If Apache is running on port 80 then you don't need to disable it so that you can run your B4J server on port 8000. There is no conflict. Unless you want to run your B4J server on port 80.
 
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
I try port 80 and 443 no acces
I stop apache
I stop Reverse Proxy Server (nginx)
no acces on port 80 or 443 listening by B4J serveur
On port 8000 it run only if apache is stop
 
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
Oups... on port 8000 it run ok with apache on
But it is note secure ssl.
Is it on b3j server side I have to check?
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
For my case, I don't want to interrupt or mess up with the default settings of the server installation. I just leave port 80 and 443 so I still can run PHP for app like PhpMyAdmin or Adminer to manage my MySQL database. I run my apps which are on port 8080 and 8888.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Oups... on port 8000 it run ok with apache on
But it is note secure ssl.
Is it on b3j server side I have to check?
Read this

You can for example set a port 7000 for non-SSL and redirect to port 8000 for SSL.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I also recommend you to create a let's encrypt certificate to enable https for your app.
 
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
I also recommend you to create a let's encrypt certificate to enable https for your app.
I will look that.
For my vps run with let's encrypt for main domain. I have to do it on port 8000
 
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
Ok my vps have let's encrypt I can use by Plesk. My domain on http switch auto to https (port 80 to 443 with apache)

Then without any change on vps, my domain on port 8000 show my web page (b4j) in http. When I switch to https, I have this error ERR_SSL_PROTOCOL_ERROR.

Let's Encrypt is set correctly for my domain. Why that's not apply for another port. Or how to do let's Encrypt on different port using plesk.
Can i use
B4X:
CSR
-----BEGIN CERTIFICATE REQUEST-----
B4X:
Private key (*.key)
-----BEGIN PRIVATE KEY-----
B4X:
Certificate (*.crt)
-----BEGIN CERTIFICATE-----
B4X:
CA certificate (*-ca.crt)
-----BEGIN CERTIFICATE-----
to my b4j webserver
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Certificates are for domains... at any port....

* caution certificates are only for domains... not IP's !!!
* also caution.... if you only setup subdomain.... for ex .. www. on certificate... it is better use only domain or *.yourdomain.com
* I think you must post the part of b4j server created to help you more.... here
 
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
My web server b4j is now running on vps on port 8000. So I want to thanks @aeric and @Magma for your help. It's appreciate.
I keep port 80 and 443 for web site for marketing for the app on b4j web server.
 
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
Take note you may need to stop and restart apache server when you renew certificate in the future.
B4j server run only on port 8000
Ports 80 and 443 is for web page in html to sell b4j web server
 
Upvote 0
Top