0

I have following maven projects (note : maven project, not maven modules). I know i will get questions, why not modules, but it has its own story, anyway.

myproj-common (JAR), myproj-core (JAR), myproj-product1-batch (EAR), myproj-product2-batch (EAR)

myproj-core depends on myproj-common, and myproj-product1-batch depends on myproj-core. If it is modules, i can simply create dependency. It if is standard archive, I can also create dependency and have JAR available in repository, if it is a library JAR, I can ...bla bla bla ...all standard dependency I can fix, I am not sure how to make a jar that is sitting somewhere on the disk, a dependency.

I am not able to get
C:\Documents and Settings\users\myproj-common\target\myproj-common-0.0.1-SNAPSHOT.jar
into following jar, as a dependency
C:\Documents and Settings\users\myproj-core\target\myproj-core-0.0.1-SNAPSHOT.jar

same problem for the JAR into EARs.

Any idea ? How ...hoping a small, quick and surprising fix, just not visible to me.

Shmil The Cat
  • 4,548
  • 2
  • 28
  • 37

1 Answers1

0

I don't see any reason why you shouldn't be able to use mvn install to install these jars and ears into your local repository. Then, you can just include them as dependencies anywhere you like.

I doubt that you'll be able to cleanly get maven to pull in a jar sitting anywhere on your filesystem other than your local repository.

To clarify, when you do mvn install it puts your JAR in the target folder, but it also puts it into your local repository (C:\Documents And Settings\.m2 by default in Windows). After that JAR is installed there, you can include that JAR in other projects as a maven dependency using a "dependencies" block in your pom like this:

<dependencies>
    <dependency>
      <groupId>group-a</groupId>
      <artifactId>artifact-a</artifactId>
      <version>1.0</version>
    </dependency>
</dependencies>

The dependencies mechanism is explained in the Maven Docs.

In addition, you'll need to tell maven to actually package all dependencies in the JAR. You can do that by adding this to your POM. (Also check this question How can I create an executable JAR with dependencies using Maven? for the source of this code block).

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <configuration>
     <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
  </configuration>
  <executions>
    <execution>
      <id>make-assembly</id> <!-- this is used for inheritance merges -->
      <phase>package</phase> <!-- bind to the packaging phase -->
      <goals>
        <goal>single</goal>
      </goals>
    </execution>
  </executions>
</plugin>
Community
  • 1
  • 1
Jon7
  • 7,165
  • 2
  • 33
  • 39
  • When I run mvn install, it produces JARs into target folders, but I can't get common jar included into core jar. I thought there is a way to get JARs from anywhere on the system, in this case in the target folder of another maven project. Also, when you said install into local repository, i did not get that part, all i have in my loacl repo are JARS they are downloaded after i put in dependency. – questionaire Apr 08 '13 at 18:10
  • This is my pom content from core


    com.myorg.myproj
    myproj-common

    0.0.1-SNAPSHOT
    – questionaire Apr 08 '13 at 18:17
  • @questionaire Please post the error that maven gives you when you try to include that dependency (also, I assume that block is from your core project's pom?). Also, please check your local repository to make sure the common JAR actually got there. – Jon7 Apr 08 '13 at 18:19
  • I do see myproj-common.jar in repository, there is no error when i duild myproj-core, it does produces myproj-core.jar, but without myproj-common.jar. – questionaire Apr 08 '13 at 18:25
  • yes I noticed you posted some guidelines, thanks a lot, I am still struggling with it. – questionaire Apr 08 '13 at 18:29
  • @questionaire My bad, I forgot an important part! Check my latest edit :) – Jon7 Apr 08 '13 at 18:36
  • jon, thanks a lot, an struggling to get the plugin working, if you have any working example, would appreciate. thanks a lot for your guidance. – questionaire Apr 08 '13 at 19:33