1

I am working on a Hadoop project in Eclipse that depends on another one of my projects; I've included the other project in my build path, but when I export the dependent project, it only contains the classes from that same project.

Ordinarily, this would not be a problem, as I could just link the other project with the -cp flag, but Hadoop requires you to pass the jar as an argument, meaning that all of my dependencies must be inside that jar.

Is there a way, in Eclipse, to automatically build and include classes from projects that you depend on?

Thanks.

Chris Gerken
  • 16,221
  • 6
  • 44
  • 59
ILikeFood
  • 400
  • 2
  • 8
  • 22

3 Answers3

1

You coud use Ant to automatically build, test and export. It needs some time learning it, but its worth. There are possible tasks (fileset, zipgroupfileset, copy) to include files, jars (unzipped) or anything into the final jar. By this way you definitly know whats inside your distribution jar and you don't need an eclipe installation running.

matcauthon
  • 2,261
  • 1
  • 24
  • 41
1

I suggest you take a look at maven as a build tool. You define the dependencies and build steps for each of your projects in files called pom files. The maven plugins for Eclipse (the m2e plugins) can take the configuration in the pom file and setup your Eclipse build paths and project description so that you can access the classes in your other project in Eclipse. Maven can also create a jar for you that has the classes from both projects (a "jar-with-dependencies").

In maven terms, your two projects are called "artifacts" with one having a dependency on the other.

The one downside to maven (and the cause for many negative comments about maven) is an initially steep learning curve that can be frustrating. What you're trying to do, however, is very straightforward and I expect you can find a number of examples showing you exactly what you want to do.

The first step, and that's what my answer is about, is to take a look at maven. It may seem overly complex, but it can scale to handle just about any build configuration you need as your hadoop apps get more and more complex.

Chris Gerken
  • 16,221
  • 6
  • 44
  • 59
0

You can export a project as a Runnable jar, which can be useful if you want a single jar, with dependencies included.

Select the Project. File > Export. Select the Java section. Select Runnable JAR file.

See related answer:

Eclipse: How to build an executable jar with external jar?

Community
  • 1
  • 1
tjg184
  • 4,508
  • 1
  • 27
  • 54