Maven, transfer of resources from jar to external



  • There is a project with internal resources and a maven collector, whether it is possible to make two sets of one project, one with jar file resources, and the other to make resources in a separate folder. resourcesin the same catalogue where jar file is stored?

    Mandatory condition, the second assembly was fully operational and used external resources.

    Edit:

    Director:

     - target
        |_ test.jar
        |_ externalResources
           |_ text.txt
    

    I've done it in pom.xml:

           <resources>
               <resource>
                   <directory>${basedir}/externalResources</directory>
               </resource>
           </resources>
    
       &lt;plugin&gt;
            &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
            &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
            &lt;version&gt;2.4&lt;/version&gt;
            &lt;configuration&gt;
                &lt;archive&gt;
                    &lt;manifest&gt;
                        &lt;mainClass&gt;com.TestMain&lt;/mainClass&gt;
                    &lt;/manifest&gt;
                    &lt;manifestEntries&gt;
                        &lt;Class-Path&gt;externalResources/&lt;/Class-Path&gt;
                    &lt;/manifestEntries&gt;
                &lt;/archive&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;
            &lt;!-- Копирование в папку target файлы из resources в externalResources --&gt;
        &lt;plugin&gt;
            &lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt;
            &lt;version&gt;2.6&lt;/version&gt;
            &lt;executions&gt;
                &lt;execution&gt;
                    &lt;id&gt;copy-resources-1&lt;/id&gt;
                    &lt;phase&gt;validate&lt;/phase&gt;
                    &lt;goals&gt;
                        &lt;goal&gt;copy-resources&lt;/goal&gt;
                    &lt;/goals&gt;
                    &lt;configuration&gt;
                        &lt;outputDirectory&gt;${basedir}/target/resources/&lt;/outputDirectory&gt;
                        &lt;resources&gt;
                            &lt;resource&gt;
                                &lt;directory&gt;src/main/externalResources&lt;/directory&gt;
                                &lt;filtering&gt;true&lt;/filtering&gt;
                            &lt;/resource&gt;
                        &lt;/resources&gt;
                    &lt;/configuration&gt;
                &lt;/execution&gt;
            &lt;/executions&gt;
        &lt;/plugin&gt;
    

    Resource challenge ClassLoader.getSystemResource("text.txt").getPath();but the resource can't be found.



  • It's pretty simple. You do two profiles. One with standard configurations, the other you do about that.

    <build>
       ...
       <resources>
         <resource>
           <directory>[пустая_дирректороия]</directory>
         </resource>
       </resources>
       ...
     </build>
    

    After that, the jar'nik that was collected under the second profile, you're gonna have to start with an additional option like this: java -cp "./externalResource" -jar myJar.jarwhere ./externalResource - the way to the folder with your external resources, and myJar.jar Your final jar'nick.


    UPDATE

    Once upon a time, I forgot about the downloading policy. But there's still a solution. We need to download resources through an empty class that will be present in several jar'niks. In the end, we'll have to collect a project excluding this class from all jar'niks except one. I've actually gathered a simple one. http://my-files.ru/Save/q4em2q/questions-475880.zip ♪ There is a root run.sh/run.bat to demonstrate.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2