8

I'm using the maven-jaxb-plugin to generate class file sources based on xsd files :

<plugin>
                <groupId>com.sun.tools.xjc.maven2</groupId>
                <artifactId>maven-jaxb-plugin</artifactId>
                <version>1.1.1</version>
                <executions>
                    <execution>
                        <id>jaxb-xsd-constants</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generatePackage>com.mypackage</generatePackage>
                            <schemaDirectory>${basedir}/src/main/resources/xsd/mylist</schemaDirectory>
                            <includeSchemas>
                                <includeSchema>mylist.xsd</includeSchema>
                            </includeSchemas>
                            <strict>true</strict>
                        </configuration>
                    </execution>                    
                </executions>
            </plugin>

enter image description here

But I then need to add these folders as a source folder in order for Eclipse to load compile them :

How can the folder be added as a source folder using the plugin or some other method ? Instead of having to manually add these folders.

blue-sky
  • 51,962
  • 152
  • 427
  • 752

3 Answers3

9

Try to use this maven plugin..

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>target/generated-sources/xjc</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Xstian
  • 8,184
  • 10
  • 42
  • 72
4

Two options:

  • use a modern plugin like which adds source dirs automatically (maven-jaxb2-plugin does this).
  • use something like a buld-helper-maven-plugin to add source folders.

Disclaimer: I am the author of the maven-jaxb2-plugin mentioned above.

Community
  • 1
  • 1
lexicore
  • 42,748
  • 17
  • 132
  • 221
  • When I use the build-helper-maven-plugin I'm required to run mvn eclipse:eclipse against the pom of the current project. Is this expected behavior ? If I do not run eclipse:eclipse then the dir is not added as a source folder. – blue-sky Sep 07 '14 at 21:49
  • @blue-sky I personally use m2eclipse and maven-jaxb2-plugin, works in eclipse automagically. I never run mvn eclipse:eclipse. – lexicore Sep 07 '14 at 22:01
0

I was struggling to add some generated files through vert.x proxy service. Here are the steps which I followed to add generated files to my project in Eclipse.

  1. Right click on your generated folder (in your case mylist)
  2. Click on Build Path
  3. Then click on Use as Source Folder

and there you go! Eclipse will add the folder which has generated files. This is how my project structure looks like after adding the generated files.

Abdul Waheed
  • 63
  • 1
  • 10