I'm trying to connect a Derby database with my Open Liberty application, but I can't get it to work. I don't think I understood the process correctly. Here's what I did.
I downloaded db-derby-10.15.2.0-bin.tar.gz
from the Derby website and extracted it into the root folder of my project.
I put the following into my server.xml
file:
<!-- Derby Library Configuration -->
<library id="derbyJDBCLib">
<fileset dir="db-derby-10.15.2.0-bin/lib" />
</library>
<!-- Datasource Configuration -->
<dataSource id="derbyjpadatasource" jndiName="jdbc/my-project">
<jdbcDriver libraryRef="derbyJDBCLib" />
<properties.derby.embedded databaseName="myDB" createDatabase="create" />
</dataSource>
Created a persistence.xml
file in my META-INF
folder:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2"
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_2.xsd">
<persistence-unit name="jpa-unit" transaction-type="JTA">
<jta-data-source>jdbc/my-project</jta-data-source>
<properties>
<property name="jakarta.persistence.schema-generation.database.action"
value="create"/>
<property name="jakarta.persistence.schema-generation.scripts.action"
value="create"/>
<property name="jakarta.persistence.schema-generation.scripts.create-target"
value="createDDL.ddl"/>
</properties>
</persistence-unit>
</persistence>
And edited my pom.xml
file so it contains this:
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.7.1</version>
<configuration>
<copyDependencies>
<location>${project.build.directory}/liberty/wlp/usr/shared/resources</location>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
</dependency>
</copyDependencies>
</configuration>
</plugin>
The project compiles and runs, but any operations with persistent object result in errors. This is one of the warnings I see when running the server:
DSRA4000E: No implementations of org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource40
for dataSource [derbyjpadatasource] with library derbyJDBCLib were found.
The name or location of the JDBC driver JAR files may be incorrect
or inaccessible. Searched in: []. Searched in packages: [org.apache.derby.jdbc].
EDIT: New error message after Scott Kurz's suggestion:
DSRA4000E: No implementations of
org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource40 were
found for dataSource[derbyjpadatasource] with the library
derbyJDBCLib. The name or location of the JDBC driver JAR files
may be incorrect or inaccessible. Searched in
[/home/(my_usr)/Desktop/Projects/proj1/target/liberty/
wlp/usr/shared/resources/derby-10.15.2.0.jar,
/home/(my_usr)/Desktop/Projects/proj1/target/liberty/
wlp/usr/shared/resources/derbyshared-10.15.2.0.jar]. Searched in
packages: [org.apache.derby.jdbc].