我一直在尝试读取存储在 target/generated-sources
文件夹中的 java 文件。为了存储这些文件,我在 pom.xml
文件中使用了以下插件
<!-- 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
下面的plguin中使用的这些文件
<!-- 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>
我尝试了多种方法从目标文件夹中读取这些文件,如下所示。但没有任何效果。
除了上述两个插件之外,我还使用 spring-boot-maven-plugin
sonar-maven-plugin
maven-surefire-plugin
>
最佳答案
https://www.benchresources.net/jaxb-a-xml-parsing-technique/
生成文件后,在 Eclipse 的类路径下添加 generated/java/source 文件夹。
关于java - 如何在Spring Boot中从目标文件夹读取java文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60448794/