• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need a little help : Jar not working when added as dependency in war

 
Indrayani Godbole
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a jar which contains dao implementation class which uses JPA entity manager for database operations.
Database details are mentioned in profile in Settings.xml in Maven Directory.
When jar is created using maven, test cases calling dao class involving database operations get executed successfully.

There is a war application and i have mentioned the dependency of above jar in the war's pom.xml .
Now the problem is when a request is sent from one of the classes of the war application to the Jar's dao class, i am getting null pointer exception.
this is happening because the EntityManager is null.

Question is, the standalone testcases from the Jar get executed successfully while jar creation.
but when a call is sent from war application to the jar dao, it gets null Entitymanager.

any idea why this is happening, I simply have no clue about it.
 
K. Tsang
Bartender
Posts: 3521
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You got a web app (war file). And you got a jar file (DAO). Is this jar in the war's WEB-INF/lib folder?

I don't think you need to specify the dependency if the jar files are in WEB-INF/lib
 
Indrayani Godbole
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:You got a web app (war file). And you got a jar file (DAO). Is this jar in the war's WEB-INF/lib folder?

I don't think you need to specify the dependency if the jar files are in WEB-INF/lib



--------------------
the jar file is not in the lib since its added in pom dependency
when i searched on internet resources, what i found was, i should instantiate the dao using lookup and not by new and this is may be the reason of entitymanager not getting initialized

like currently i am doing

DaoImpl obj = new DaoImpl()

wheres as i should be doing

DaoImpl obj = (DaoImpl)context.lookup("DaoImpl/local")


i tried the same , but now i am getting, Name [DaoImpl/local] is not bound in this Context. Unable to find [DaoImpl].


the DaoImpl class, i have put these annotations
@Transactional
@Repository

do i need to do anything apart from above, what could be the reason of 'name not bound' error.

 
Tim Holloway
Saloon Keeper
Posts: 18301
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are getting a NullpointerException, then it would appear that Maven is doing what it should. It is more likely that your runtime environment is not set up properly. Maven failures would be more likely to result in a ClassNotFoundException.

I use JPA in webapps running under Tomcat. I use the Spring Framework to maintain the persistence components. To make them work properly, I have to include the Spring tomcat agent and weaver jars in Tomcat's lib directory (NOT the WAR!)



 
Indrayani Godbole
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:If you are getting a NullpointerException, then it would appear that Maven is doing what it should. It is more likely that your runtime environment is not set up properly. Maven failures would be more likely to result in a ClassNotFoundException.

I use JPA in webapps running under Tomcat. I use the Spring Framework to maintain the persistence components. To make them work properly, I have to include the Spring tomcat agent and weaver jars in Tomcat's lib directory (NOT the WAR!)





------------------------
so does it mean that, i can not use jpa as a part of jar and put the jar's dependency in a war project ?
 
Tim Holloway
Saloon Keeper
Posts: 18301
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indrayani Godbole wrote:
Tim Holloway wrote:If you are getting a NullpointerException, then it would appear that Maven is doing what it should. It is more likely that your runtime environment is not set up properly. Maven failures would be more likely to result in a ClassNotFoundException.

I use JPA in webapps running under Tomcat. I use the Spring Framework to maintain the persistence components. To make them work properly, I have to include the Spring tomcat agent and weaver jars in Tomcat's lib directory (NOT the WAR!)





------------------------
so does it mean that, i can not use jpa as a part of jar and put the jar's dependency in a war project ?


No. All of the JPA stuff is part of the WAR. Both my actual user code and the (Hibernate) JPA support librarues. Only the things that enable Spring to weave the annotations are made part of Tomcat.

One thing worth asking, since your EntityManager is null is where and how your webapp constructs the EntityManager. Because Tomcat won't do that for you. Full-stack JEE implementations will, but I think that the JPA has to be full-blown EJB for that to be done.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic