I want to load postgreSQL jar file from ear archive .
this is my configuration :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<includeLibInApplicationXml>true</includeLibInApplicationXml>
<generateApplicationXml>true</generateApplicationXml>
<defaultLibBundleDir>/lib</defaultLibBundleDir>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
<modules>
<jarModule>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</jarModule>
<webModule>
<groupId>${project.groupId}</groupId>
<artifactId>module-war</artifactId>
<uri>/foodpicker.war</uri>
<!-- Set custom context root -->
<contextRoot>/</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
and server.xml :
<server description="Default Server">
<featureManager>
<feature>cdi-2.0</feature>
<feature>beanValidation-2.0</feature>
<feature>appSecurity-3.0</feature>
<feature>managedBeans-1.0</feature>
<feature>ejbLite-3.2</feature>
<feature>localConnector-1.0</feature>
<feature>microProfile-3.3</feature>
<feature>jpa-2.2</feature>
<feature>jwt-1.0</feature>
</featureManager>
<library id="project-libs">
<fileset dir="lib" includes="*.jar"/> // <--- not loaded from ear file !!!
</library>
<dataSource jndiName="jdbc/jta-datasource" transactional="true">
<jdbcDriver id="database-driver" libraryRef="project-libs"/>
<properties databaseName="${database.name}" serverName="${database.hostname}" portNumber="${database.port}"
user="${database.username}" password="${database.password}"/>
</dataSource>
<basicRegistry id="basic" realm="BasicRealm"/>
<httpSession securityIntegrationEnabled="false"/>
<httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="8080" httpsPort="9443">
<httpOptions http2="enabled"/>
</httpEndpoint>
<webContainer disableXPoweredBy="true"/>
<applicationManager autoExpand="true"/>
<applicationMonitor updateTrigger="mbean"/>
</server>
this is directory structure of ear file :
.
├── foodpicker.war
├── lib
│ └── org.postgresql-postgresql-42.2.12.jar
└── META-INF
├── application.xml
├── MANIFEST.MF
└── maven
└── ir.moke.foodpicker
└── module-ear
├── pom.properties
└── pom.xml
if i change <fileset>
to absolute path of another directory on filesystem , application load and worked without any problem . but i want to OpenLiberty Application Server load this library from ear file .
How can fix this problem ?
UPDATE
finally i configured server.xml to fix this problem :
<library id="project-libs">
<fileset dir="${server.config.dir}/lib" includes="*.jar"/>
</library>
<dataSource jndiName="jdbc/jta-datasource" transactional="true">
<jdbcDriver id="database-driver" libraryRef="project-libs"/>
<properties databaseName="${database.name}" serverName="${database.hostname}" portNumber="${database.port}"
user="${database.username}" password="${database.password}"/>
</dataSource>
Server configured data sources in Liberty must load JDBC driver classes from a library that is defined in server configuration via the libraryRef. This allows the data source, which is backed by a connection pool, to be used across multiple applications if so desired, without needing to be concerned with whether the connection pool is handing out connections from the right class loader to each respective application. So you cannot achieve it in the way that you are configuring it.
However, there is a way (defined by the Java/Jakarta EE spec) to define data sources within the application itself, which can then load JDBC driver classes from the application.
Instead of defining the data source in server.xml, define it in your web component (Servlet)
You can look up the data source as follows,
And you can also define resource references to it, just as you would any server-configured data source,