Jboss data source or properties from classpath resource - jboss

Is it possible in Jboss eap-6.4 to configure the datasource using a resource loaded from the classpath?
I would like it to be a classpath resource because I have a mechanism that securely substitutes properties in files loaded as classpath resources.

Are you trying to load JDBC driver from class-path ? which resources you are trying to load from class-path ? If you are trying to load JDBC driver from class-path then you can add JDBC driver jar in 'deployment' directory in standalone mode.

Related

Jboss deployment structure loading

When do modules specified in jboss deployment structure load? At jboss startup or when classes in jars within modules are called ?
Module jar files will be loaded into memory while deploying application, but i think class object is initialized when its called.

JBOSS7 external jar with dependency on ear file

I am using JBOSS 7
In my custom jar I am implementing an Interface. The interface is in a jar packaged with ECM.ear file. Unless I put my custom jar inside the web-inf/lib folder (of the war file located in ear file) I am getting ClassNotFoundException w.r.to the interface.
I created a module for my custom jar but I don't how to set up a dependency with ear file. I copied the jar containing the interface say mdm.jar and placed it in the module and also added an entry in the resource root of module.xml. After restarting I am getting ClassNotFoundException for the classes referred by mdm.jar, which arein ear file.
How to achieve this dependency?
Thanks,
Raghu
JBOSS 7 needs you to place the packaged jar files in the lib folders of your web-inf/lib or the ear/lib cos of the Class Loading Precedence that JBOSS server follows.
Alternatively you could load it as a module, but you need to specify any addition of this kind outside of JBOSS default supplied modules using your MANIFEST file or jboss-deployment-structure.xml
This link should provide you more insight on what would suit you best.
Hope it helps.

Deploying to Glassfish classpath not set for com.mysql.jdbc.jdbc2.optional.MysqlXADataSource

Glassfish is not loading the com.mysql.jdbc.jdbc2.optional.MysqlXADataSource package.
The following error is thrown
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence
Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException:
Error in allocating a connection. Cause: Class name is wrong or classpath is not set
for:com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
Error Code: 0 at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy
(EntityManagerSetupImpl.java:517)...
I have copied the mysql-connector jar file to the lib directory of Glassfish but I still get the above error.
How do I ensure that Glassfish can find my JDBC driver for my deployed application?
You will need to make the MySQL JDBC jar file available to Glassfish.
http://ushainformatique.com/blog/2010/03/19/jdbcwithglassfish/
EDIT:
How do I use different JDBC drivers? Where should I copy the jar(s)?
It is recommended to place JDBC drivers, that are used by all the
applications in the domain, in domain-dir/lib or
domain-dir/lib/classes. A restart of the application server instance
is required today so that the JDBC drivers are visible to applications
deployed in the domain.
From https://blogs.oracle.com/sivakumart/entry/classloaders_in_glassfish_an_attempt
So move the jar file into the lib dir below the domain into which you are deploying your app. The default Glassfish domain is domain1.
Restart Glassfish and this should work.
There is a Maven Glassfish plugin which may be worth evaluating http://maven-glassfish-plugin.java.net/ Using Maven and this plugin would help automate the deployment step. This would be more robust than doing manual deployments. Your call though of course.
Besides adding the driver to your classpath, you should try adding the appserv-rt.jar file to your project's build path (the jar is located in Glassfish's lib directory). If you don't want to include all the other jars you should first create a library containing the appserv-rt jar and then add it to your project's build path.
We could fix using
./asadmin start-database
This starts Derby (don't know why this is required, may be a bug, and I dont use this DB in my app)
:)

Including the MySql's connector/j as part of an EAR file: Glassfish

We want to simplify the deployment process of an app by including the MySql connector/j jar as part of the EAR. (so we won't need to manually copy it in the /lib folder of our Glassfish servers)
Is it possible?
UPDATE: We have read this is possible using the SAR files in JBoss, but we don't think it's available in Glassfish.
Because of the classloader hierarchy in Glassfish I don't think this is possible. The mysql driver jar needs to be available outside of your application's classloader because the connection pool is globally available.
http://download.oracle.com/docs/cd/E19226-01/820-7695/6niugesfp/index.html#indexterm-28
From what I can find, Glassfish doesn't support anything like .sar files:
http://old.nabble.com/Migrating-From-jboss-4.2.1-to-GlassFish-td18629992.html
Maybe vote for this issue, or create your own for a .sar-like deployment option:
http://java.net/jira/browse/GLASSFISH-16915

jndi.properties in JBoss and GlassFish deployment

Currently an EJB / Web Application project uses a JBoss-specific JNDI configuration file, placed either in the conf directory or in the Jar file (both works fine).
How can I make this project portable between JBoss (4.2.3 or 5) and GlassFish 3? Is there a recommended way to set different JNDI configuration parameters depending on the container?
According to their EJB FAQ, Glassfish developers have put a jndi.properties file within appserv-rt.jar. The JNDI machinery in Java SE automatically detects this file when used in conjunction with no-arg InitialContext() and bootstraps the correct naming provider.
My understanding is that this should work in Glassfish also. Did you try do deploy your application without the jndi.properties file specific to JBoss (and to place it into the conf directory when deploying on JBoss)?