2

Suppose I have a set of n Java libraries each with a conf and a resources folder and then I have a Java project X that depends on some of these n Java libraries, how do I make it so that when X is built, all the dependent conf and resources folders are copied and merged in the dist folder. No - I don't want them to be embedded in the jars.

Obviously, there will be issues with duplicate filenames, but let's assume all files have distinct names.

Edit: An additional and related question: How do it so that project X can detect the conf and resources during development phase of all the dependent projects without needing to copy them over to project X's folder. For example, I'd like Netbeans to be able to find these resources that the referenced libraries use when I click "Run" on X's main method.

Edit2: Here's a hypothetical example of a project setup:

**Library 1:** Image Processing

conf: Processing configurations, log4j
resources: Training sets, etc.

**Library 2:** Machine Learning

conf: Training parameters, log4j
resources: Dependent C++ batch files (i.e. system calls)

**Library 3:** Reporting Tool

resources: Reporting templates

**Library 4:** Text Mining Toolkit

conf: Encoding, character sets, heuristics
resources: Helper PHP scripts

**Executable Project 1: **

Uses Library 1 to process images 
Uses Library 2 to do machine learning on processed images
Uses Library 3 to make reports

**Executable Project 2: **

Uses Library 4 to do text mining
Uses Library 2 to do machine learning on collected textual information
Uses Library 3 to make reports

We can assume Executable Projects 1 and 2 can use different parameters for their constituent libraries once deployed.

Some Newbie
  • 1,059
  • 3
  • 14
  • 33
  • Like execellent Khmarbaise answer, I would recommended the way he pointed out. Take a look here, this is quite the same needs : http://stackoverflow.com/questions/12298178/maven-depend-on-assembled-zip/12299646#12299646 – Jean-Rémy Revy Sep 20 '12 at 07:40

2 Answers2

2

Take a look at the maven-dependency-plugin which can copy the deps and copy them to particular location.

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.5.1</version>
        <executions>
          <execution>
            <id>copy</id>
            <phase>package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <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>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • A second question would be: How do I tell Maven that each project is dependent on a conf and a resource folder? To keep them external to the jar, I put them at the root folder of the project. I am using Netbeans btw, which doesn't have that nifty GUI for pom.xml. :/ – Some Newbie Sep 19 '12 at 18:35
  • Are you talking about non jar dependencies which means to have folder? Than this won't work. Are these projects located within a multi-module build? Usually you work with dependencies (binary kind of like a jar file which can contain a propertey file). – khmarbaise Sep 19 '12 at 18:37
  • Yes, non-jar dependencies. No, these are separate projects. – Some Newbie Sep 19 '12 at 18:41
  • Than there is no good way to do so. Maven is not intended to do such things. – khmarbaise Sep 19 '12 at 18:49
  • Well then how should I be doing things? – Some Newbie Sep 19 '12 at 18:52
  • Can you give an example of those library and why you need the conf files within other projects instead of the jar dependencies..Are those projects/libraries related to each other? – khmarbaise Sep 19 '12 at 18:54
2

I see the following in your example. Let me use Library 1 as an example.

Library 1: Image Processing

conf: Processing configurations, log4j resources: Training sets, etc.

You have library 1 which contains processing configuration which sounds to me like a runtime configuration. This mean it should be part of the created jar (src/main/resources the location for such things). The same is for log4j configuration. Just put it into the jar (src/main/resources of the project.

Now comming to resources: Training set. If you make a separate maven project which contains a training set so this will produce a single artifact and can later be used to integrate that into the Example 1. If you have several training sets you can create different artifacts and use them as usual dependency or use the maven-dependency-plugin (or may be the maven-remote-resources-plugin) to use them in your projects.

With this setup you can deploy Library 1 into your local repository and of course into a repository manager and use it as a dependency.

You can use the same approach to handle Library 2, 3 etc.

May be you can take a look at the maven-remote-resource-plugin (I'm not sure if this helps).

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Thanks for the responses. A question that lingers in my mind is that if say there are several of these libraries, then each of these libraries have to be deployed manually. – Some Newbie Sep 19 '12 at 19:28
  • Usually you deploy via maven only once during a release (or maybe several times via *mvn deploy* a SNAPSHOT version into your local repository). Or did i miss something ? – khmarbaise Sep 19 '12 at 19:32
  • No, I am just commenting on the issue that Libraries 1-3 have to each be separately deployed to the target folder along with Executable Project 1, which is also deployed separately. – Some Newbie Sep 19 '12 at 19:58