Ant JUnit Task couldn't find junit/framework/TestCase.class - eclipse

I'm trying to get a JUnit 4.8.1 task to run in Ant 1.7.1. My IDE is Eclipse Helios. I've been banging my head against a brick wall for 2 days now and cannot figure this out. I'm sure from reading other posts its a classpath problem, but I can't see where I'm going wrong.
My JUnit4 test suite is defined as follows:
package mypackage.tests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
/**
* JUnit 4 Test Suite for the entire <code>mypackage</code>
* package
*/
#RunWith(Suite.class)
#Suite.SuiteClasses({ mypackage.tests.controller.AllTests.class })
public class AllTests {
}
...simple enough, but the test fails with a ClassNotFoundException
java.lang.ClassNotFoundException: mypackage.tests.AllTests
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
When I switch on the debug flag, I get the following trace from Ant:
(...)
[junit] Couldn't find junit/framework/TestCase.class
[junit] Found C:\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-launcher.jar
[junit] Found C:\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant.jar
[junit] Found C:\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-junit.jar
fileset: Setup scanner in dir C:\eclipse\plugins with patternSet{ includes: [org.junit_4.8.1.v4_8_1_v20100427-1100/junit.jar] excludes: [] }
Finding class junit.framework.Test
Loaded from C:\eclipse\plugins\org.junit_4.8.1.v4_8_1_v20100427-1100\junit.jar junit/framework/Test.class
(...)
Clearly the JUnit jar is on the classpath, and other classes such as Test.class are being picked up, so why am I getting the 'couldn't find TestClass.class' message?
I tried adding the JUnit.jar to the ant classpath in the Eclipse GUI, and this has the following effect:
(...)
[junit] Found C:\eclipse\plugins\org.junit_4.8.1.v4_8_1_v20100427-1100\junit.jar
[junit] Found C:\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-launcher.jar
[junit] Found C:\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant.jar
[junit] Found C:\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-junit.jar
(...)
[junit] WARNING: multiple versions of ant detected in path for junit
[junit] jar:file:C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant.jar!/org/apache/tools/ant/Project.class
[junit] and jar:file:/C:/eclipse/plugins/org.apache.ant_1.7.1.v20100518-1145/lib/ant.jar!/org/apache/tools/ant/Project.class
(...)
Can someone please please please help me to get this working!
Oh, I almost forgot... the test suite runs fine from within Eclipse.
Thanks in advance!

The error is caused by the fact that your test classes cannot be loaded.
Did you put the package mypackage.tests.controller (i.e. the folder(s) containing the class files or the jar archive) on the classpath of your junit call? This can be done using a nested classpath structure. (http://ant.apache.org/manual/Tasks/junit.html).

Related

Joda Time - Cannot run JUnit tests in Eclipse or IntelliJ

I cloned the joda-time GitHub repository locally, imported it as a Maven project in both Eclipse and IntelliJ Idea and it built absolutelly fine in both IDEs. But when trying to run the JUnit tests it just will not work in either IDE and I cannot see what the issue is.
I know that I need to create an additional folder
src\tz-data\org\joda\time\tz\data
and place in there the two files
CET
ZoneInfoMap
and I have done all that.
The JUnit tests still do not run and the funny thing is that I get completelly different errors under Eclipse:
java.lang.ExceptionInInitializerError
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.getTest(JUnit3TestLoader.java:100)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.loadTests(JUnit3TestLoader.java:51)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.IllegalArgumentException: The datetime zone id 'Europe/Paris' is not recognised
at org.joda.time.DateTimeZone.forID(DateTimeZone.java:234)
at org.joda.time.TestLocalDate_Basics.<clinit>(TestLocalDate_Basics.java:50)
... 10 more
and under IntelliJ Idea:
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.joda.time.TestAbstractPartial
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at junit.framework.TestSuite.createTest(TestSuite.java:58)
at junit.framework.TestSuite.addTestMethod(TestSuite.java:280)
at junit.framework.TestSuite.<init>(TestSuite.java:140)
at com.intellij.junit3.TestRunnerUtil.createClassOrMethodSuite(TestRunnerUtil.java:147)
at com.intellij.junit3.TestAllInPackage2.<init>(TestAllInPackage2.java:32)
at com.intellij.junit3.TestRunnerUtil.getTestSuite(TestRunnerUtil.java:78)
at com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:43)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Any tips on how to get around this would be really appreciated.
I am new to maven and it turns out the issue was with the way I was trying to run the tests.
As noted by roby, I should have used the maven bar in IntelliJ to run the correct maven goal (simmilarly, I should have used Run As.. and the correct maven goal in Eclipse), whereas I was just trying to run the tests by using the IDE, i.e. right click on the project and 'Run All Tests' which understandably did not work as it was not using the correct configuration.

gwtbootstrap3 available at compile time but not at runtime?

question is about gwtbootstap3 error that I am receiving when trying to run my GWT application. Everything mentioned here Initial Setup is being done and my code compiles and gets installed using maven. Dependency scope is provided so should I manually copy jar to application server? I am using JBoss 6.1.0 Final. If JAR file needs to be copied manually, where do I put it? Below is error that I receive,
unning GPE launcher for GWT-2.6.x version.
Runing CodeServer with parameters: [-noprecompile, -port, 9876, -bindAddress, 127.0.0.1, com.HouseKeepingGWT]
workDir: /tmp/gwt-codeserver-1867973844823357957.tmp
Loading modules
com.HouseKeepingGWT
Loading inherited module 'com.HouseKeepingGWT'
Loading inherited module 'org.gwtbootstrap3.GwtBootstrap3'
Loading inherited module 'com.HouseKeepingGWT'
[ERROR] Unable to find 'org/gwtbootstrap3/GwtBootstrap3.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
Loading inherited module 'org.gwtbootstrap3.GwtBootstrap3'
[ERROR] Unable to find 'org/gwtbootstrap3/GwtBootstrap3.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
[ERROR] Line 17: Unexpected exception while processing element 'inherits'
[ERROR] Line 17: Unexpected exception while processing element 'inherits'
com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
at com.google.gwt.dev.cfg.ModuleDefLoader.nestedLoad(ModuleDefLoader.java:328)
at com.google.gwt.dev.cfg.ModuleDefLoader.nestedLoad(ModuleDefLoader.java:328)
at com.google.gwt.dev.cfg.ModuleDefSchema$BodySchema.__inherits_begin(ModuleDefSchema.java:497)
at com.google.gwt.dev.cfg.ModuleDefSchema$BodySchema.__inherits_begin(ModuleDefSchema.java:497)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.google.gwt.dev.util.xml.HandlerMethod.invokeBegin(HandlerMethod.java:230)
at com.google.gwt.dev.util.xml.HandlerMethod.invokeBegin(HandlerMethod.java:230)
at com.google.gwt.dev.util.xml.ReflectiveParser$Impl.startElement(ReflectiveParser.java:294)
at com.google.gwt.dev.util.xml.ReflectiveParser$Impl.startElement(ReflectiveParser.java:294)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
Looks like, JAR is not available at run time that is why I am receiving error. Please suggest. GwtBootstrap3.gwt.xml is in gwtbootstrap3 jar.
Check this tutorial for configuring JBoss shared libs folder (or find another one on the web, it shouldn't be too hard). However, why are you using the provided scope? If this application is the only one using gwtBootstrap you can remove it so that Maven can package the jar directly inside your application's war.

Executable Scala Jar from Eclipse using Java main class

I am trying to create an executable Jar from my Scala project. Therefore, I followed a tutorial. It suggested creating a Java main class within eclipse, which calls the Scala entry point. This works fine when executing within eclipse. After adding this class I was able to export an executable jar. However, it wont work with
java -jar myjar.jar
I made sure to activate "Package required library into jar" when exporting. My Java main class looks like this (where Driver is also located in the package core)
package core;
public class Main {
public static void main(String[] args) {
Driver.main(args);
}
}
And when executing the exported char the follwing error is thrown, which I can debug:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.NoClassDefFoundError: scala/collection/Seq
at core.Driver$.main(Driver.scala:14)
at core.Driver.main(Driver.scala)
at core.Main.main(Main.java:5)
... 5 more
Caused by: java.lang.ClassNotFoundException: scala.collection.Seq
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:425)
You could use the One-jar application to guarantee all the necessary jars are in the jarfile, I suspect the scala-lang jars are not in it or in the classpath of the command line.
Maven: https://code.google.com/p/onejar-maven-plugin/
SBT: https://github.com/sbt/sbt-onejar
If you aren't using either maven or SBT I would suggest switching to them as well as they are the main supported build systems in Scala

NPE when building OSGi bundles with Maven Tycho

I have several OSGi-bundles that I want to build using Maven Tycho. While the dependencies of the first 4 bundles can be resolved without problem, Tycho quits with the following cryptic exception at the 5th:
[INFO] Resolving dependencies of MavenProject: my.parent:my.module:0.0.1-SNAPSHOT # D:\Path\To\Project\pom.xml
[WARNING] The following locally built units have been used to resolve project dependencies:
[WARNING] my-other-module/0.0.1.201407011334
[INFO] Resolving class path of MavenProject: my.parent:my.module:0.0.1-SNAPSHOT # D:\Path\To\Project\pom.xml
[ERROR] Internal error: java.lang.NullPointerException -> [Help 1]
org.apache.maven.InternalErrorException: Internal error: java.lang.NullPointerException
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:167)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: java.lang.NullPointerException
at org.eclipse.tycho.core.osgitools.OsgiBundleProject.resolveClassPath(OsgiBundleProject.java:187)
at org.eclipse.tycho.core.resolver.DefaultTychoDependencyResolver.resolveProject(DefaultTychoDependencyResolver.java:122)
at org.eclipse.tycho.core.maven.TychoMavenLifecycleParticipant.afterProjectsRead(TychoMavenLifecycleParticipant.java:75)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
... 11 more
Following is the MANIFEST.MF of that bundle (Import-Package section):
Import-Package: my.other.module.package;version="[0.0,1)",
org.apache.commons.lang3.builder;version="[3.3,4)",
org.dozer;version="[5.5,6)",
org.osgi.service.blueprint;version="[1.0.0,2.0.0)"
Resolving the dependencies from the repository shouldn't be a problem, as launching the bundles from within eclipse works fine.
Interesting aspect: I'm working on Windows 7x64. On my coworker's pc with Linux it runs fine.
I'm not really sure where to start finding the error - the exception doesn't really give a hint, so I'd appreciate every tip. If you need further information, I'd be happy to clarify.

Unable to find 'com/extjs/gxt/ui/GXT.gwt.xml' in GXT sample application

I'm trying to run a sample application using GXT (ExtJS + GWT) as described in the tutorial at
http://www.sencha.com/learn/setting-up-your-first-ext-gwt-project-in-eclipse
When I try to run the application in eclipse, I get the error
Loading modules
com.hello.gxt.HelloGXT
Loading inherited module 'com.extjs.gxt.ui.GXT'
[ERROR] Unable to find 'com/extjs/gxt/ui/GXT.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
[ERROR] Line 15: Unexpected exception while processing element 'inherits'
My build path looks like this
and the build path of the run configuration looks like this
Here's the source: https://dl.dropbox.com/u/11776689/2012_09_27_HelloGXT.zip
How can I fix the problem?
'Update 29.09.2012': The former error is fixed, but now I get another one:
Loading modules
com.hello.gxt.HelloGXT
Loading inherited module 'com.sencha.gxt.ui.GXT'
Loading inherited module 'com.sencha.gxt.data.Data'
Loading inherited module 'com.sencha.gxt.core.Core'
[ERROR] Unexpected error while processing XML
java.lang.NoClassDefFoundError: com/google/gwt/core/ext/Generator
at java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.lang.ClassLoader.findBootstrapClassOrNull(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Change your *.gwt.xml file from:
<inherits name="com.extjs.gxt.ui.GXT" />
to
<inherits name='com.sencha.gxt.ui.GXT' />
The tutorial you used is definitely for version 2.0. From GXT 3.0, the namespace changed to com.sencha.gxt...
UPDATE - to answer the next issue:
I think you are missing gwt-dev.jar
See this for reference: http://www.sencha.com/forum/showthread.php?73617-GWT-1.64-Class-not-found-exception-GXT-module-declaration-is.