gpt4 book ai didi

java - 从包含 WAR 文件的 EAR 文件中读取属性

转载 作者:行者123 更新时间:2023-12-01 10:55:04 27 4
gpt4 key购买 nike

我的属性文件有一个小问题。我使用 maven 生成一个 dependency-tree.txt 文件并将其存储在我的 EAR 文件中

EAR
/META-INF
dependency-tree.txt
/lib
some libs
restservice.war

现在我想使用 REST 服务显示 dependency-tree.txt 文件。我在restservice.war中开发了REST端点。

我可以访问存储在 war 文件外部但ear 文件内的 dependency-tree.txt 文件吗?

这个 REST 端点的原因是,我们想为测试团队提供一个接口(interface)。通过这种方法,我们可以描述部署的 Artifact ,而无需任何手动步骤。

或者有人可以为我提供更好的解决方案吗?

谢谢

最佳答案

The idea is to run the plugin maven-dependency-plugin:tree at validate phase (1 phase in maven Lifecycle ) , and copy the file (tree.txt) to the right place for your WAR that after the generation of the war / ear, the file must be in the right place to be deploy a REST service.

<build>
<pluginManagement>
<plugins>
<plugin>
<!-- because we will use the plugin org.apache.maven.plugins at validate
phase, for Eclipse is happy , we'll ignore here -->
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[2.10,)</versionRange>
<goals>
<goal>tree</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution> <!-- -->
<id>generateTree</id>
<phase>validate</phase> <!-- You can change it , if you put 'test' , you can delete <pluginManagement> -->
<goals>
<goal>tree</goal>
</goals>
<configuration>
<outputFile>src/main/resources/tree_rest_access.txt</outputFile>
<!-- change location, exemple : you can use => restservice/src/main/webapp/tree/rest
, and expose from controller "tree/rest/tree_rest_access.txt" -->
</configuration>
</execution>
</executions>
</plugin>

关于java - 从包含 WAR 文件的 EAR 文件中读取属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33650849/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com