I know how I'd do this using JBoss: create a *-ds.xml
file, and drop it into my deploy
directory.
- Is there a declarative way to do the same with GlassFish (v3.1)?
- Am I thinking about this the wrong way? (See next question)
- Is there a more-Glassfishy way to get my Java EE application to talk to a database?
Other potentially-r开发者_高级运维evelant info:
- I want to connect to a SQL Server 2008 database
- I'm using Eclipse + GlassFish Server Tools
- I know next to nothing about GlassFish. I'm much more familiar with JBoss
You can define it in application.xml
or ejb-jar.xml
of your EAR. You can even use annotations.
Long answer short: DataSource Resource Definition in Java EE 6.
BalusC is right (+1), with Java EE 6 you can declare datasource definitions either through annotations or through the use of deployment descriptors in a standard and portable way.
Just in case you'd be also interested by creating other resources than datasources like JMS resources, you can also package a glassfish-resources.xml
file as part of your application. See:
- Supporting glassfish-resources.xml
- 4.1.3 Application scoped resources
精彩评论