【问题标题】:Maven project pom sourceDirectory as method parameterMaven 项目 pom sourceDirectory 作为方法参数
【发布时间】:2016-12-15 19:17:18
【问题描述】:

我正在研究一个自动生成类,它从给定的模式生成 jsonObjects。这个想法是有一个包含所有模式的文件夹,然后能够根据需要浏览所有模式和过程。我的问题是如何将 pom 中定义的 sourceDirectory 作为参数传入。以及如何访问 outputDirectory 。 例如,我有一个这样的类

public void generateJSONOrder() throws JSONException, IOException
{
    File folder = <sourceDirecotry>; // how do I get this ?
    // other code here and then write output
    FileWriter fileWriter = new FileWriter(new File(<outputDirectory>)); //how to get this too?

}

【问题讨论】:

标签: java rest api maven pom.xml


【解决方案1】:

您可以使用properties-maven-plugin,然后使用以下任何选项 访问代码中的值

  1. 设置系统属性
  2. 写入属性文件

像这样的。

   <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0.0</version>
    <executions>
        <execution>
            <goals>
                <goal>set-system-properties</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
                <properties>
                    <property>
                        <name>schemaSourceDirectory</name>
                        <value>\pathToSchema</value>
                    </property>
                </properties>
            </configuration>
        </execution>
    </executions>
</plugin>

只需使用 maven 工具 jsonschema2pojo 从 JSON Schema 生成 Java 类型,使用此工具您可以指定 sourceDirectorytargetPackage

【讨论】:

  • 我已经有了。我正在尝试定义自己的,但将 作为参数传入
  • 比你可以使用 properties-maven-plugin
猜你喜欢
  • 1970-01-01
  • 2017-02-23
  • 2023-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-30
  • 1970-01-01
  • 2015-11-07
相关资源
最近更新 更多