boot中从目标文件夹读取java文件

boot中从目标文件夹读取java文件

本文介绍了如何在spring boot中从目标文件夹读取java文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试读取存储在 target/generated-sources 文件夹中的 java 文件.为了存储这些文件,我在 pom.xml 文件中使用了下面的插件

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>

现在这个插件生成了几个java文件并访问我在pom.xml

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.

除了以上 2 个插件,我还使用了 spring-boot-maven-plugin sonar-maven-plugin maven-surefire-plugin

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

推荐答案

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

生成文件后,在eclipse中的classpath下添加generated/java/source文件夹.

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

这篇关于如何在spring boot中从目标文件夹读取java文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 05:25