Programmatically, I don't think it is an easy task. The interfaces were not designed for the purpose. However, someone might have better insight into this.
I suppose one way you could achieve this is by creating a process to write and deploy a *-ds.xml. However, since deployment is asynchronous there are issues such as blocking until the DS is deployed and instantiated.
hmm... how fool i am. i was trying to package my *.rar and my *-ds.xml into an ear and deploy it all at once. from your post it seems like it's impossible, or at least not reasonable...
but if i deploy my *-ds.xml, what is the connection between the datasource and the resource adapter in my .rar? is it the JNDI name you mentioned in you previous post? btw, do you have some example you could paste?
oops, i've read the JNDI thing in a different thread... here it is for reference:
Have you updated the "standardjbosscmp-jdbc.xml" file (found in Jboss install dir\server\your server\conf) with the following line?
You should be able to package your RAR and datasource.xml into a SAR archive.