Results 1 to 3 of 3

Thread: [RESOLVED] How do I copy a file using Maven and specify the first module as the target folder?

  1. #1

    Thread Starter
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,836

    Resolved [RESOLVED] How do I copy a file using Maven and specify the first module as the target folder?

    There's more to it that the simple question in the subject. I've looked at the suggested links of "similar questions" and none of them completely helped.

    BACKGROUND: Building a plugin system for an application. Part of that will require other teams to build the plugins themselves. The structure of each plugin that's built has a reactor project with two modules, one of which gets merged into the other using the shade plugin. This results in a single jar file that gets created in the target folder of one of the modules. That all works great. Because we have some things that all plugins are going to need (settings, structure, dependencies) we've built another project project-plugin-parent with only a POM that contains all of the common referenced and dependencies. Each plugin is then to reference this parent POM for all the common items, so that the devs don't need to worry about it. One of the parameters that's passed to the util is the jar file.

    As part of that POM, we've got some utilities that we're marking as dependencies, which then get copied to a local utils folder. After that utility is downloaded, we then run it (depending on the profile that's used) ... In order to run it, it needs to be discoverable. When I put the dependency and the copy commands into the POM of the plugin (first module), it works great. But we want it to actually be in the project-plugin-parent POM... This puts the utils folder in the reactor's folder... OK, I can work with that. The problem happens when it then tries to run the utility... because it's in the parent POM, it tries to run it from there and so incorrectly passes the wrong jar file in the parameters.

    OK, so here's what the structure looks like

    Code:
    project-plugin-parent.pom
    
    plugin-project-reactor (with dependency on project-plugin-parent.pom
    |
    |-- plugin-project-main
    |
    \-- plugin-second
    I'd prefer if the util ended up inside of plugin-project-main... but if it ends up in the reactor structure that's fine. Somehow I need to be able to get to the folder/jar of the plugin-project-main. At the same time, I can't simply hard code the folder name as it will vary form project to project.

    In the proect-plugin-parent, here's the configuration node for the maven copy command.

    Code:
    <configuration>
      <artifactItems>
          <artifactItem>
              <groupId>gov.va.bip.docgen</groupId>
              <artifactId>my-project-svc-rest</artifactId>
              <version>1.0.0</version>
              <type>jar</type>
              <destFileName>my-service.jar</destFileName>
          </artifactItem>
      </artifactItems>
      <outputDirectory>${project.build.directory}/../utils</outputDirectory>
    </configuration>
    This will successfully download the file from nexus an copy it to a utils folder inside the reactor level. Again, I'd prefer it went into the main plugin folder instead.

    Here's the exec of that downloaded jar:

    Code:
                            <configuration>
                                <executable>java</executable>
                                <arguments>
                                    <argument>-Dloader.path=${project.build.directory}/${project.build.finalName}/${artifactId}.jar</argument>
                                    <argument>-Dserver.port=10080</argument>
                                    <argument>-jar</argument>
                                    <argument>${project.build.directory}/../utils/my-service.jar</argument>
                                </arguments>
                                <includeProjectDependencies>false</includeProjectDependencies>
                            </configuration>
    You can see we're passing in a path to the plugin's jar, which is in plugin-project-main/target ... With the above configuration I'm getting a reference to the reactor's jar instead (which doesn't exist).

    So is there a way to dynamically get that folder of the main module in the reactor? If I can get that, then I can either put the utils into the module's folder (preferred) or at least pass the correct path to the util when it gets executed.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  2. #2

    Thread Starter
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,836

    Re: How do I copy a file using Maven and specify the first module as the target folde

    Figured it out...
    By using an activation with a file exists entry I was able to get it to only run the profile on the module I wanted it (the folder in question will only ever exist in that module's structure).

    I then ran into a problem where it was being activated on a simple mvn clean install command... something I didn't want. So I added a property setting to the activaiton.
    Code:
                <activation>
                    <activeByDefault>false</activeByDefault>
                    <property>
                        <name>run-service</name>
                    </property>
                    <file>
                        <exists>
                            target/classes/content-root
                        </exists>
                    </file>
                </activation>
    Now when I do a mvn clean install it doesn't run. To activate it, I use mvn install -Drun-service
    Works like a champ!

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Lively Member
    Join Date
    Jan 2020
    Posts
    81

    Re: [RESOLVED] How do I copy a file using Maven and specify the first module as the t

    <configuration>
    <artifactItems>
    <artifactItem>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>3.8.1</version>
    <type>jar</type>
    <overWrite>false</overWrite>
    <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
    <destFileName>optional-new-name.jar</destFileName>
    </artifactItem>
    </artifactItems>
    <outputDirectory>${project.build.directory}/wars</outputDirectory>
    <overWriteReleases>false</overWriteReleases>
    <overWriteSnapshots>true</overWriteSnapshots>
    </configuration>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width