How to embed database in javadb with my javafx standalone database application - netbeans

I am creating a desktop application using JavaFx with database integration. When I run the Java DB server from programfiles/sun/javadb it shows me ClassNotFound Exception but the same thing when i run from NetBeans IDE it works.. So please tell me how to make my application run without NetBeans IDE. I also want to create its exe. How can we embed database with JAR. while creating exe.

You will need to include the Derby jar files (at least derby.jar, maybe some others) in your application CLASSPATH.

I'm an Eclipse user so I can't help you with Netbeans but here how it's done in Eclipse: in this explanation I used JPA in Java SE (this is from a real project so I hope I could help)
First export the the project as a jar:
Click File -> export -> and choose Java/Runnable JAR file -> Click
Next
-> Eclipse automatically will find and select your Main class + select the location where you want eclise to save the JAR file
-> select package required libraries into generated JAR -> click finish.
Next, I assume you create your database manually, let's assume the the db folder is called finance. now put the db folder in the same folder as the JAR, I used JPA in this project of mine so here is the persistence.xml
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="FinanPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>lite.money.entities.Category</class>
<!-- <shared-cache-mode>NONE</shared-cache-mode> -->
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:finance;" /> <!-- Derby -->
<property name="eclipselink.ddl-generation.output-mode" value="database" />
</properties>
</persistence-unit>
this line:
<property name="javax.persistence.jdbc.url" value="jdbc:derby:finance;" />
as you can see finance is the path to your DATABASE FOLDER, and since it's a relative path; the db driver will search for the folder in the same folder that the JAR exist.
and this how I embed JavaDB with JavaFX applications (using JPA of course).

Related

What is dedicated .org.eclipse.wst.jsdt.core.javascriptValidator.launch file on eclipse project .externalToolBuilders folder?

I have problem to deploy my project to run on tomcat server on Eclicpse IDE after when it imported from git repository. And nowhere I can find the problem. Now I am looking into the project folder structure and found .externalToolBuilders folder with .org.eclipse.wst.jsdt.core.javascriptValidator.launch file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="false"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_DISABLED_BUILDER" value="org.eclipse.wst.jsdt.core.javascriptValidator"/>
<mapAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
</launchConfiguration>
I want to know what this file do and or it can has the influence for my problem?
This is a launch configuration file for an Ant Builder. It looks like this builder is disabled. Builders are listed in the 'Builders' tab on the Project Properties dialog.
It is unlikely that this is causing whatever problem you are having.

Arquillian: Do I need domain.xml and arquillian.xml for minimal Glassfish Embedded tests with Derby DB?

in the internet I often find recent but contrary information on this topic..., thus I would like to ask a question on minimum requirements.
My goal is to do a very simple integration test of simple EJB 3.1 application:
Simple JPA 2.0 functionality with EclipseLink
Arquillian with JUnit for testing
Maven
Derby DB (in memory or file in ./target), JTA persistence context.
Embedded Glassfish in Arquillian
So I just want to do a simple JPA test. I get my Glassfish running in Arquillian, but when doing my JPA stuff, my app always fails to handle the Derby DB (tells me there are no tables etc.), but DDL files look sane.
I played around with providing schema name, user etc. in my persistence.xml, but nothing helps. Sometimes a come accross posts telling me about making changes in a minimal domain.xml for the embedded Glassfish to match my persistence.xml or to adapt the arquillian.xml.
My question is: for this minimal approach - do I really require that src/test/glassfish/domains/domain1/domain.xml or arquillian.xml?
I am quite sure that some time ago I managed to do so with Embedded Glassfish but using Hibernate 4 as JPA provider. I have no access to the project anylonger and thus cannot tell the difference except that I definetely did not add a domain.xml etc.
Posts like (other question here) really do confuse me.
Important is that I am not using a managed server, but an embedded one.
Thanks and cheers,
Timo
Here is one of my versions, please see my following comment.
<persistence-unit name="localiser-core" transaction-type="JTA">
<jta-data-source>jdbc/__default</jta-data-source>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url"
value="jdbc:derby:memory:test;create=true" />
<property name="javax.persistence.jdbc.user" value="" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="eclipselink.target-database" value="Derby"/>
<property name="eclipselink.ddl-generation.output-mode"
value="database" />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.application-location" value="target" />
<property name="eclipselink.create-ddl-jdbc-file-name" value="create.sql"/>
<property name="eclipselink.drop-ddl-jdbc-file-name" value="drop.sql"/>
<property name="eclipselink.debug" value="ALL"/>
<property name="eclipselink.weaving" value="static"/>
<property name="eclipselink.logging.level" value="FINEST"/>
<property name="eclipselink.logging.level.sql" value="FINEST"/>
<property name="eclipselink.logging.level.cache" value="FINEST"/>
</properties>
</persistence-unit>
Since your connection URL is: jdbc:derby:memory:test;create=true, what you have told Derby is: connect to a database in the folder 'test', relative to the current working directory of wherever Derby is started, and if that database 'test' is not present in the current working directory, create it from scratch.
So one possibility is that your application has a different current working directory each time, or perhaps that something else in your application is clearing out your current working directory each time you run the application.
Thus Derby doesn't find the previous database in that location, and so it creates a fresh new one.
One way around this is to specify a more explicit location for your database, by using a connection URL such as: jdbc:derby:memory:/users/timo/testdb
Then create the database once, up front, and subsequent to that your application will find the database in the specified location and use it.

Eclipse - JBoss (Hibernate) tools not showing any tables

I want to use JBoss tools in Eclipse to generate java code from DDL.
I am using the following:
Oracle XE
Eclipse Helios (SpringSource version)
JBoss Tools
I've configured the hibernate.cfg.xml (as below) and created a sample application to insert and update records in XE and it works fine.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:#localhost:1521:xe</property>
<property name="hibernate.connection.username">admin</property>
<property name="hibernate.connection.password">admin</property>
<property name="hibernate.default_schema">users</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="users.hbm.xml"/>
</session-factory>
</hibernate-configuration>
But when I select (in hibernate perspective) File->New->Hibernate console configuration, I get the following in the "Hibernate Configurations" window:
-Console
+Configuration
+Session Factory
+Database
Expanding the "Database" above shows "pending" for few seconds and then shows nothing. I expecting it to show the table names. I am struggling to find out the reason. There are no exceptions\errors in any of the log files, nothing on console, all XE services are running, hibernate configuration is correct because my sample app works.
While creating the "console configuration" I created a new database connection and have done the "Test connection" and it shows "Ping successfully" message. I've used the following in the configuration:
hibernate.connection.url jdbc:oracle:thin:#localhost:1521:xe
hibernate.dialect org.hibernate.dialect.Oracle10gDialect
hibernate.connection.driver_class oracle.jdbc.OracleDriver
Any help is appreciated. Thanks.
Fixed it..
had to change the following
<property name="hibernate.default_schema">users</property>
to
<property name="hibernate.default_schema">USERS</property>
I had this same problem, then found out my database had no tables in it and felt embarrassed. After creating a quick table, it worked. Will never get that time back..

JPA Entity (in multiple persistence-unit) in OSGi (Spring DM) Environnement is confusing me

I'm a bit confused about a strange behavior of my JPA's related objects.
I have three bundle :
The User bundle does contain some user-related objects, but mainly the User object.
The Energy bundle does contain some energy-related objects, and particularly a ConsumptionTerminal which contains a List of User.
The Index bundle does contain an Index object that has no dependency at all.
My OSGi environment is the following :
A DataSource bundle that provide 2 services : dataSource and jpaVendorAdapter.
The three bundles. They consume dataSource and jpaVendorAdapter.
Their module-context.xml file look like :
And they all have a persistence.xml file :
User
<?xml version="1.0" encoding="UTF-8"?>
<persistence>
<persistence-unit name="securityPU" transaction-type="JTA">
<jta-data-source>java:/securityDataSourceService</jta-data-source>
<class>net.nextep.amundsen.security.domain.User</class>
<!-- [...] -->
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.logging.level" value="INFO" />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.orm.throw.exceptions" value="true" />
</properties>
</persistence-unit>
</persistence>
Energy
<?xml version="1.0" encoding="UTF-8"?>
<persistence>
<persistence-unit name="energyPU" transaction-type="JTA">
<jta-data-source>java:/securityDataSourceService</jta-data-source>
<class>net.nextep.amundsen.security.domain.User</class>
<class>net.nextep.amundsen.energy.domain.User</class>
<!-- [...] -->
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.logging.level" value="INFO" />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.orm.throw.exceptions" value="true" />
</properties>
</persistence-unit>
</persistence>
Index : This one has the most simple persistence.xml with just the Index class (no shared Class).
I'm using named #PersistenceUnit annotation like #PersitenceUnit(name = 'securityPU') (for the User bundle).
And finally, I'm using EclipseLink as Jpa provider and Spring DM (+ Spring DM Server in the development process)
The problem is the following :
When the User bundle is deployed, I'm able to persist User objects.
When the User bundle and Energy bundles are both deployed, I'm not able to persist User objects (neither the Energy object). But I don't have any exception at all !
There is no problem at all with the Index bundle.
The bug is dataSource independent (I tried with PostgreSQL and MySQL so far).
My first conclusion was that the <class>net.nextep.amundsen.security.domain.User</class> in both persistence unit was causing the trouble. I tried without it (and hiding the User dependent object in the Energy bundle) but it failed too.
I'm a bit confused about that bug. I'm also not quite sure about the transaction management in this context.
I wasn't the one who designed this architecture (but I tell my intern OK without testing it.. shame on me) but if I could understand this bug and maybe fix it without rewrite the bundle (and break my intern work), I would appreciate. Am I doing something wrong ? (it's obvious, but what..) Did I miss something while reading documentation ?
By the way, I'm also looking for some best practices or advices when it comes to JPA, EclipseLink (or whatever JPA Provider) and Spring DM (and OSGi in general). I found interesting slides from Mike Keith about this topic (by browsing Stackoverflow).
Ok, it seems stupid to answer my own question (because it's actually not an answer but a step to the understanding of the bug).
emphasized text
It might be related to load-time weaving. I'm not quite alright with this concept yet, so I'm going to learn about it..

Eclipse + Tomcat = wrong docBase?

I am running Eclipse Galileo with Tomcat 6.0.18.
Currently, I have a working application with the m2Eclipse plugin installed. It deploys to Tomcat and I am able to test my application.
I am wanting to switch over to just using the Maven Eclipse plugin. The problem is that Tomcat is refusing to deploy my application.
I have converted my web project to a dynamic web module and set all my build paths as close to my previous m2Eclipse workspace as possible and still no success. When I hit the url, I just get a blank page.
What I did narrow down was that in my m2Eclipse workspace, when Tomcat publishes the web project, the context.xml file in [TOMCAT_HOME]\conf\Catalina\localhost has the docBase set to the "Web Content" directory. While my Maven Eclipse workspace, the context.xml that Tomcat publishes to have the docBase set to "Java Source" directory.
What do I need to do to have my "Maven Eclipse" workspace integrated with Tomcat work successfully like my m2Eclipse workspace?
Seams you don't have proper configuration of maven-eclipse-plugin if you converted project manually to dynamic web module.
According to maven-eclipse-plugin documentation you need to specify additional configuration in your pom (or by passing -D parameters) for WTP project. Key is <wtpversion> tag.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<projectNameTemplate>[artifactId]-[version]</projectNameTemplate>
<wtpmanifest>true</wtpmanifest>
<wtpapplicationxml>true</wtpapplicationxml>
<wtpversion>2.0</wtpversion>
<manifest>${basedir}/src/main/resources/META-INF/MANIFEST.MF</manifest>
</configuration>
</plugin>
Look into using the Tomcat plugin for Eclipse.
I went the other way, taking an existing Eclipse Dynamic Web project and converting it to a Maven project. To get them both to work will likely involve manually editing the project files.
First choose to "Customize View" from the little arrow in your "Project Explorer" view and uncheck ".* resources" from the list of filters. This will allow you to view the contents of the .settings directory.
Open org.eclipse.wst.common.component. It's an XML file that tells the WTP project where the webapp files are located.
To make it work with Maven, you'll need it to look something like:
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="(project name)">
<wb-resource deploy-path="/" source-path="/src/main/webapp"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/resources"/>
<property name="context-root" value="(project URL)"/>
<property name="java-output-path"/>
</wb-module>
</project-modules>
There are two "variables" in there that you'll probably want to leave alone - the name of the project (as it appears in the "Servers" view) and the name of the URL where the project is deployed on Tomcat.
I think that's the only change really needed to get WTP to play nice with Maven, since that tells it where to find the various files it needs to deploy to Tomcat.