How to connect to the H2 HTTP Console using "Embedded server"?

1,983 views
Skip to first unread message

marcolopes

unread,
Nov 24, 2010, 10:11:28 AM11/24/10
to H2 Database
I have tested H2 as a server, and now i have it "embedded" in a
Eclipse RCP Java App.

Everything works just fine connecting to the Database engine. Embedded
(local) connection jdbc:h2:[file:][]

Now, can i connect to the H2 HTTP Console using the Embedded server?

Virtually, all Eclipse RCP views have browser capability, so the
preferred way would be to execute the console inside em RCP view.

Basically i need to set the browser url inside the view:
browser.setUrl(url);

But the H2 console must be called specifically with:
org.h2.tools.Server.openBrowser(url); This opens the the console into
an external browser and does not connect to the embedded browser.

thanks.

Sergi Vladykin

unread,
Nov 24, 2010, 10:41:43 AM11/24/10
to H2 Database
You should not use console but just start web server directly from
your app
org.h2.tools.Server.createWebServer().start();
for example on plugin initialization and then manually open views or
editors with browser and point it to correct url.

marcolopes

unread,
Nov 24, 2010, 11:06:42 AM11/24/10
to H2 Database
Great! Works like a charm.

I have a few doubts:

1) As far as i can see, the embedded server does not take
the .h2.server.properties file into account. Is this configuration
file only used with the local or remote server? If so, how can we
specify the PORT of the embedded server?

2) The console USES the .h2.server.properties. Can i specify a path
for the console to read that file? I can't find any methods in
org.h2.tools.Server (the purpose is, for example, to make a portable
app that will have the config file on the path we need to)

thanks.

On Nov 24, 3:41 pm, Sergi Vladykin <sergi.vlady...@gmail.com> wrote:
> You should not use console but just start web server directly from
> your app
> org.h2.tools.Server.createWebServer().start();
> for example on plugin initialization and then manually open views or
> editors with browser and point it to correct url.
>
> On Nov 24, 6:11 pm, marcolopes <marcolo...@netc.pt> wrote:
>
> > I have tested H2 as a server, and now i have it "embedded" in a
> >Eclipse RCPJava App.
>
> > Everything works just fine connecting to theDatabase engine. Embedded
> > (local) connection jdbc:h2:[file:][]
>
> > Now, can i connect to the H2 HTTP Console using the Embedded server?
>
> > Virtually, allEclipse RCPviews have browser capability, so the

Sergi Vladykin

unread,
Nov 25, 2010, 3:32:05 PM11/25/10
to H2 Database
To specify the port use string arguments like that
Server.createWebServer("-webPort", "100500").start();
See also http://h2database.com/javadoc/org/h2/tools/Server.html#main_String...

If you running inside of eclipse it would be better not to use
external config files.

marcolopes

unread,
Nov 30, 2010, 4:27:52 PM11/30/10
to H2 Database
Thanks. The web server parameters are clarified, but:

What about the ".h2.server.properties" that the CONSOLE reads to build
the SAVED SETTINGS?

#H2 Server Properties
#Tue Nov 30 21:02:02 GMT 2010
0=H2 (Server)|org.h2.Driver|jdbc\:h2\:tcp\://localhost/database|sa
1=PostgreSQL|org.postgresql.Driver|jdbc\:postgresql\:database|postgres
2=MySQL|com.mysql.jdbc.Driver|jdbc\:mysql\://localhost/database|root
3=H2 (Embedded)|org.h2.Driver|jdbc\:h2\:file\:\\\\eclipse\\\\database|
sa
webAllowOthers=false
webPort=8082
webSSL=false

I understand that webPort and webSSL are irrelevant for the Embedded
webServer, but the console IS reading the config file located in the
System USER folder...

On Nov 25, 8:32 pm, Sergi Vladykin <sergi.vlady...@gmail.com> wrote:
> To specify the port use string arguments like that
> Server.createWebServer("-webPort", "100500").start();
> See alsohttp://h2database.com/javadoc/org/h2/tools/Server.html#main_String...

Thomas Mueller

unread,
Dec 1, 2010, 2:54:39 PM12/1/10
to h2-da...@googlegroups.com
Hi,

The .h2.server.properties file is read even if you start the server
using Server.createWebServer. The port in the command line overrides
the port in the config file, however if ssl is enabled in the config
file, you can't override this in the command line (you can only enable
it in the command line, not disable).

In the newest version of H2, you can set the directory where the
properties file is loaded. However, it needs to be a directory that
exists. If you don't want to use the stored .h2.server.properties
file, you could use (it's a workaround, only works when since H2
version 1.2.147, it's using an in-memory file system to load and store
the server config):

Server.createWebServer("-properties", "memFS:").start();

This is a bit ugly. For the next version, the following will be
supported to mean "do not load or store any properties":

Server.createWebServer("-properties", "null").start();

Regards,
Thomas

Reply all
Reply to author
Forward
0 new messages