Dwagner
Dwagner

Reputation: 236

Where to put -ds.xml?

I am having trouble adding a datasource to my wildfly server using a -ds.xml file as recommended by the jboss doc. I have a maven project with a persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
   xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

   <persistence-unit name="primary">
      <jta-data-source>java:jboss/datasources/DvdRental4</jta-data-source>
      <properties>
         <property name="hibernate.hbm2ddl.auto" value="create-drop" />
         <property name="hibernate.show_sql" value="true" />
      </properties>
   </persistence-unit>
</persistence>

and a postgres-ds.xml in the root of the project:

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
    <local-tx-datasource>
        <jndi-name>DvdRental4</jndi-name>
        <connection-url>jdbc:postgresql://localhost:5432/dvdrental4</connection-url>
        <driver>postgresql-9.4.1208</driver>
        <user-name>postgres</user-name>
        <password>1234</password>
        <metadata>
            <type-mapping>PostgreSQL</type-mapping>
        </metadata>
    </local-tx-datasource>
</datasources>

When running mvn package and deploying the .war, I get an error that DvdRental4 is missing. So I suppose I need to place the postgres-ds.xml somewhere specific, but where? Or maybe the xml files are wrong? If needed, I can also provide the pom.xml. I already created the database dvdrental4, so this shouldn't be an issue.

I also read somewhere that you have to place the -ds.xml file in the deploy folder, I only have a wildfly/standalone/deployments folder, and putting it in there didn't work.

EDIT: Wildfly gives the following error:

ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) WFLYCTL0013: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {
    "WFLYCTL0412: Required services that are not installed:" => ["jboss.naming.context.java.jboss.datasources.DvdRental4"],
    "WFLYCTL0180: Services with missing/unavailable dependencies" => [
        "jboss.persistenceunit.\"dvdrental-gruppe-4.war#primary\".__FIRST_PHASE__ is missing [jboss.naming.context.java.jboss.datasources.DvdRental4]",
        "jboss.persistenceunit.\"dvdrental-gruppe-4.war#primary\" is missing [jboss.naming.context.java.jboss.datasources.DvdRental4]"
    ]
}

Upvotes: 3

Views: 3829

Answers (3)

Dwagner
Dwagner

Reputation: 236

I think I solved it by just putting the *-ds.xml file in the project/src/main/webapp/WEB-INF of my maven project, at least there is no error saying the datasource couldn't be found. I also changed the postgres-ds.xml a bit:

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
    <datasource jndi-name="java:jboss/datasources/DvdRental4" pool-name="DvdRental4"
        enabled="true" use-java-context="true">
        <connection-url>jdbc:postgresql://localhost:5432/dvdrental4</connection-url>
        <driver>postgresql-9.4.1208.jar</driver>
        <security>
            <user-name>postgres</user-name>
            <password>1234</password>
        </security>
    </datasource>
</datasources>

Note: I deployed the driver as a .jar, so that is why I can specify the driver directly as a .jar, I think.

Upvotes: 3

Will Tatam
Will Tatam

Reputation: 572

The ability to deploy datasources was not a feature that made it between JBoss 5 and the AS7 rewrite, only the deployable jms destinations. You will need to configure the server to define the datasource, before you deploy your application

Upvotes: 0

fhossfel
fhossfel

Reputation: 2191

The JNDI name you specified for your datasource is "DvdRental4". But the persistence context specifies "java:jboss/datasources/DvdRental4". I am not sure whether that is correct. Either try "java:jboss/datasources/DvdRental4" in both places or (even better) use the Boss JNDI view to see where the datasource is actually deployed.

Upvotes: 0

Related Questions