11

I have an eclipse Luna project with a bunch of maven dependencies defined in a pom.xml

Everything works fine in eclipse. But now I need to include all of those dependencies in an exportable jar file (so that I can ship them to workers in Apache Spark).

I keep fiddling with the export settings, but I don't see any way to export them into the jar file.

enter image description here

I find some answers explaining how to configure maven to package its dependencies. Is that my only option, or is there some way to do this in eclipse?

bernie2436
  • 22,841
  • 49
  • 151
  • 244
  • You will have the dependencies as JARs in your local Maven repo (usually ~/.m2/). Doesn't it suffice to use these? If not, have a look at [this somewhat related question](http://stackoverflow.com/questions/81260/easiest-way-to-merge-a-release-into-one-jar-file). – s.d Feb 05 '15 at 01:33
  • I currently have no eclipse installed - but as far as I remember the "export runnable jar" dialog could be what you are looking for. – slartidan Feb 05 '15 at 01:34
  • Just wonder, why don't use Maven for such kind of release? It is trivial to do by maven assembly or maven shade plugin – Adrian Shum Feb 05 '15 at 08:29
  • Yes, I believe it is your only choice to configure maven. As @AdrianShum suggests, use the maven assembly plugin or maven shade plugin to achieve this. – Zoltán Feb 05 '15 at 08:51

4 Answers4

8

Take a look at this question: How can I create an executable JAR with dependencies using Maven?

I think that @Rocky Inde's answer is what you are looking for (using eclipse):

1) Just right-click on your project folder (in Eclipse) and select Export

2) Then select Java -> Runnable Jar

3) You will be asked to choose the location of the jar file

4) Finally, select the class that has the Main method that you want to run and choose Package dependencies with the Jar file and click Finish

Community
  • 1
  • 1
Tarik
  • 4,961
  • 3
  • 36
  • 67
1

Then you need to include shade pluggin in your pom.xml and mvn package will produce the shade jar(fat jar) this link provides info about shade pluggin

kasinavijay
  • 168
  • 1
  • 12
  • 1
    Personally, if I tell someone to use shade plugin for a uber-jar, I will explicitly tell them to make that a separate classifier for the uber-jar, because Maven's dependency management will be messed up if in any case you used the result uber-jar as dependency of another project. – Adrian Shum Feb 05 '15 at 09:07
0

I think that this question is duplicated:

If you want to do it with the console and Maven you could take a look into this thread: the link that @Tarik mentions

If you want to use Eclipse, take a look into this one: How to create a jar with external libraries included in eclipse?

Community
  • 1
  • 1
Iker Aguayo
  • 3,980
  • 4
  • 37
  • 49
0

I suggest you use Maven assembly plugin. From the usage page:

For example, imagine that our project produces a JAR. If we want to create an assembly binary that includes our project's dependencies, we can take advantage of one of the Assembly Plugin's prefabricated descriptors. You configure it as follows in your project's pom.xml:

<project>
  [...]
  <build>
  [...]
  <plugins>
    <plugin>
      <!-- NOTE: We don't need a groupId specification because the group is
         org.apache.maven.plugins ...which is assumed by default.
       -->
      <artifactId>maven-assembly-plugin</artifactId>
      <version>2.5.3</version>
      <configuration>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
      [...]
</project>
Zoltán
  • 21,321
  • 14
  • 93
  • 134