Marshall Schor wrote:
> We've changed several sandbox projects (SimpleServer,
> DictionaryAnnotator, RegularExpressionAnnotator, and CFE) that use
> XMLBeans to produce an XML parser, to an approach where the parse is
> built (if needed) by maven using the xmlbeans-maven-plugin.
>
> This plugin generates java sources and classes for the parser into
> target/generated-sources/xmlbeans and
> target/generated-classes/xmlbeans.  Note that the generated-classes have
> additional java classes that are different from what would be compiled
> from generated-sources, so both are needed.
>
> (Maven build / test seems to be working fine.)
>
> The maven eclipse:eclipse goal (maven-eclipse-plugin version 2.7)
> generates a .project/.classpath for eclipse that uses these files by (a)
> adding both of these directories to the classpath, (b) turning on the
> flag that says "allow output folders for source folders" (not sure why
> it does this, it isn't needed), and setting up complementary
> inclusion/exclusion rules around **/*.java for these two folders:
>
>   proj/target/generated-classes/xmlbeans
>     Output folder: (Default output folder = proj/target/classes
>     Included: (All)
>     Excluded: **/*.java
>
>   proj/target/generated-sources/xmlbeans
>     Output folder: (Default output folder = proj/target/classes
>     Included: **/*.java
>     Excluded: (None)
>
> This works for having Eclipse build the project without errors, but
> there seems to be an Eclipse problem using this configuration for
> running Junit tests as configured and launched by Eclipse.  The
> classpath for the launcher for a Junit test (or test suite) has as a
> first element an icon showing the folder for the project - indicating
> that the project's output class folder (in this case,
> proj/target/classes) is on the classpath.  The project's output class
> folder does indeed have classes from both generated-sources and
> generated-classes (I checked this using Windows Explorer).  However, the
> Junit tests fail, indicating class-not-found for the generated-classes
> items.
>   
Found the problem. 

If you do mvn clean install (of SimpleServer), followed by
Eclipse->project->clean (of SimpleServer), and then run the tests, it fails.

If you redo mvn clean install after any Eclipse building, it works.

The error (when it occurs) is:

java.lang.ClassNotFoundException:
schemaorg_apache_xmlbeans.system.sD8360DFF7E1263139EC462A6BFD0672D.TypeSystemHolder

The class path for running tests in Eclipse looks in target/classes,
which is the standard, default output directory for this Eclipse build;
it is in the Eclpse classpath for running the test.

The Eclipse "clean" operation erases the target/class file, and rebuilds
it.  The rebuilding operation takes all of the generated-classes files
**except the TypeSystemHolder** and copies them, as part of the build
process, into the target/class file. 

Running mvn clean install rebuilds the target/class file, but does
include the TypeSystemHolder when it copies the generated-classes files.

So - why is that one file singled out?  It turns out it's the only file
with the extension ".class".  The Eclipse copy-resources step must be
excluding these...

Some additional work-arounds.  The Eclipse Java builder can be
configured to not delete all the .classes in the output folder when
rebuilding.  You can set on all projects, or particular projects.  To
set it on a particular project, like the SimpleServer, select that
project, and then do Project->properties->Java
Compiler->Building->Output folder and uncheck the box "Scrub output
folders when cleaning projects". 

See http://dev.cleversafe.org/weblog/?p=53 for another mention of this
solution, in the context of using m2eclipse Eclipse plugin. 

This seems to me to be an Eclipse bug, that could be fixed by having the
Eclipse step the copies resources to the output folder include .class
files it finds.

-Marshall
> This seems to be an Eclipse problem - in both 3.5 and 3.5.1 versions.
>
> Work-around:
> ------------
>
> Change the launch configuration for running the Junit test by adding
> explicitly an additional classpath that picks up the
> target/generated-classes/xmlbeans directory as an additional "folder" to
> use.  You can alternatively add the project's Jar artifact instead. 
> I've tried both approaches and they both make the tests go through OK.
>
> Others have seen this problem also:
> http://www.nabble.com/Help-with-running-in-eclipse-td15345608.html
>
> -Marshall
>
>
>  
>
>
>   

Reply via email to