Topic
No replies
vijisan
vijisan
2 Posts
ACCEPTED ANSWER

Pinned topic JPA Classes Not found at runtime

‏2010-09-11T16:36:24Z |
I created a JPA project for my Web application. JPA project classes are NOT FOUND at run time when those are referred from web application. I followed the below steps to create Web/JPA project in RAD 7.5.

1. Created a EAR project called MySampleEAR
2. Created a dynamic web project
- project name: MySampleWeb
- Target Runtime: Websphere Application Server 7.0
- Dynamic Web module version 2.5
- Configuration : Default configuration for WAS 7.0
- Selected "Add project to EAR" and selected the EAR - MySampleEAR
- Finished it

3. Created JPA Project
- Project name : MySampleJpa
- Target Runtime : WAS7
- Configuration : Utility JPA Project with 5.0
- Selected Add project to an EAR : MySampleEAR
- In the next screen, Platform: RAD JPA platform
- Use implementation provided by runtime
- Left rest as default options

4. Created a very basic class in JPA project under src dir

package com.mysample.persistence;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table (name="USERS")
public class Users implements Serializable {
@Id
@Column(name="USER_ID")
private long userId;

private static final long serialVersionUID = 1L;

public Users() {
super();
}

public long getUserId() {
return this.userId;
}

public void setUserId(long userId) {
this.userId = userId;
}
}

5. Added MySampleJpa project into web project's (MySampleWeb) build path.

6. Created a simple Servlet in the web project and mapping the web.xml file is created by RAD. When I import import com.mysample.persistence.Users, no compilation error and able to refer Users object.

My Servet code is below:

package com.mysample.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mysample.persistence.Users;

/**
* Servlet implementation class SampleServlet
*/
public class SampleServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
new Users();
}

}

Now, run/deploy the ear file into WAS 7, Try to load the servlet uri in the browser: http://localhost:9081/mysampleweb/sampleservlet/
Getting the below ClassNotFoundE in the server console.

9/11/10 10:24:04:218 EDT 0000001f servlet E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: Uncaught exception created in one of the service methods of the servlet SampleServlet in application MySampleEar. Exception created : java.lang.NoClassDefFoundError: com.mysample.persistence.Users
at com.mysample.web.SampleServlet.doGet(SampleServlet.java:19)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1661)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:937)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:500)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3826)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:931)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1583)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:272)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1550)
Caused by: java.lang.ClassNotFoundException: com.mysample.persistence.Users
at java.net.URLClassLoader.findClass(URLClassLoader.java:419)
at com.ibm.ws.bootstrap.ExtClassLoader.findClass(ExtClassLoader.java:150)
at java.lang.ClassLoader.loadClass(ClassLoader.java:643)
at com.ibm.ws.bootstrap.ExtClassLoader.loadClass(ExtClassLoader.java:90)
at java.lang.ClassLoader.loadClass(ClassLoader.java:609)
at com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java:62)
at com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java:58)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:508)
at java.lang.ClassLoader.loadClass(ClassLoader.java:609)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:508)
at java.lang.ClassLoader.loadClass(ClassLoader.java:609)
... 25 more