<i id='UX4wT'><tr id='UX4wT'><dt id='UX4wT'><q id='UX4wT'><span id='UX4wT'><b id='UX4wT'><form id='UX4wT'><ins id='UX4wT'></ins><ul id='UX4wT'></ul><sub id='UX4wT'></sub></form><legend id='UX4wT'></legend><bdo id='UX4wT'><pre id='UX4wT'><center id='UX4wT'></center></pre></bdo></b><th id='UX4wT'></th></span></q></dt></tr></i><div id='UX4wT'><tfoot id='UX4wT'></tfoot><dl id='UX4wT'><fieldset id='UX4wT'></fieldset></dl></div>

    1. <tfoot id='UX4wT'></tfoot>
    2. <legend id='UX4wT'><style id='UX4wT'><dir id='UX4wT'><q id='UX4wT'></q></dir></style></legend>

      <small id='UX4wT'></small><noframes id='UX4wT'>

        <bdo id='UX4wT'></bdo><ul id='UX4wT'></ul>
    3. 自定义插件无法从 jar 复制文件,因为协议是“jar";

      Custom plugin can#39;t copy files from jar because protocol is quot;jarquot;(自定义插件无法从 jar 复制文件,因为协议是“jar;)
        <legend id='EFGcE'><style id='EFGcE'><dir id='EFGcE'><q id='EFGcE'></q></dir></style></legend>

        • <bdo id='EFGcE'></bdo><ul id='EFGcE'></ul>

          <small id='EFGcE'></small><noframes id='EFGcE'>

                <i id='EFGcE'><tr id='EFGcE'><dt id='EFGcE'><q id='EFGcE'><span id='EFGcE'><b id='EFGcE'><form id='EFGcE'><ins id='EFGcE'></ins><ul id='EFGcE'></ul><sub id='EFGcE'></sub></form><legend id='EFGcE'></legend><bdo id='EFGcE'><pre id='EFGcE'><center id='EFGcE'></center></pre></bdo></b><th id='EFGcE'></th></span></q></dt></tr></i><div id='EFGcE'><tfoot id='EFGcE'></tfoot><dl id='EFGcE'><fieldset id='EFGcE'></fieldset></dl></div>
                  <tbody id='EFGcE'></tbody>

                <tfoot id='EFGcE'></tfoot>
                本文介绍了自定义插件无法从 jar 复制文件,因为协议是“jar";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在为 SonarQube 开发一个插件,它必须做的一部分是将文件从自身复制到 SonarQube 服务器的目录.我正在使用 Apache Commons IO,并且发现 FileUtils.copyDirectory 工作得非常好(在使用 main 方法对其进行测试之后).
                麻烦来自试图从插件本身的 jar 中获取我想要复制的文件目录.我试过这个:

                I am developing a plugin for SonarQube, and part of what it must do is copy files from itself to the SonarQube Server's directory. I am using Apache Commons IO, and have found that FileUtils.copyDirectory works wonderfully (after testing it with a main method).
                The trouble comes from trying to get the directory of files that I want to copy from the jar of the plugin itself. I have tried this:

                public File getSrcDir() {
                    URL inputUrl = getClass().getResource("/images");
                    File srcDir = FileUtils.toFile(inputUrl);
                    System.out.println(srcDir);
                    return srcDir;
                }
                

                当我在 IDE (Eclipse) 的 main 方法中运行它时,它会打印出 C:...[Project Directory] argetclassesimages但是,当我将插件作为 Sonar 的插件"文件夹中的 jar 文件夹安装到 SonarQube 中时,此方法会打印出 null.
                我调查发现 FileUtils.toFile(URL url) 如果 url 参数的协议不是文件",则将返回 null.所以我在我的方法中添加了这一行:System.out.println(inputUrl.getProtocol());
                果然,在我的IDE中,协议是文件",但是当我安装插件时,协议是jar"!

                我花了最后一天倾注于 Stack Overflow 和 Google 试图找到解决此问题的方法,但无济于事.

                我愿意尝试/重构任何东西.

                我要做的就是让我的插件将其 jar 中的目录复制到 SonarQube 的服务器.
                我该怎么做?

                如果相关,这是我项目中的目录(我想复制图像"文件夹及其中的所有内容):

                When I run it in a main method in my IDE (Eclipse), it prints out C:...[Project Directory] argetclassesimages But when I install the plugin into SonarQube as a jar folder in Sonar's "plugins" folder, this method prints out null.
                I investigated and found that FileUtils.toFile(URL url) will return null if the url argument has a protocol other than "File". So I added this line to my method: System.out.println(inputUrl.getProtocol());
                Sure enough, in my IDE the protocol is "file", but when my plugin is installed the protocol is "jar"!

                I have spent the last day pouring over Stack Overflow and Google trying to find a way to deal with this, but to no avail.

                I am willing to try/refactor anything.

                All I want to do is make it so that my plugin copies a directory from within its jar to SonarQube's Server.
                How can I do this?

                In case it's relevant, here is the directory within my project (I want to copy the "images" folder and everything in it):

                [Project Directory]
                    |
                    +--/src/main/resources
                            |
                            +--images
                                 |
                                 +--profiles
                                          |
                                          +--awards
                                          |    |
                                          |    +--Award1.png
                                          |    |
                                          |    +--Award2.png
                                          |
                                          +--projects
                                               |
                                               +--default.png
                

                这里是 SonarQube 服务器中要复制到的目录:[SONARQUBE_HOME]/war/sonar-server/images

                And here is the directory to copy to in the SonarQube server: [SONARQUBE_HOME]/war/sonar-server/images

                推荐答案

                当classpath中的资源(这里是图片或目录)来自jar时,不再是物理文件

                When resource (in this case images or directory) in classpath coming from jar, it is no longer a physical file

                您需要修改代码,使其从 Stream 而不是 File

                You need to modify the code so that it reads those resources from Stream instead of File

                • 如何从
                • 从类路径目录中获取资源列表

                这篇关于自定义插件无法从 jar 复制文件,因为协议是“jar";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Slf4j LoggerFactory.getLogger and sonarqube(Slf4j LoggerFactory.getLogger 和 sonarqube)
                Security - Array is stored directly(安全性 - 数组直接存储)
                SonarQube quot;Class Not Foundquot; during Main AST Scan(SonarQube“找不到类在主 AST 扫描期间)
                Integrate Spock#39;s test with Sonar(将 Spock 的测试与声纳集成)
                How do I make Hudson/Jenkins fail if Sonar thresholds are breached?(如果违反声纳阈值,我如何让 Hudson/Jenkins 失败?)
                automatically add curly brackets to all if/else/for/while etc. in a java code-base(自动将大括号添加到 java 代码库中的所有 if/else/for/while 等)

                  <bdo id='rRAXN'></bdo><ul id='rRAXN'></ul>
                • <legend id='rRAXN'><style id='rRAXN'><dir id='rRAXN'><q id='rRAXN'></q></dir></style></legend>

                  <small id='rRAXN'></small><noframes id='rRAXN'>

                • <tfoot id='rRAXN'></tfoot>
                  <i id='rRAXN'><tr id='rRAXN'><dt id='rRAXN'><q id='rRAXN'><span id='rRAXN'><b id='rRAXN'><form id='rRAXN'><ins id='rRAXN'></ins><ul id='rRAXN'></ul><sub id='rRAXN'></sub></form><legend id='rRAXN'></legend><bdo id='rRAXN'><pre id='rRAXN'><center id='rRAXN'></center></pre></bdo></b><th id='rRAXN'></th></span></q></dt></tr></i><div id='rRAXN'><tfoot id='rRAXN'></tfoot><dl id='rRAXN'><fieldset id='rRAXN'></fieldset></dl></div>

                            <tbody id='rRAXN'></tbody>