java.lang.ClassNotFoundException for a class in external JAR - eclipse

I have a maven project in Eclipse Java EE IDE for Web Developers.
When running Tomcat, I'm getting an error for a class that I can see that I have included.
My question is - do I have to add these JARs to an additional place because of Tomcat Apache?
Error:
SEVERE: Servlet /Resource threw load() exception
java.lang.ClassNotFoundException: org.odata4j.jersey.producer.resources.ODataApplication
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:171)
at com.sun.jersey.core.reflection.ReflectionHelper.classForNameWithException(ReflectionHelper.java:240)
at com.sun.jersey.core.reflection.ReflectionHelper.classForNameWithException(ReflectionHelper.java:220)
at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:711)
And here is the class in my Library:
UPDATE:
My Web Deployment Assembly looks like:

The issue you are seeing is due to the fact that tomcat is looking at the wrong directory. It is currently most likely pointed at your src/main/webapp directory of your project. This does not jive with how maven works. Maven downloads the dependencies, but will only include them in the target build. You need to have the tomcat server look at target/myapp-0.0.1, or build to a war and deploy that way. The easiest solution as of now, would be for you to use the tomcat plugin. After setting it up, you can use an imbedded server, and just use the following command 'mvn tomcat:run'.
Maven Tomcat Plugin Docs
UPDATE:
I looked at the properties settings, and you should actually be able to edit the "Web Deployment Assembly" settings for your project (under project properties). Check screenshot for how I have mine setup. Notice how Maven Dependencies is mapped.
http://imgur.com/ofxryns

Related

Drools project throws "The Eclipse JDT Core jar is not in the classpath"

When I run the sample Drools project in Eclipse, it throws an Exception "The Eclipse JDT Core jar is not in the classpath". I have created the Drools 6 runtime manually. Am I missing something?
Full stacktrace
org.drools.core.RuntimeDroolsException: Unable to load dialect 'org.drools.compiler.rule.builder.dialect.java.JavaDialectConfiguration:java:org.drools.compiler.rule.builder.dialect.java.JavaDialectConfiguration'
at org.drools.compiler.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.java:360)
at org.drools.compiler.compiler.PackageBuilderConfiguration.buildDialectConfigurationMap(PackageBuilderConfiguration.java:346)
at org.drools.compiler.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:228)
at org.drools.compiler.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:196)
at org.drools.compiler.compiler.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:152)
at org.drools.compiler.kie.builder.impl.AbstractKieModule.buildKnowledgePackages(AbstractKieModule.java:166)
at org.drools.compiler.kie.builder.impl.KieContainerImpl.createKieBase(KieContainerImpl.java:244)
at org.drools.compiler.kie.builder.impl.KieContainerImpl.getKieBase(KieContainerImpl.java:204)
at org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:347)
at org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:322)
at com.sample.ProcessTest.main(ProcessTest.java:17)
Caused by: java.lang.RuntimeException: The Eclipse JDT Core jar is not in the classpath
at org.drools.compiler.rule.builder.dialect.java.JavaDialectConfiguration.setCompiler(JavaDialectConfiguration.java:100)
at org.drools.compiler.rule.builder.dialect.java.JavaDialectConfiguration.init(JavaDialectConfiguration.java:61)
at org.drools.compiler.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.java:356)
... 10 more
You are missing the Ecliose jdt core jar. Add yhat jar and it should work.
Added the org.eclipse.jdt.core-3.7.1.jar file to the buildpath of the project and it works perfectly fine. Not sure why this was not part of the Drools runtime which i created manually.

maven + eclipse + tomcat : class not found exception

I have a simple web app using that uses servlets. I created it as a maven project and then imported it into eclipse ( file ->import -> existing maven projects)
The war gets deployed to tomcat 7 correctly.
However when I create a tomcat 7 server in Eclipse and then start tomcat in eclipse I get an exception when I run the application.
root cause
java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
first.model.BeerExpert.<clinit>(BeerExpert.java:12)
first.servlet.BeerServlet.doPost(BeerServlet.java:26)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.ClassNotFoundException: com.google.common.collect.ImmutableMap
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
first.model.BeerExpert.<clinit>(BeerExpert.java:12)
first.servlet.BeerServlet.doPost(BeerServlet.java:26)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
is there any specific class path setting that needs to be done in the eclipse/tomcat
Note: I am able to run mvn clean install and it creates the jar file. And then when I move the jar to a tomcat(7) webapp directory and restart it works just fine.
I am not posting details of the pom.xml because the application itself is working fine. However id it is needed in resolution I can post it.
Tomcat & Spring Web - Class Not Found Exception org.springframework.web.context.ContextLoaderListener
Right Click on your web project in Project Explorer -> select 'Properties'. Under project properties, select 'Deployment Assembly'.
The Deployment Assembly property page shows the content that will be published as a assembled artifact by Eclipse to the server. You need to tell Eclipse that you want all your Maven dependencies to be published too.
To do that, click 'Add' button, then select 'Java Build Path Entries'. Click Next and select Maven Dependencies. This will publish the Maven dependency JAR files to the lib folder when Eclipse publishes your project to WST server

RAD / WebSphere: NoClassDefFoundError

When I deploy my application to the integrated WebSphere server, I get NoClassDefFoundErrors for two classes that are contained in the same project.
Note: I call the missing class com.my.package.MyClass here.
The consuming project contains Session Beans and imports the exporting project in "Configure Build path". The exporting project is listed as "EAR library" if the consuming project in the Enterprise Explorer.
The exporting project is a normal java project that contains com.my.package.MyClass. It exports its source folders.
The exceptions look like that:
com.ibm.websphere.naming.CannotInstantiateObjectException: Exception occurred while the JNDI NamingManager was processing a javax.naming.Reference object. [Root exception is com.ibm.ejs.container.ContainerEJBException: Unable to initialize deferred EJB.; nested exception is: java.lang.NoClassDefFoundError: com.my.package.MyClass]
at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookupExt(Helpers.java:1033)
at com.ibm.ws.naming.urlbase.UrlContextHelper.processBoundObjectForLookup(UrlContextHelper.java:175)
at com.ibm.ws.naming.urlbase.UrlContextImpl.processBoundObjectForLookup(UrlContextImpl.java:1736)
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1249)
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1225)
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1276)
at javax.naming.InitialContext.lookup(Unknown Source)
...
or like that
[22.03.13 14:56:12:994 CET] 00000025 EJBContainerI E WSVR0068E: Attempt to start EnterpriseBean MyEar#MyJar.jar#MyBean failed with exception: java.lang.NoClassDefFoundError: com.my.package.MyClass
at java.lang.Class.getDeclaredMethodsImpl(Native Method)
at java.lang.Class.getDeclaredMethods(Class.java:673)
at com.ibm.ws.metadata.ejb.EJBMDOrchestrator.processTimeoutMetaData(EJBMDOrchestrator.java:6494)
at com.ibm.ws.metadata.ejb.EJBMDOrchestrator.finishBMDInit(EJBMDOrchestrator.java:1488)
at com.ibm.ws.runtime.component.EJBContainerImpl.finishDeferredBeanMetaData(EJBContainerImpl.java:5036)
at com.ibm.ws.runtime.component.EJBContainerImpl.initializeDeferredEJB(EJBContainerImpl.java:4845)
at com.ibm.ejs.container.HomeOfHomes$1.run(HomeOfHomes.java:406)
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
at com.ibm.ejs.container.HomeOfHomes.getHome(HomeOfHomes.java:403)
at com.ibm.ejs.container.HomeOfHomes.getHome(HomeOfHomes.java:339)
at com.ibm.ejs.container.util.EJBLocalInterfaceObjectFactory.getObjectInstance(EJBLocalInterfaceObjectFactory.java:139)
at javax.naming.spi.NamingManager.getObjectInstanceByFactoryInReference(Unknown Source)
at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookupExt(Helpers.java:927)
at com.ibm.ws.naming.urlbase.UrlContextHelper.processBoundObjectForLookup(UrlContextHelper.java:175)
at com.ibm.ws.naming.urlbase.UrlContextImpl.processBoundObjectForLookup(UrlContextImpl.java:1736)
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1249)
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1225)
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1276)
at javax.naming.InitialContext.lookup(Unknown Source)
...
I'm using IBM Rational Application Developer for WebSphere in Version 8.0.4
and IBM WebSphere Application Server in Version 7.0.0.11
My workspace has no errors in the Problems view.
What I already tried:
- Starting RAD with the -clean parameter
- Refreshing all projects in the Enterprise Explorer
- Project > Clean
- In the Server view: stopping, restarted, cleaning, publishing
- Closing and restarting RAD
First I had a second problem: in RAD I wasn't able to find com.my.package.MyClass by Ctrl + Shift + T.
I solved it by deleting files (*.index files and the "savedIndexNames.txt") in
/.metadata/.plugins/org.eclipse.jdt.core.
But unfortunately that didn't solve the problem at runtime / deploy time. :-(
Can somebody give me hints?
Thanks in advance!
what you need to do is add the Java Project as a Deployment Assembly for the EAR project.
This will than automatically add the $PROJECT.jar from your Java Project under /lib/ folder for thie .ear
WebSphere automatically pics .jar files from lib folder and add them to the classpath and these .jar can be found by all EJB.jar and .war packaged inside the .ear file.
So, right click your EAR project, go to properties, and than selec "Deployment Assembly" than add your Java Project there, you should than see the generated jar under lib folder.

NoClassDefFoundError in Eclipse when adding project in build path

I am receiving an NoClassDefFoundError in Eclipse when I try to run my project.
My Project looks like this:
JavaProject: BulkAdmin
- src
- com.mycompany.bulkadmin.SDK.util
- Login.java
Dynamic Web Project: JSPTesting
- src
- com.mycompany.bulkadmin.jspController
- Controller.java
- WebContent
- index.html
- execute.jsp
This is the control flow:
index.html loads
index.html has a form that redirects to execute.jsp
execute.jsp takes the info returned in the form and makes a static call to Login.java
execute.jsp prints the results of the call
Controller.java uses Login.java. I was receiving compilation errors. To resolve them I did this:
Right click on JSPTesting -> properties
Choose java build path on the left bar
Choose projects tab
Click add
Choose BulkAdmin (Project)
I am not sure why but now when I am getting a NoClassDefFoundError. I have done some googling. I think that this means that I have messed up my classpath somehow but I am not sure how to resolve this.
java.lang.NoClassDefFoundError: com/myCompany/bulkadmin/SDK/util/Login
at com.myCompany.bulkadmin.jspController.Controller.process(Controller.java:44)
at org.apache.jsp.execute_jsp._jspService(execute_jsp.java:63)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:321)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:257)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:595)
Other information:
I am using tomcat (in Eclipse) as my server
The exception shows up in the browser and the eclipse console
execute.jsp is a JSP
It seems like there are many similar questions to this on SO. I have read about 15 of them and tried various things however I think that my question has a different solution. I can provide more information.
Rightclick your dynamic web project, go to Properties > Deployment Assembly and add the dependent projects there. This way they will end up as JAR in /WEB-INF/lib, exactly there where you want it to be.
In Eclipse versions older than 3.5 you need to go to Properties > Java EE Module Dependencies.
See also:
ClassNotFoundException when using User Libraries in Eclipse build path
Difference between Deployment Assembly and J2EE Module Dependencies in Eclipse
The NoClassDefFoundError indicates that a class that was available during compilation is no longer available at runtime. Your problem is that the com/myCompany/bulkadmin/cSDK/util/Login class is available in the compilation classpath (in Eclipse via the Project reference you added to the build path) but not in the runtime classpath (Tomcat, which has no idea how to find this class).
You need to add the BulkAdmin project to the web-app class path when deployed on Tomcat as well.
One way to do this would be to export the BulkAdmin project as a JAR and put it into the WEB-INF/lib directory of your JSPTesting project.

GWT Development Mode with Eclipse/Maven

I am just starting with GWT. I use Eclipse and have installed the GWT plugin.
I have followed the directions here Maven GWT 2.0 and Eclipse to set up a GWT project using the gwt-maven-plugin. When I run the Maven goals gwt:compile gwt:run, GWT Development Mode is launched and I can copy the url from it to my browser and view the label.
However, the project has this problem:
Description: The web.xml file does not exist
Resource: WEB-INF
Path: /GWTExample/war
Location: Unknown
Type: Google Web App Problem
If I try to run the project as a Google Web Application, I get this warning:
[WARN] No startup URLs supplied and no plausible ones found -- use -startupUrl
I can get rid of the problem by copying the web.xml to the war directory, but I still get the URL issue when running as a Google Web App.
If I'm using Maven and GWT in Eclipse, should I just ignore the web.xml problem and always run applications in development mode via the Maven goals? Or is there a way to set things so I can run as a Google Web App?
EDIT: Related to the above, is it possible to debug a GWT app running in development mode started by gwt:compile gwt:run? I have added breakpoints to my application but it doesn't stop on them. I'm not sure if it is something I've configured wrong or if it's just not possible.
Update:
In response to Prem's answer...
When I run a compile gwt:run, the web.xml file isn't copied. When I run the install gwt:run, I get this error:
[INFO] --- gwt-maven-plugin:1.2:test (default) # SampleGWT ---
[INFO] using GWT jars from project dependencies : 2.0.4
[INFO] establishing classpath list (scope = test)
[ERROR] java.lang.NoClassDefFoundError: org/codehaus/mojo/gwt/test/MavenTestRunner
[ERROR] Caused by: java.lang.ClassNotFoundException: org.codehaus.mojo.gwt.test.MavenTestRunner
[ERROR] at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
[ERROR] at java.security.AccessController.doPrivileged(Native Method)
[ERROR] at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
[ERROR] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
[ERROR] Could not find the main class: org.codehaus.mojo.gwt.test.MavenTestRunner. Program will exit.
[ERROR] Exception in thread "main"
I’m guessing that bug http://jira.codehaus.org/browse/MGWT-24 is included in version 1.2 of the gwt-maven-plugin. Normally I wouldn’t run install on a project that builds a war file, but I would expect to at least get past the test phase of the build cycle.
Does anybody have any idea why I would get this error on the install but not the compile goals? Also, should I be expecting either goal to copy the web.xml file from src/main/webapp/WEB-INF/web.xml to the /war directory?
Description: The web.xml file does not exist
gwt-maven-plugin creates a project with 'war' packaging format (it's a web app so no surpirse here). Web.xml for this project will be under 'src/main/webapp' folder which will be copied to the 'war' directory (which is set as the output directory) as part of the 'resources' phase in the maven build life-cycle. You should always use
mvn compile gwt:run
or
mvn install gwt:run
so that resources are copied, all java files are compiled and gwt:compile is also invoked (since it is bound to the 'compile' phase automatically)
[WARN] No startup URLs supplied and no plausible ones found -- use -startupUrl
As per the stackoverflow link you used as reference, only your maven build file is setup with startupUrl. In order for it to work in Eclipse, you must edit the Run Configuration of your project and add the '-statupUrl' command line arguments to the existing arguments in the "Arguments" panel.
However, this is just a warning and it should not stop you from running your GWT application from eclipse. If you are facing the same "web.xml" problem here as well, it could be because you did not compile your project in your IDE before invoking "Run as Web Application". I suggest you to disable "Build Automatically" option for this project and always build it manually and invoke "GWT Compile" and then try "Run as web application"
EDIT: Related to the above, is it possible to debug a GWT app running in development mode started by gwt:compile gwt:run?
In general you must use "Remote Application" debug configuration for remote debugging a process. However I am not sure if it will work for GWT projects.
I got me too this warning:
No startup URLs supplied and no plausible ones found
when I have followed this gwt tutorial
In that screenshot there is no checkbox with "Generate sample code" . In my IDE ( sdk 2.5) it is, so I have unchecked...
It wasn't created any of the server and client packages, I have created the client manually, as the tutorial required. The tutorial until that step doesn't say I must have a server package too. That and his configuration is missing from project.
If you right-click on your project and go to Properties -> Google -> Web Application, your WAR directory might be something like either war or src/main/webapp/WEB-INF/classes.
Change that to src/main/webapp.
Also un-check the box next to "Launch and delploy from this directory..."
That's what fixed this problem for me. It also fixed the "can't find gwt-servlet.jar" problem at the same time.