Where is my ejb-jar.xml?

匆匆过客 提交于 2019-12-12 12:41:38

问题


i created a Java EE 5 Enterprise Application on NetBeans 7.4 including a WAR and an EJB using Weblogic 10.3.0

Im using JPA so i need to use the datasource for my persistence.xml

My problem is i'm trying to make a JDBC Datasource following this: http://docs.oracle.com/cd/E15051_01/wls/docs103/jdbc_admin/wwimages/jdbc_package_simple.gif

But Netbeans didn't add a ejb-jar.xml to the EJB, which i need for a resource reference. Oracle's documentation says it needs to be inside META-INF folder but if i add that file to that folder and then compile it is automatically deleted.

So, where is my ejb-jar.xml ? If i create it by my own what can i do to include it without being deleted after compilation ? Open the jar with WINRAR and add it manually (joke) ? Is there a easier way of doing this ?

Thanks


回答1:


I strongly recommend you use the new Java EE 5 Annotations instead. For this example thisIsMyDataSource is the name, but you can use whatever name configured on the Server (e.g. you might have several).

@Resource
javax.sql.DataSource thisIsMyDataSource;
public Foo doSomethingNeedingADataSource() {
   Connection con = thisIsMyDataSource.getConnection();
   .........
}

Java EE 5 simplifies development by removing the requirement for that older boilerplate configuration. You can, but probably should not, use something like Apache Derby programing (perhaps through DI). There's a separation of roles in EJB. Here's an example using WebSphere. You might want to read more about JDBC.




回答2:


Well, i deleted my EJB (it wasn't necessary). I just created my JDBC Application Module to use it in my WAR without doing all those things in the link. Putting my datasource-jdbc.xml in the config folder (META-INF) and inserting the next code in the weblogic-application.xml was enough:

<module>
  <name>
    MyDatabase
  </name>
  <type>
    JDBC
  </type>
  <path>
    META-INF/datasource-jdbc.xml
  </path>
</module>

Then I used the JNDI "MyDatabase" in my Persistence.xml

To generate the datasource-jdbc.xml you can go to the server (a testing one), make the datasource and then go to the server folder and there is a folder (inside one of the main folders, look for it) with the name "jdbc". Inside it, you can get your generated xml.



来源:https://stackoverflow.com/questions/19987084/where-is-my-ejb-jar-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!