How run java web strat application with hsql and glassfish? - java

I have java program with main function, that packaged into jar archive. There is dao class with DataSource. An jdbc url to data file is expected an is passed as argument to main function. Everything works as standalone application, but how I must link jar file with database when they both in glassfish? For example, I put jnlp into glassfish docroot directory, and put HSQL database file with populated data too. Whta link I must pass tho that database? If I simple replace
"C:\path"
with
"http://localhost:8080\path_inside_docroot_folder"
I get EOFException in java when it tryies to read a file.
Off topic:
Also it very strange, when I created hsql database I write something like this:
jdbc:hsqldb:C:\\path\db_file.dat
But actually in the path there is no exactly db_file.dat. There are several files, like:
db_sile.dat.tmp
db_sile.dat.lck
db_sile.dat.log
db_sile.dat.properties
db_sile.dat.scrip
Can anyone solve my problem? May files mentioned upper influence to the problem or it is pure glassfish deploy problem?
If something unclear ask me.

The answer is you can not run HSQL inside as static resource glassfish. You can run HSQL server as HTTP server or as servlet if you deploy web application. The solution for my problem is to put JNDI file and java jar file as static resources in glassfish and run HSQL server in the same computer (where glassfish is running).

Related

Deploying a regular JAR to Tomcat server

I know this is a weird question but is it possible to somehow run a JAR with a main class on Tomcat like a WAR?
I'm aware that won't automatically give it any website capability.
I just want it to execute it inside the web server JVM with the isolation that it gives

How to include Hsql database in WAR File?

i am developing a little application in JAVA, in which i use HSQL database to store some statistics and perform some calculations, now the requirement of application is like
The web application should be packaged as a self-contained portable war file. The war should contain any/all 3rd party jars that it depends on.
It should be possible to download a fresh tomcat, install the war, and use web app immediately without any configuration.
All config parameters should have useful default values.
i have developed the application but i am not able to include thw HSQL database in WAR file, i have tried different tutorials and search on stack overflow but i can't find any solution,
please tell me the way how i include hsql database in war file ?
Create a java class that create HSQL database on tomcat start if not exist
path of HSQL database for exemple tomcat/conf:
Server server = new Server();
server.setDatabaseName(0, "test");
server.setDatabasePath(0, "file:/path/to/db");
server.start();

Birt: how to deploy a report in production?

I have just prepared a report with bird using eclipse plugin. It works.
Now I have deployed a birt 4.4 viwer on a Tomcat7. It works.
Now I put my report.rptdesign file insider birt folder under webapps in tomcat.
It does not work.
Obviously because:
the jdbc driver is encoded in report with full path that is obviously different from eclipse to tomcat;
birt needs a "org.eclipse.datatools_workspacepath" configured in tomcat (why????)
even if I configure above variable it complains about missing:
java.lang.NoClassDefFoundError: org/eclipse/datatools/enablement/ibm/util/ClientUtil
Yes I have used standard jdbc source (not "for query builder" one).
I would like to ask stack overflow why is so bloody complicated (and not documented) putting in production a simple report that uses a mysql jdbc jar.
Can you help me?
Thanks,
Mario
Well I don't understand all the question but I use birt with glassfish and jboss, you need to configure a JDBC in your server (I suppose you already have done that), then you have to change your Datasources erase all and use a JNDI URL with the name of your JDBC for example, if you create a datasource JDBC/test this is the JNDI url.
For the workspacepath I think this can be solved changing something in the birt war, go to META-INF and open the web.xml, then change this properties for another folders that have sufficient access permissions:
<param-name>BIRT_VIEWER_WORKING_FOLDER</param-name>
<param-name>BIRT_VIEWER_DOCUMENT_FOLDER</param-name>
<param-name>BIRT_VIEWER_IMAGE_DIR</param-name>
<param-name>BIRT_VIEWER_LOG_DIR</param-name>

Get JDBC connection working in play framework (java)

Was wondering, what steps am I missing to get a jdbc embeded h2 database working in my play application? Following these docs.
So far editted Application.conf file to contain this:
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:databases/test"
db.default.user=test
db.default.password="testtest"
Next I created a libs directory and added the jar file
h2-1.3.174.jar
Is this necessary or does the provided driver handle all types of h2 databases (embeded and server - I know it handles in memory)?
Now in the controler how can I access the database? Do I have to start/shutdown the database?
I know I can get connections from the getConnection() method in play.db. But everytime I execute a statement through this connection I get an exception saying no data is available. If I then check - looks like directory
databases/test
was not created so no database files exist.
What am I missing?
H2 works out of the box. Just create a new project in the terminal.
Otherwise, to your listing:
I think you should change db.default.url="jdbc:h2:databases/test" to db.default.url="jdbc:h2:mem:play"
don't need to create lib directories. It's all handeled by the build in dependency mgmt sbt
Just use the model objects and call save/update. No need to call start/shutdown
you are in a framework, it's all there ready for you...
I think you should start reading the documentation from the beginning to the end and examine the example applications. It's all there what you are looking for.
In addition to myborobudur's answer I'll only mention, that you don't need to use memory database, as you can for an instance use file storage (Embedded) or even run H2 as a server and then connect to it with TCP in Server Mode... Everything is clearly described in H2 documentation.

Best way to access a sqlite database file in a web service

First question from me on stack overflow.
I have created a java web application containing a web service using netbeans (I hope a web application were the correct choice). I use the web application as is with no extra frameworks. This web service use a sqlite JDBC driver for accessing a sqlite database file.
My problem is that the file path end up incorrect when I try to form the JDBC connection string. Also, the working directory is different when deploying and when running JUnit tests. I read somewhere about including the file as a resource, but examples of this were nowhere to be seen.
In any case, what is the best way to open the sqlite database, both when the web service is deployed and when I test it "locally"?
I don't know much about web services, I just need it to work, so please, help me with the technicalities.
Update
To put this a litle bit in context, some "println" code gives this:
Printing the work directory from a simple JUnit test gives
C:\MinaFiler\Work\SOA\BusTimetableWS
Invoking a similar web servic method returns
C:\Program Files\sges-v3\glassfish\domains\domain1
The connection string is formed from prepending "jdbc:sqlite:" to the path which at the moment is absolute:
C:\MinaFiler\Work\SOA\BusTimetableWS\src\java\miun\bustimetable\database\sqlit\BusTimetableWS.db
However, this fails because my tests throws exceptions stating database tables doesn't exist although they really do, I can see them with sqlite3.exe .
One way would be to use a config file that you can read and fetch your connection string from there.
I'm sure the framework you are using has some kind of standard way of saving configurations.
Another option would be to place the db in a known relative path from your main execution files. Then when executed fetch your current directory, and look for the db from that path.
In any case, what is the best way to open the sqlite database, both when the web service is deployed and when I test it "locally"?
The web service should use a DataSource to retrieve a connection from a connection pool configured at the application server level. In your unit test, use whatever you want (a standalone connection pool, a direct JDBC connection).
But in both cases, why don't you use an absolute path to the database file in your jdbc url? From How to Specify Database Files:
jdbc:sqlite:C:/work/mydatabase.db
The working directory wouldn't matter if you do so.

Categories

Resources