Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add generated-sources as source folder to Eclipse

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.

like image 541
blue-sky Avatar asked Aug 29 '14 12:08

blue-sky


People also ask

How do I mark a folder as source in eclipse?

Right-click the folder, choose Build Path, then Use as Source Folder.

What is the difference between source folder and folder in eclipse?

A source folder is marked by Eclipse as containing java sources. Then, when you compile your project Eclipse will look for your source code into all your source folders. You can make any folder become a source folder adding it to the java build path.


1 Answers

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>
like image 71
Xstian Avatar answered Sep 21 '22 09:09

Xstian