如何在 spring 引导中从目标文件夹读取 java 文件
How to read java files from target folder in spring boot
我一直在尝试读取存储在 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 文件夹。
我一直在尝试读取存储在 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
<!-- 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 文件夹。