简体   繁体   English

Linux覆盖Java资源文件

[英]Linux Overwrite Java Resource file

I want to overwrite a quartz-jobs.xml file I have in a WAR deployed in JBOSS under a Linux x86 machine. 我想覆盖在Linux x86机器下部署在JBOSS中的WAR中的quartz-jobs.xml文件。

I have tried several things but I have not been able to obtain the correct path to do it properly: 我尝试了几件事,但是我无法正确地找到正确的道路:

Error writing: /content/ThisIsMyWar.war/WEB-INF/classes/quartz-jobs.xml (No such file or directory) 写错误: /content/ThisIsMyWar.war/WEB-INF/classes/quartz-jobs.xml (没有这样的文件或目录)

Currently, the code is as this (but I have tried some more things without success): 目前,代码是这样的(但我已经尝试了一些没有成功的事情):

String urlPath = null;
            String filePath = null;
            final URL url = classLoader.getResource("quartz-jobs.xml");
            if (url != null) {
                urlPath = URLDecoder.decode(url.getPath(), "UTF-8");
            }
            if (urlPath != null) {
                filePath = urlPath;
            } else {
                filePath = new File("quartz-jobs.xml").getAbsolutePath();
            }

            final File file = new File(filePath);
            LOG.warn(String.format("File %s absolute: %s", url.getPath(), file.getAbsolutePath()));
            LOG.warn(String.format("File canonical: %s", file.getCanonicalPath()));

            writer = new BufferedWriter(new FileWriter(file));
            writer.write(newQuartzJobsXml);

Is it possible to overwrite the XML resource in Linux ? 是否可以在Linux中覆盖XML资源?

Thanks in advance 提前致谢

The reason why its not working is because you are modifying resource read from classLoader. 它无法工作的原因是因为您正在修改从classLoader读取的资源。 This wont modify war's resource entry. 这不会修改war的资源条目。

You can update war by using standard java command "jar uf" ( http://docs.oracle.com/javase/tutorial/deployment/jar/update.html ) 您可以使用标准java命令“jar uf”更新war( http://docs.oracle.com/javase/tutorial/deployment/jar/update.html

Steps for this can be: 步骤可以是:

  1. Keep the modified "quartz-jobs.xml" in same directory where target-war is. 将修改后的“quartz-jobs.xml”保存在target-war所在的目录中。

  2. Create an executor (quartz_updader.sh) and add commands for going to right directory and updating jar: 创建一个执行程序(quartz_updader.sh)并添加用于转到正确目录和更新jar的命令:

    cd #director-where-war-and-updated-xml-reside cd#director-where-war-and-updated-xml-reside

    jar uf #target-war quartz-jobs.xml jar uf#target-war quartz-jobs.xml

  3. Give right permissions to (quartz_updader.sh) for execution. 授予(quartz_updader.sh)执行权限。

  4. Execute the .sh from java using Runtime.getRuntime().exec( command ) where command=sudo ./quartz_updader.sh 使用Runtime.getRuntime()。exec(command)从java执行.sh其中command = sudo ./quartz_updader.sh

Above was on assumption "quartz-jobs.xml" is directly under war instead of some relative location. 以上是假设“quartz-jobs.xml”直接在战争中而不是某些相对位置。 If it is in relative location, modify above approach to: 如果它位于相对位置,请修改上述方法:

  • create #relative-location# hierarchy next to #target-war and keep new "quartz-jobs.xml" under it. 在#target-war旁边创建#relative-location#hierarchy,并在其下面保留新的“quartz-jobs.xml”。
  • Modify the .sh file jar update command: jar uf #target-war #relative-loc/quartz-jobs.xml 修改.sh文件jar更新命令:jar uf#target-war#relative-loc / quartz-jobs.xml

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

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