Hi Sahoo,
Thanks for the reply. I like your blog. I was looking at the EE6 stuff earlier today and can't wait for JNDI improvements.
I eventually set up some maven profiles to deal with my issue since it's not for production and a quick hack seems to do what I need. Mainly I don't want to be editing persistence.xml every time I want to try a different application server. I'll post the relevant portions of my maven configuration below in case it's helpful to anyone else.
I use a standard maven layout for my jpa module:
[code]
module-name
src
main
java
resources
[/code]
I added two non-standard directories; one for glassfish and one for jboss. Each contains a vendor specific persistence.xml file:
[code]
module-name
src
main
java
resources
glassfish-resources
META-INF
persistence.xml
jboss-resources
META-INF
persistence.xml
[/code]
Then I added two profiles to the pom.xml for my jpa module:
[code]
<profiles>
<profile>
<id>glassfish</id>
<!-- Setting activeByDefault makes this the default profile if no profile is selected -->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<resources>
<!-- Normal Resources -->
<resource>
<directory>src/main/resources</directory>
</resource>
<!-- Glassfish specific persistence resources -->
<resource>
<directory>src/main/glassfish-resources</directory>
</resource>
</resources>
</build>
</profile>
<profile>
<id>jboss</id>
<activation>
<!--
If the system property 'env_jboss' is set then this profile will be activated
rather than the default. In IntelliJ IDEA 9 I had to ensure the variable was
given an arbitrary value to ensure it was set for the build. IDEA allows you
to set system properties in:
Project > Settings > Maven > Runner
-->
<property>
<name>env_jboss</name>
</property>
</activation>
<build>
<resources>
<!-- Normal Resources -->
<resource>
<directory>src/main/resources</directory>
</resource>
<!-- JBoss specific persistence resources -->
<resource>
<directory>src/main/jboss-resources</directory>
</resource>
</resources>
</build>
</profile>
</profiles>
[/code]
If you run maven normally you'll get the default build profile which uses the Glassfish specific persistence.xml:
[code]
mvn clean package
[/code]
If you set the 'env_jboss' property you'll get the jboss profile which uses the JBoss specific persistence.xml:
[code]
mvn -Denv_jboss=true clean package
[/code]
The value for 'env_jboss' doesn't matter. It just needs to get set. Even if you build from a parent module (which I do), the profiles will work. It's more than likely someone can come up with a fancier setup that names files differently etc, but this is a quick fix that worked for me. I simply cloned the config on my build server and added the -Denv_jboss property to the cloned configuration.
[Message sent by forum member 'jptech' (jptech)]
http://forums.java.net/jive/thread.jspa?messageID=359373