简体   繁体   English

如何在EAR中打包属性文件和JAR?

[英]How to package a properties file and JAR inside an EAR?

I'm made a Java application that access a web service, gets data, and updates a properties file once, in order to do all it's operations (the app does not access the web service after this call, and keeps it in the properties file instead). 我已经制作了一个Java应用程序,它可以访问Web服务,获取数据并一次更新属性文件,以便执行其所有操作(此调用后,该应用程序不访问Web服务,并将其保存在属性文件中代替)。 It has been planned that this app must be deployed in a Websphere Application Server (WAS), so I want to put the JAR file and the properties file inside an EAR file, assuming that when it is deployed, the JAR and properties file will be inside the same path in the server. 已经计划必须将此应用程序部署在Websphere Application Server(WAS)中,因此我想将JAR文件和属性文件放在EAR文件中,假设在部署时,JAR和属性文件将是在服务器的同一路径内。

Is there some way I can package the EAR so both the JAR and the properties file are together? 有什么方法可以打包EAR,以便JAR和属性文件都在一起?

This can be achieved, I do not see any problems here. 这可以实现,我在这里看不到任何问题。 Do as below: 执行以下操作:

Package the properties file in the jar and then bundle the jar in the ear . properties文件打包到jar ,然后将jar捆绑在ear

Using ant you can build the jar with the below command: 使用ant可以使用以下命令构建jar:

<target name="jarx.jar">
    <jar destfile="${dist.dir}/jarx.jar">
        <fileset dir="${classes.dir}">
            <include name="**/*.*"/>
        </fileset>
    </jar>
</target>

How to access the properties file later? 以后如何访问属性文件?

If you want to access the properties file later from any class ClassX, you can simply write 如果您以后想从任何ClassX访问属性文件,只需编写

InputStream is = ClassX.getResourceAsStream('/abc.properties');

EDIT: 编辑:

The second part of the question is already answered here . 问题的第二部分已经在这里回答。 But I would not advice it because the changes might not immediately reflect or get loaded, without a server start. 但是我不建议这样做,因为如果没有启动服务器,更改可能不会立即反映出来或被加载。 Not sure on this point. 在这一点上不确定。

Also, you need to evaluate what if the jar is a sealed one? 另外,如果罐子是密封罐,您需要评估该怎么办?

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

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