How to read java files from target folder in spring boot

爷,独闯天下 提交于 2021-01-29 14:52:38

问题


I've been trying to read java files that are stored inside target/generated-sources folder. To store these files I have used below plugin in pom.xml file

<!-- For Code Generation -->
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.12.3</version>
                <executions>
                    <execution>
                        <id>add-source-for-demoapp</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <schemaDirectory>src/main/resources/xsd</schemaDirectory>
                            <schemaIncludes>
                                <include>myschema.xsd</include>
                            </schemaIncludes>
                            <generateDirectory>target/generated-sources/xjc/workflow</generateDirectory>
                            <generatePackage>com.websystique.xml.workflow</generatePackage>
                            <!-- For including equals,hashcode and toString methods in generated code -->
                            <plugins>
                                <plugin>
                                    <groupId>org.jvnet.jaxb2_commons</groupId>
                                    <artifactId>jaxb2-basics</artifactId>
                                    <version>0.9.4</version>
                                </plugin>
                            </plugins>
                            <args>
                                <arg>-Xequals</arg>
                                <arg>-XhashCode</arg>
                                <arg>-XtoString</arg>
                            </args>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Now this plugin generated few java files and to access those file I have used below plguin inside pom.xml

<!-- For Adding Generated code directory as source folder -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.9</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${basedir}/target/generated-sources/xjc/workflow/com.websystique.xml.workflow</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

I have tried several ways to read these files from target folder as shown below. But nothing is working.

Apart from above 2 plugins I'm also using spring-boot-maven-plugin sonar-maven-plugin maven-surefire-plugin


回答1:


https://www.benchresources.net/jaxb-a-xml-parsing-technique/

Once files are generated then add generated/java/source folder under classpath in eclipse.



来源:https://stackoverflow.com/questions/60448794/how-to-read-java-files-from-target-folder-in-spring-boot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!