如何使用 JBoss 以编程方式获取当前 EAR 位置
有谁知道如何以编程方式从同一 EAR 中的 Java 代码获取部署在 JBoss 中的 EAR 文件系统中的绝对路径?
我需要这个,因为我想在部署时将 EAR 内的一些文件复制到文件系统的另一部分。
谢谢大家!
Does anyone know how to get programmatically the absolute path in the filesystem for an EAR deployed in JBoss, from Java code within that same EAR?
I need this because I want to copy some files that are inside the EAR to another part of the filesystem, on deploy-time.
Thank you everyone!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以执行“System.getProperty()”,这里是您可以获取的其他属性的链接使用
ex:
result
之后您只需添加
"/deployments/YOUR_PROJECT_EAR/..."
you can do you "System.getProperty()" here is the link for other the properties you can used
ex:
result
After you just need to add
"/deployments/YOUR_PROJECT_EAR/..."
我就是这样做的。
EAR 有一个服务 MyService,我可以在其中处理 EAR 内容:
I do this way.
EAR has a service MyService, where I work with EAR contents:
要从 Seam 获取
ServletContext
,您可以执行以下操作:一旦 Seam 创建了
applicationContext
,该操作就可用。 然后getRealPath("/")
对于根上下文的部署文件夹来说效果很好。 可以访问上下文根中的任何文件夹结构。To get the
ServletContext
from Seam, you can do:which is available as soon as Seam has created the
applicationContext
. And thengetRealPath("/")
works fine for root context's deployment folder. Any folder structure within context root can be reached.这相当繁琐,但您可以通过查询 JBoss
MainDeployer
MBean 来完成此操作。 MBean 可在jboss.system:service=MainDeployer
中找到,并且具有 JMX 操作listDeployments
。 这将返回 DeploymentInfo 对象的集合,其中之一将是您的 EAR 部署。 该 DeploymentInfo 有一个url
属性,它是描述您的部署目录的file://
URL。很好,嗯? 您可以使用原始 JMX API 来执行此操作,但 Spring 提供了更好的机制,使用
MBeanProxyFactoryBean
公开MainDeployerMBean
的实例。我想找到一种更简单的方法,但这是迄今为止我发现的最好的方法。
This is quite fiddly, but you can do this by querying the JBoss
MainDeployer
MBean. The MBean is found atjboss.system:service=MainDeployer
, and has a JMX operationlistDeployments
. This returns a collection ofDeploymentInfo
objects, one of which will be your EAR deployment. That DeploymentInfo has aurl
property which is afile://
URL describing your deployment directory.Nice, eh? You can use the raw JMX API to do this, but Spring provides a much nicer mechanism, using a
MBeanProxyFactoryBean
to expose an instance ofMainDeployerMBean
.I'd like to find a simpler way, but that's the best I've found so far.
这些资源是否在 Web 路径下(在 WAR 内)映射或可用?
如果是这样,您可以尝试使用
ServletContext.getRealPath()
将虚拟路径转换为真实/文件系统路径。Are these resources mapped or made available under a web path (within a WAR)?
If so, you could attempt to use
ServletContext.getRealPath()
to translate the virtual path to the real/filesystem path.