简体   繁体   English

Maven 依赖项内的文件路径 jar

[英]Maven path to file inside a dependency jar

I have a maven plugin and I'd like to configure it by providing a path to a file/directory which is inside a dependency jar.我有一个 maven 插件,我想通过提供一个文件/目录的路径来配置它,该文件/目录位于依赖项 jar 内。

Here is a sample of my maven projects pom.xml.这是我的 maven 项目 pom.xml 的示例。 It has a plugin with a dependency which has a property as part of its execution called templateDirectory .它有一个带有依赖项的插件,该依赖项有一个属性作为其execution的一部分,称为templateDirectory I would like to put a path here to the plugins dependency mylang-swagger-codegen to a file/directory inside of the dependency { Some path }/src/resources/api/我想在此处放置插件依赖mylang-swagger-codegen的路径到依赖项内的文件/目录{ Some path }/src/resources/api/

How can I get to this path?我怎样才能到达这条路? I understand references like ${project.basedir} work to get to the project.我了解像${project.basedir}这样的参考资料可以进入项目。 Is there a way I can reference to the dependency and inside the jar to get to the file / directory I want?有没有办法可以引用依赖项并在 jar 内部访问我想要的文件/目录?

<plugin>
    <groupId>io.swagger</groupId>
        <artifactId>swagger-codegen-maven-plugin</artifactId>
        <version>2.4.19</version>
        <executions>
            <execution>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <inputSpec>${project.basedir}/api/swagger.yaml</inputSpec>
                    
                    <language>myLang</language>
      

        <templateDirectory>    <!-- Path here to api.mustache -->      </templateDirectory>
                    



            </execution>
        </executions>

        <dependencies>
            <dependency>
                <groupId>io.swagger</groupId>
                <artifactId>mylang-swagger-codegen</artifactId>
                <version>1.0.0</version>
            </dependency>
        </dependencies>
    </plugin>
</plugins>

Jar files are built on.zip. Jar 文件建立在.zip 上。 Maybe a Maven plugin that unwraps dependencies can help with what you want to accomplish.也许一个解开依赖关系的 Maven 插件可以帮助你完成你想要完成的事情。

Take a look at this to unpack a specific artifact: https://maven.apache.org/plugins/maven-dependency-plugin/examples/unpacking-artifacts.html看一下这个来解压一个特定的工件: https://maven.apache.org/plugins/maven-dependency-plugin/examples/unpacking-artifacts.ZFC35FDC70D5FC69D23EZ8C

Or this, to unpack the project dependencies: https://maven.apache.org/plugins/maven-dependency-plugin/examples/unpacking-project-dependencies.html或者这个,解压项目依赖: https://maven.apache.org/plugins/maven-dependency-plugin/examples/unpacking-project-dependencies.ZFC35FDC70D5FC69D75269883A8E

After running this plugin, you can access the path where you unpacked the jar.运行此插件后,您可以访问解压 jar 的路径。 In the examples above, the plugin runs in the "package" phase of maven.在上面的示例中,插件在 maven 的“打包”阶段运行。 If you want to change the order, take a look at the maven build phases: https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html If you want to change the order, take a look at the maven build phases: https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM