First tomcat application - 'ant install' error "NoClassDefFound" - java

JSP/servlets are something I would like to learn, so I set about creating my first tomcat application.
I have gone through the apache tutorial here, and progressed to trying to install my application in tomcat (simple test html file with appropriate dir structure). Now, I realise its very wishful thinking hoping to use the stock build.xml provided by the tutorial but I need to start somewhere, Im not sure how to write one myself just yet. I have looked for examples, but they dont seem to have 'install' targets, perhaps they are not web applications.
My project builds, but does not install onto tomcat via ant. When I attempt to 'ant install' my console outputs...
ant install
Buildfile: /home/mark/svn/tomcatapp/build.xml
Trying to override old definition of datatype resources
prepare:
compile:
[javac] /home/mark/svn/tomcatapp/build.xml:299: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
install:
BUILD FAILED
/home/mark/svn/tomcatapp/build.xml:375: java.lang.NoClassDefFoundError: org/apache/tomcat/util/buf/B2CConverter
at org.apache.catalina.util.Base64.encode(Base64.java:173)
at org.apache.catalina.ant.AbstractCatalinaTask.execute(AbstractCatalinaTask.java:204)
at org.apache.catalina.ant.DeployTask.execute(DeployTask.java:211)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:811)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.lang.ClassNotFoundException: org.apache.tomcat.util.buf.B2CConverter
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 19 more
Total time: 0 seconds
Why would a class fail to be found, would it not be contained within the tomcat install? There is a similar question, but I am not attempting to use the manager app, and I am not sure how to edit the class path - would I need to have compiled a .java class to create one for the project?
I am sure a more simple build file would suffice, but I am not sure which components are relevant. Sorry for the potentially very stupid questions.
Here is my install target from my build.xml file.
<target name="install" depends="compile"
description="Install application to servlet container">
<deploy url="${manager.url}"
username="${manager.username}"
password="${manager.password}"
path="${app.path}"
localWar="file://${build.home}"/>
</target>

If you're using the sample build.xml , change
localWar="file://${build.home}"
to
war="${dist.home}/${app.name}-${app.version}.war"
If you have catalina-ant.jar in ANT_HOME/lib. Try removing it from this location.
Restart tomcat.
That has worked for me.

Short answer:
copy file tomcat-util.jar from CATALINA_HOME/lib to ANT_HOME/lib OR
when issuing ant commands, add -lib option with a path to that file,
for example ant -lib C:\Tomcat8\lib\tomcat-util.jar install (provided CATALINA_HOME points to C:\Tomcat8)
Explanation:
I have encountered similar problem with Tomcat 8.0.36. According to error message class org.apache.tomcat.util.codec.binary.Base64 was not found. ant install command from the tutorial executes deploy task, that is not a standard task in Ant, but a custom task provided by Tomcat. Deploy task is implemented by DeployTask class (full name of the class is org.apache.catalina.ant.DeployTask) which is placed in CATALINA_HOME/lib/catalina-ant.jar. Custom tasks (like DeployTask) usually are dependent on external libraries, so you need to add those libraries to Ant's classpath. For more information see Optional Tasks in Ant.

You have hit https://issues.apache.org/bugzilla/show_bug.cgi?id=52148
Upgrade to the latest Tomcat 7 release and the problem will go away.

I am also running a new version of Tomcat (7.0.32) and encountered the same error while trying to follow the tutorial. I know this isn't the best solution, but perhaps it will be helpful in your debugging: When I use the -lib option with ant I was able to make it pull in the jar files with the needed classes:
ant -lib /usr/local/apache-tomcat-7.0.32/lib/ -lib /usr/local/apache-tomcat-7.0.32/bin/ install (In my case /usr/local/apache-tomcat-7.0.32 is $CATALINA_HOME)

Related

Hadoop with mongoDB : NoClassDefFoundError MongoConfigUtil

I'm learning how to write a map / reduce job in hadoop with mongodb data as input. So I followed this example, but I got following error :
Exception in thread "main" java.lang.NoClassDefFoundError: com/mongodb/hadoop/util/MongoConfigUtil
at WordCount.main(WordCount.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.lang.ClassNotFoundException: com.mongodb.hadoop.util.MongoConfigUtil
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
I've been searching for hours without any result. Any one can help me please.
it means mongo-hadoop-core.jar is available at compile time but not at run time.
Try running your application with dependency jars added in classpath
Example : java -cp mongo-hadoop-core.jar<++other dependencies> MainClass
EDIT 1
If you're running using hadoop shell
check the classpath by executing hadoop classpath it will print the dir/jars in the classpath.
If the dependent jars are not in the classpath add them in the classpath using export command then execute hadoop jar yourjar.jar mainClass
EDIT 2
make use of libjars option
hadoop jar myjar.jar mainClass -libjars ${LIBJARS}
I can see this link examples folder structure is maven. I CANT see pom.xml in that link.
We can set maven scope from provided to runtime
You need to write assembly.xml (to package your application lib and related dependencies in tar file) and need to refer it from pom.xml to package mongo-hadoop-core.jar along with other dependencies which are NOT installed in cluster.
export HADOOP_CLASSPATH=`hadoop classpath`:`hbase classpath`
hadoop jar .... -cp $HADOOP_CLASSPATH MainClass
If you unzip the tar file mentioned above and you can refer the classpath for example :
hadoop jar .... ../lib/* main classs
where lib folder contails all your dependencies like your mongodb also.
If mongo db and related components are installed in the cluster we can mention the classpath like below example.
Also see this answer how they have used libjars

java.lang.ClassNotFoundException: javax.persistence.Entity

I got a sample project, copied from somewhere else, when I am trying to run it in netbeans I am getting some error/exceptions in tomcat's console window.
java.lang.ClassNotFoundException: javax.persistence.Entity
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
at org.springframework.core.type.classreading.RecursiveAnnotationAttributesVisitor.visitEnd(AnnotationAttributesReadingVisitor.java:167)
at org.springframework.asm.ClassReader.a(Unknown Source)
at org.springframework.asm.ClassReader.accept(Unknown Source)
at org.springframework.asm.ClassReader.accept(Unknown Source)
javax.persistence is already added to my project. I even removed and re-added in netbeans but still same error. This error is when running the web applictation not when compiling.
You need to add following Jar Files to your Build Path: -
javax.persistence_2.0.3.v201010191057.jar
org.eclipse.persistence.jpa_2.3.0.v20110604-r9504.jar
org.eclipse.persistence.jpa.equinox_2.3.1.v20111018-r10243.jar
org.eclipse.persistence.antlr_2.3.0.v20110604-r9504.jar
org.eclipse.persistence.asm_2.3.0.v20110604-r9504.jar
Preferably adding the first one will work, as javax.persistence.Entity is found in that Jar only.
But you may also need to add the later ones, for working with JPA
Google them with the name of JPA Jars. You will get them.
The javax.persistence.Entity is a class inside the Java EE SDK library “javaee.jar“, you are missing this jar file in your project classpath.
refer this http://www.mkyong.com/hibernate/java-lang-classnotfoundexception-javax-persistence-entity/

appengine 1.7.2 err after upgrade

I upgraded AE to 1.7.2 and now get the following error when first trying to access a page:
What can I do to get 1.7.2 working???
Could not initialize class com.google.appengine.tools.appstats.RecordingData
Caused by:
java.lang.NoClassDefFoundError: Could not initialize class
com.google.appengine.tools.appstats.RecordingData
at com.google.appengine.tools.appstats.Recorder.makeAsyncCall(Recorder.java:300)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
at com.google.appengine.tools.appstats.AppstatsFilter.call(AppstatsFilter.java:231)
Note: the "RecordingData" class that could not be initialized is in the appengine-api-labs.jar is definately in my build path only now it is not working. I guess though that the Could not initialize class error means it's being found but not working. the NoClassDefFoundError is misleading I suspect.
I had the same issue recently, I started working on an existing AppEngine project which had been using the 1.7.1 API. I had a new eclipse setup using the newest plugin (1.7.2.1 at the time of writing).
In my case there was an older copy of the labs jar (appengine-api-labs.jar) in the build path. Deleting this and replacing it with the version from the AppEngine SDK in current use resolved the issue.
You'll find the labs jar in your eclipse plugins directory under: appengine-java-sdk-[X.X.X.X]\lib\impl).
Once you have replaced the jar do a clean build and you should be laughing.

Integrated ant - taskdef classloader issue

On Weblogic 10.3 my enterprise application includes a webservice that runs ant scripts inside. My problem is that I cannot get my custom tasks running due to java.lang.ClassNotFoundExceptions.
(All this works well on Tomcat 5.5)
My task implementation can be found in 4 different locations:
something.ear/APP-INF/lib/antaddon.jar!/foo/bar/MyTask.class
something.ear/Webservice.war/WEB-INF/lib/antaddon.jar!/foo/bar/MyTask.class
something.ear/Webservice.war/WEB-INF/classes/foo/bar/MyTask.class
server/lib/antaddon.jar!/foo/bar/MyTask.class
I see that the Weblogic 10.3 integrated Ant 1.6.5 module might cause problems
as I have an Ant 1.8.0 bundled, so I added
<prefer-application-packages>
<package-name>antlr.*</package-name>
<package-name>org.apache.ant.*</package-name>
<package-name>org.apache.zip.*</package-name>
</prefer-application-packages>
to my weblogic-application.xml to overcome this. (This solved some NoSuchMethodErrors..)
However my Task is still not found:
java.lang.ClassNotFoundException: foo.bar.MyTask.class
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java:457)
at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:183)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:142)
at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:91)
can you help me how to solve this?
The problem was that my prefer-application-packages directive was wrong, ant classes are not in org.apache.ant.* but in org.apache.tools.ant.*. After repairing this my custom class gets loaded and works well from APP-INF/lib/antaddon.jar

Why does m2eclipse exclude resources from Eclipse build path?

I am trying out m2eclipse, the Eclipse plugin for Maven, and have noticed that the resources are now excluded from the build path of all my projects.
I have seen a question on the M2Eclipse FAQ page which seems to deal with this exact question, but the answer (paraphrased) seems to say that this is intentional to allow resource filtering, and everything Should Just Work.
However, when I run my application from within Eclipse, lots of my resources in dependent projects are failing to get found by my application.
I have tried my usual Eclipse waving-a-rubber-chicken actions (cleaning all projects, starting with -clean) to no avail. I'm sure I'm missing something fairly simple. Does anyone have any suggestions?
EDIT: Some digging in the m2 console has revealed that one of the projects is not building correctly. I get a ClassNotFoundException when it tries to find org.apache.maven.plugin.MojoFailureException in a custom plugin used to build one of the projects.
org.apache.maven.lifecycle.LifecycleExecutionException: Internal error in the plugin manager executing goal 'ourdemain:ourcustomplugin:2.0:process': Mojo execution failed.
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:505)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmentForProject(DefaultLifecycleExecutor.java:265)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:191)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:149)
at org.apache.maven.DefaultMaven.execute_aroundBody0(DefaultMaven.java:223)
at org.apache.maven.DefaultMaven.execute_aroundBody1$advice(DefaultMaven.java:304)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:1)
at org.apache.maven.embedder.MavenEmbedder.execute_aroundBody2(MavenEmbedder.java:904)
at org.apache.maven.embedder.MavenEmbedder.execute_aroundBody3$advice(MavenEmbedder.java:304)
at org.apache.maven.embedder.MavenEmbedder.execute(MavenEmbedder.java:1)
at org.maven.ide.eclipse.internal.project.DefaultBuildParticipant$1.execute(DefaultBuildParticipant.java:130)
at org.maven.ide.eclipse.internal.project.MavenProjectManagerImpl.execute(MavenProjectManagerImpl.java:986)
at org.maven.ide.eclipse.internal.project.MavenProjectFacade.execute(MavenProjectFacade.java:320)
at org.maven.ide.eclipse.internal.project.DefaultBuildParticipant.executePostBuild(DefaultBuildParticipant.java:116)
at org.maven.ide.eclipse.internal.project.DefaultBuildParticipant.build(DefaultBuildParticipant.java:80)
at org.maven.ide.eclipse.internal.builder.MavenBuilder.build(MavenBuilder.java:84)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:633)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:170)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:201)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:253)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:256)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:309)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:341)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:140)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:238)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: org.apache.maven.plugin.PluginExecutionException: Mojo execution failed.
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:601)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:498)
... 27 more
Caused by: org.apache.maven.plugin.MojoExecutionException: org/apache/maven/plugin/MojoFailureException
at org.codehaus.mojo.ruby.DefaultRubyMojo.execute(DefaultRubyMojo.java:98)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:579)
... 28 more
Caused by: java.lang.NoClassDefFoundError: org/apache/maven/plugin/MojoFailureException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.getConstructor(Class.java:1657)
at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:587)
at org.jruby.javasupport.Java.new_proxy_instance(Java.java:570)
at org.jruby.javasupport.JavaInvokerSnew_proxy_instancexx1.call(Unknown Source)
at org.jruby.runtime.callback.InvocationCallback.execute(InvocationCallback.java:49)
at org.jruby.internal.runtime.methods.FullFunctionCallbackMethod.internalCall(FullFunctionCallbackMethod.java:79)
at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:79)
at org.jruby.evaluator.EvaluationState.callNode(EvaluationState.java:577)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:206)
at org.jruby.evaluator.EvaluationState.setupArgs(EvaluationState.java:2182)
at org.jruby.evaluator.EvaluationState.attrAssignNode(EvaluationState.java:481)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:191)
at org.jruby.evaluator.EvaluationState.blockNode(EvaluationState.java:522)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:200)
at org.jruby.evaluator.EvaluationState.eval(EvaluationState.java:163)
at org.jruby.internal.runtime.methods.DefaultMethod.internalCall(DefaultMethod.java:167)
at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:79)
at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:125)
at org.jruby.evaluator.EvaluationState.callNode(EvaluationState.java:564)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:206)
at org.jruby.evaluator.EvaluationState.callNode(EvaluationState.java:544)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:206)
at org.jruby.evaluator.EvaluationState.localAsgnNode(EvaluationState.java:1230)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:285)
at org.jruby.evaluator.EvaluationState.rescueNode(EvaluationState.java:1522)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:349)
at org.jruby.evaluator.EvaluationState.ensureNode(EvaluationState.java:980)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:246)
at org.jruby.evaluator.EvaluationState.eval(EvaluationState.java:163)
at org.jruby.internal.runtime.methods.DefaultMethod.internalCall(DefaultMethod.java:167)
at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:79)
at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:125)
at org.jruby.evaluator.EvaluationState.fCallNode(EvaluationState.java:1019)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:252)
at org.jruby.evaluator.EvaluationState.blockNode(EvaluationState.java:522)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:200)
at org.jruby.evaluator.EvaluationState.rootNode(EvaluationState.java:1622)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:355)
at org.jruby.evaluator.EvaluationState.eval(EvaluationState.java:163)
at org.jruby.Ruby.eval(Ruby.java:274)
at org.codehaus.plexus.component.jruby.JRubyRuntimeInvoker.runInterpreter(JRubyRuntimeInvoker.java:392)
at org.codehaus.plexus.component.jruby.JRubyRuntimeInvoker.invoke(JRubyRuntimeInvoker.java:313)
at org.codehaus.mojo.ruby.DefaultRubyMojo.execute(DefaultRubyMojo.java:81)
... 29 more
Caused by: java.lang.ClassNotFoundException: org.apache.maven.plugin.MojoFailureException
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
... 75 more
The resource filtering mentioned in the FAQ is run whenever the Maven builder is run on the project. In practice I've found this to be more trouble than it's worth as the Maven builder runs quite slowly, and is only run when configured (which by default is only on a full build), leaving you to scratch your head and wonder why your changes aren't picked up.
I tend to modify the Eclipse classpath to include src/main/resources. This is sufficient for most use cases.
For the cases where the simple approach doesn't work (for example if a dependent project has some complicated resource processing), I do as Robert suggests and turn off workspace resolution, then install the dependency to the local repository so it is included in the Maven classpath container.
Try switching between the embedded ( 3.0 AFAIK ) Maven runtime and the one you use to perform your builds ( locally installed ).
Maven installations http://img150.imageshack.us/img150/6193/m2eclipseinstallations.png

Categories

Resources