我的属性文件有一个小问题。我用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端点的原因是,我们希望为测试团队提供一个接口。使用这种方法,我们可以描述部署的工件,而不需要任何手动步骤。
或者有人给我更好的解决方案?
谢谢
发布于 2015-11-11 21:23:22
插件maven -
- plugin :tree的想法是在验证阶段(maven生命周期的1个阶段)运行树,并将文件(tree.txt)复制到WAR的正确位置,这样在war / ear生成后,文件必须位于正确的位置才能部署REST服务。
<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>发布于 2015-11-11 21:36:07
你为什么要把它放在耳朵里!?EAR通常应该只包含WAR,如果您的服务器需要的话,还应该包含另一个部署文件(例如jboss- deployment -structure.xml )。EAR是将几个模块打包在一起的包装器,没有别的。
如果您有REST端点,并且希望它从项目中回馈资源,则可以通过将资源放入项目中来实现这一点。通过在加载资源时使用相对路径,可以很容易地配置在项目根目录中创建文件并从那里读取它。更好的解决方案是明确定义存储此文件的外部位置,使此位置在某些应用程序config.properties文件中可配置。在这种情况下,所有开发人员只需在各自的配置中设置此路径即可。
https://stackoverflow.com/questions/33650849
复制相似问题