How to deploy a DataSource in jboss at application level ?

Data source definitions can be also packed in your application so that you don’t have to modify at all the server configuration. When deploying data source as part of your application you have to add them in a specific folder, which varies depending on the application package format.

For example, for a Web application, check the kitchensink example from WildFly quickstarts:

src
├── main
│   ├── java
│   │   └── org
│   │       └── jboss
│   │           └── as
│   │               └── quickstarts
│   │                   └── kitchensink
│   │                       ├── controller
│   │                       │   └── MemberController.java
│   │                       ├── data
│   │                       │   ├── MemberListProducer.java
│   │                       │   └── MemberRepository.java
│   │                       ├── model
│   │                       │   └── Member.java
│   │                       ├── rest
│   │                       │   ├── JaxRsActivator.java
│   │                       │   └── MemberResourceRESTService.java
│   │                       ├── service
│   │                       │   └── MemberRegistration.java
│   │                       └── util
│   │                           └── Resources.java
│   ├── resources
│   │   ├── import.sql
│   │   └── META-INF
│   │       └── persistence.xml
│   └── webapp
│       ├── index.html
│       ├── index.xhtml
│       ├── resources

│       └── WEB-INF
│           ├── beans.xml
│           ├── faces-config.xml
│           ├── kitchensink-quickstart-ds.xml
│           └── templates
│               └── default.xhtml
└── test
    ├── java
    │   └── org
    │       └── jboss
    │           └── as
    │               └── quickstarts
    │                   └── kitchensink
    │                       └── test
    │                           └── MemberRegistrationIT.java
    └── resources
        ├── arquillian.xml
        ├── META-INF
        │   └── test-persistence.xml
        └── test-ds.xml

And here is the kitchensink-quickstart-ds.xml datasource:

<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
    <!-- The datasource is bound into JNDI at this location. We reference
        this in META-INF/persistence.xml -->
    <datasource jndi-name="java:jboss/datasources/KitchensinkQuickstartDS"
        pool-name="kitchensink-quickstart" enabled="true"
        use-java-context="true">
        <connection-url>jdbc:h2:mem:kitchensink-quickstart;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1</connection-url>
        <driver>h2</driver>
        <security>
            <user-name>sa</user-name>
            <password>sa</password>
        </security>
    </datasource>
</datasources>