Skip to main content

GlassFish 3.1 embedded and Java EE 6 DataSource definition

5 replies [Last post]
greeneyed
Offline
Joined: 2003-06-10
Points: 0

Hi there,

I have been able to successfully define a datasource using the new Java EE 6 features, defining it in web.xml using a data-source node. However, I would like this application to be compatible with other servers that do not implement Java EE 6 yet, and that complain that this node is not allowed in web.xml.

So my question would be, is it possible to define this data-source node in another file that is not web.xml? I tried adding application.xml to META-INF but it is being ignored.

I have also tried adding it to sun-web.xml but it seems to be ignored there, as all I get is the same JNDI name not bound that I get if I define nothing.

I know mixing servlet versions is not a good thing, but I could not find any other descriptor to get GlassFish embedded to define a datasource, all the other embeeded containers have their own custom descriptors to do that, so I'm simply trying to get the application to be compatible with all the containers.

S!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jr158900
Offline
Joined: 2005-04-13
Points: 0

DataSource definition is available from Java EE 6 onwards and you can define it in web.xml/ejb-jar.xml/application.xml. If other servers do not have Java EE 6 support, DataSource definition will not work in those servers.

Martin Gainty

if you dont mind using spring.. you can use spring's ContextLoaderListener to load the first applicationContext.xml found on the classpath


contextConfigLocation classpath:applicationContext.xml

org.springframework.web.context.ContextLoaderListener

hth
Martin Gainty
______________________________________________
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.

> Date: Sun, 16 May 2010 13:28:51 -0700
> From: glassfish@javadesktop.org
> To: users@glassfish.dev.java.net
> Subject: GlassFish 3.1 embedded and Java EE 6 DataSource definition
>
> Hi there,
>
> I have been able to successfully define a datasource using the new Java EE 6 features, defining it in web.xml using a data-source node. However, I would like this application to be compatible with other servers that do not implement Java EE 6 yet, and that complain that this node is not allowed in web.xml.
>
> So my question would be, is it possible to define this data-source node in another file that is not web.xml? I tried adding application.xml to META-INF but it is being ignored.
>
> I have tried adding it to sun-web.xml but it seems to be ignored there, as all I get is the same JNDI name not bound that I get if I define nothing.
>
> I know mixing servlet versions is not a good thing, but I could not find any other descriptor to get GlassFish embedded to define a datasource, all the other embeeded containers have their own custom descriptors to do that, so I'm simply trying to get the application to be compatible with all the containers.
>
> S!
> [Message sent by forum member 'greeneyed']
>
> http://forums.java.net/jive/thread.jspa?messageID=470061
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

_________________________________________________________________
The New Busy think 9 to 5 is a cute idea. Combine multiple calendars with Hotmail.
http://www.windowslive.com/campaign/thenewbusy?tile=multicalendar&ocid=P...
[att1.html]

greeneyed
Offline
Joined: 2003-06-10
Points: 0

Hi Martin,

Thanks for the suggestion. I'm trying to find a solution that requires no dependencies but if there is none, I know I can always resort to that one.
I'm trying to find a mechanism that works for any kind of application and it would be a shame to have to add Spring simply because of GlassFish, as all the other containers (Jetty, Resin, Tomcat) I use for the tests do not require it.

Thanks,
D.

tsmets
Offline
Joined: 2005-05-04
Points: 0

Apparently the file : ${SERVER_BASE_DIR}/domains/domain1/config/domain.xml should contain all the information...
It is recommended to use the "asadmin" tool to update it or to use the admin-console (which is supposedly the same).
I am now into looking how to adapt the classpath to have the database specific jar available.
Dropping it in the ${SERVER_BASE_DIR}/lib does not seem to work.
Testing the other lib's folders now ...

\T,

ps : I find it bad practice to have the datasource being configured with the artifacts compiled (war/jar/...) or with Spring.

greeneyed
Offline
Joined: 2003-06-10
Points: 0

If you read carefully, you'll see that this was in an embedded environment, as part of running a set of automatic tests to be precise, so running command tools by and administrator was not a possibility and including the datasource with the application for that specific testdeployment was the more convenient thing to do.

In any case, that was 3 years ago and I dropped the issue long ago :).

Thanks for your interest anyway,
Cheers!