Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » IAM (Eclipse Integration for Apache Maven) » Dependency on test classes in another project
Dependency on test classes in another project [message #527287] Wed, 14 April 2010 12:36 Go to next message
No real name is currently offline No real name
Messages: 19
Registered: July 2009
Junior Member
I'm using Eclipse IAM: 0.11.0.201001181900 on eclipse 3.5.2

First project has a package.Foo class in src/test/java

Second project depends on that one via:

<dependency>
<groupId>group</groupId>
<artifactId>artifact</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
<optional>false</optional>
</dependency>
<dependency>
<groupId>groupg</groupId>
<artifactId>artifact</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
<optional>false</optional>
</dependency>

Creating a JUnit class in the second src/test/java that uses Foo. It compiles fine. But if I run it, it fails with:

java.lang.NoClassDefFoundError: package.Foo
at bar.SomeTest.someTest(SomeTest.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java: 52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java: 184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: package.Foo
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:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301 )
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320 )
... 23 more

I go to the debug perspective right click on terminated process, properties, and look at classpath on the command line. It doesn't include the first project's test-classes. Why?

[Updated on: Wed, 14 April 2010 13:04]

Report message to a moderator

Re: Dependency on test classes in another project [message #527755 is a reply to message #527287] Fri, 16 April 2010 07:24 Go to previous messageGo to next message
Carlos Sanchez is currently offline Carlos Sanchez
Messages: 114
Registered: July 2009
Senior Member
is your src/test/java folder a source folder in the "artifact" project?
IAM adds a link between projects, and Eclipse should honor those
settings while running in Eclispe

On 4/14/10 6:36 PM, joel@mentics.com wrote:
> First project has a package.Foo class in src/test/java
>
> Second project depends on that one via:
>
> <dependency>
> <groupId>group</groupId>
> <artifactId>artifact</artifactId>
> <version>0.0.1-SNAPSHOT</version>
> <type>jar</type>
> <scope>compile</scope>
> <optional>false</optional>
> </dependency>
> <dependency>
> <groupId>groupg</groupId>
> <artifactId>artifact</artifactId>
> <version>0.0.1-SNAPSHOT</version>
> <type>test-jar</type>
> <scope>test</scope>
> <optional>false</optional>
> </dependency>
>
> Creating a JUnit class in the second src/test/java that uses Foo. It
> compiles fine. But if I run it, it fails with:
>
> java.lang.NoClassDefFoundError: package.Foo
> at bar.SomeTest.someTest(SomeTest.java:11)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce
> ssorImpl.java:39)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe
> thodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
> FrameworkMethod.java:44)
> at org.junit.internal.runners.model.ReflectiveCallable.run(Refl
> ectiveCallable.java:15)
> at org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr
> ameworkMethod.java:41)
> at org.junit.internal.runners.statements.InvokeMethod.evaluate(
> InvokeMethod.java:20)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> 4ClassRunner.java:76)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> 4ClassRunner.java:50)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java: 52)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :191)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 42)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java: 184)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
> at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r
> un(JUnit4TestReference.java:46)
> at org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test
> Execution.java:38)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> sts(RemoteTestRunner.java:467)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> sts(RemoteTestRunner.java:683)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R
> emoteTestRunner.java:390)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> RemoteTestRunner.java:197)
> Caused by: java.lang.ClassNotFoundException: package.Foo
> 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:307)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301 )
> at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
> at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320 )
> ... 23 more
>
> I go to the debug perspective right click on terminated process,
> properties, and look at classpath on the command line. It doesn't
> include the first project's test-classes. Why?
>
Re: Dependency on test classes in another project [message #527810 is a reply to message #527755] Fri, 16 April 2010 10:49 Go to previous messageGo to next message
No real name is currently offline No real name
Messages: 19
Registered: July 2009
Junior Member
Carlos Sanchez wrote on Fri, 16 April 2010 07:24
is your src/test/java folder a source folder in the "artifact" project?
IAM adds a link between projects, and Eclipse should honor those
settings while running in Eclispe


Yes, src/test/java is a source folder. And if I manually edit the launcher and add the first project to the classpath it will work. For some reason it is not adding the test-classes to the classpath of the launcher or something. Obviously, manually editing all the launchers to add that to the classpath is a real nuisance and shouldn't be necessary--something isn't working right.
Re: Dependency on test classes in another project [message #528085 is a reply to message #527810] Mon, 19 April 2010 05:16 Go to previous messageGo to next message
Carlos Sanchez is currently offline Carlos Sanchez
Messages: 114
Registered: July 2009
Senior Member
from what you say you don't have the 1st project on the 2nd' classpath,
can you check that in the Maven Classpath Container? you may have a
dependency to the jar in the local repository instead.
IAM will automatically add that link if the dependency
group/artifact/version match

On 4/16/10 4:50 PM, joel@mentics.com wrote:
> Carlos Sanchez wrote on Fri, 16 April 2010 07:24
>> is your src/test/java folder a source folder in the "artifact" project?
>> IAM adds a link between projects, and Eclipse should honor those
>> settings while running in Eclispe
>
>
> Yes, src/test/java is a source folder. And if I manually edit the
> launcher and add the first project to the classpath it will work. For
> some reason it is not adding the test-classes to the classpath of the
> launcher or something. Obviously, manually editing all the launchers to
> add that to the classpath is a real nuisance and shouldn't be
> necessary--something isn't working right.
Re: Dependency on test classes in another project [message #528166 is a reply to message #528085] Mon, 19 April 2010 11:01 Go to previous message
No real name is currently offline No real name
Messages: 19
Registered: July 2009
Junior Member
Carlos Sanchez wrote on Mon, 19 April 2010 05:16
from what you say you don't have the 1st project on the 2nd' classpath,
can you check that in the Maven Classpath Container? you may have a
dependency to the jar in the local repository instead.
IAM will automatically add that link if the dependency
group/artifact/version match



The project does show up in Maven Classpath Container. And, target/classes for the other project does show up in the classpath in the launcher. Just target/test-classes doesn't.

At least that's what it was doing. I tried again today and now it's working. I had added the project explicitly to the run config as a workaround. I recreated it, and created a new one and now it's working. I don't know if it was restarting eclipse, rebuilding... whatever that might have kicked it into working... oh well.
Re: Dependency on test classes in another project [message #572783 is a reply to message #527287] Fri, 16 April 2010 07:24 Go to previous message
Carlos Sanchez is currently offline Carlos Sanchez
Messages: 114
Registered: July 2009
Senior Member
is your src/test/java folder a source folder in the "artifact" project?
IAM adds a link between projects, and Eclipse should honor those
settings while running in Eclispe

On 4/14/10 6:36 PM, joel@mentics.com wrote:
> First project has a package.Foo class in src/test/java
>
> Second project depends on that one via:
>
> <dependency>
> <groupId>group</groupId>
> <artifactId>artifact</artifactId>
> <version>0.0.1-SNAPSHOT</version>
> <type>jar</type>
> <scope>compile</scope>
> <optional>false</optional>
> </dependency>
> <dependency>
> <groupId>groupg</groupId>
> <artifactId>artifact</artifactId>
> <version>0.0.1-SNAPSHOT</version>
> <type>test-jar</type>
> <scope>test</scope>
> <optional>false</optional>
> </dependency>
>
> Creating a JUnit class in the second src/test/java that uses Foo. It
> compiles fine. But if I run it, it fails with:
>
> java.lang.NoClassDefFoundError: package.Foo
> at bar.SomeTest.someTest(SomeTest.java:11)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce
> ssorImpl.java:39)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe
> thodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
> FrameworkMethod.java:44)
> at org.junit.internal.runners.model.ReflectiveCallable.run(Refl
> ectiveCallable.java:15)
> at org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr
> ameworkMethod.java:41)
> at org.junit.internal.runners.statements.InvokeMethod.evaluate(
> InvokeMethod.java:20)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> 4ClassRunner.java:76)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> 4ClassRunner.java:50)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java: 52)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :191)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 42)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java: 184)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
> at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r
> un(JUnit4TestReference.java:46)
> at org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test
> Execution.java:38)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> sts(RemoteTestRunner.java:467)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> sts(RemoteTestRunner.java:683)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R
> emoteTestRunner.java:390)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> RemoteTestRunner.java:197)
> Caused by: java.lang.ClassNotFoundException: package.Foo
> 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:307)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301 )
> at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
> at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320 )
> ... 23 more
>
> I go to the debug perspective right click on terminated process,
> properties, and look at classpath on the command line. It doesn't
> include the first project's test-classes. Why?
>
Re: Dependency on test classes in another project [message #572801 is a reply to message #527755] Fri, 16 April 2010 10:50 Go to previous message
No real name is currently offline No real name
Messages: 19
Registered: July 2009
Junior Member
Carlos Sanchez wrote on Fri, 16 April 2010 07:24
> is your src/test/java folder a source folder in the "artifact" project?
> IAM adds a link between projects, and Eclipse should honor those
> settings while running in Eclispe


Yes, src/test/java is a source folder. And if I manually edit the launcher and add the first project to the classpath it will work. For some reason it is not adding the test-classes to the classpath of the launcher or something. Obviously, manually editing all the launchers to add that to the classpath is a real nuisance and shouldn't be necessary--something isn't working right.
Re: Dependency on test classes in another project [message #572823 is a reply to message #572801] Mon, 19 April 2010 05:16 Go to previous message
Carlos Sanchez is currently offline Carlos Sanchez
Messages: 114
Registered: July 2009
Senior Member
from what you say you don't have the 1st project on the 2nd' classpath,
can you check that in the Maven Classpath Container? you may have a
dependency to the jar in the local repository instead.
IAM will automatically add that link if the dependency
group/artifact/version match

On 4/16/10 4:50 PM, joel@mentics.com wrote:
> Carlos Sanchez wrote on Fri, 16 April 2010 07:24
>> is your src/test/java folder a source folder in the "artifact" project?
>> IAM adds a link between projects, and Eclipse should honor those
>> settings while running in Eclispe
>
>
> Yes, src/test/java is a source folder. And if I manually edit the
> launcher and add the first project to the classpath it will work. For
> some reason it is not adding the test-classes to the classpath of the
> launcher or something. Obviously, manually editing all the launchers to
> add that to the classpath is a real nuisance and shouldn't be
> necessary--something isn't working right.
Re: Dependency on test classes in another project [message #572851 is a reply to message #528085] Mon, 19 April 2010 11:01 Go to previous message
No real name is currently offline No real name
Messages: 19
Registered: July 2009
Junior Member
Carlos Sanchez wrote on Mon, 19 April 2010 05:16
> from what you say you don't have the 1st project on the 2nd' classpath,
> can you check that in the Maven Classpath Container? you may have a
> dependency to the jar in the local repository instead.
> IAM will automatically add that link if the dependency
> group/artifact/version match



The project does show up in Maven Classpath Container. And, target/classes for the other project does show up in the classpath in the launcher. Just target/test-classes doesn't.

At least that's what it was doing. I tried again today and now it's working. I had added the project explicitly to the run config as a workaround. I recreated it, and created a new one and now it's working. I don't know if it was restarting eclipse, rebuilding... whatever that might have kicked it into working... oh well.
Previous Topic:Dependency on test classes in another project
Next Topic:Incremental Build runs continually
Goto Forum:
  


Current Time: Fri Jul 25 09:47:26 EDT 2014

Powered by FUDForum. Page generated in 0.09861 seconds