How do I create and distribute a Java project?

I used Eclipse to create a fairly simple Java project. It builds and runs in the IDE. I have some unit tests that I wrote with JUnit. They all build and run in the IDE.

My project is located in the following path:

/home/vg1890/workspace/project/

      

The main source is in:

/home/vg1890/workspace/project/src

      

And the tests are in:

/home/vg1890/workspace/project/tests

      

Package name com.vg1890.stuff

.

When I type: echo $CLASSPATH

on the command line, nothing is returned (ubuntu).

  • How can I create my entire project outside of the IDE?
  • How do I make it so that when distributing the source to another computer that it will build and run (including unit tests)?

Thank!

+2


source to share


3 answers


This is exactly what Apache Ant is usually used for. Eclipse supports ant scripts well.



+8


source


I would suggest using Apache Maven to manage your build and distribution of your sources (maven is widely used and like Ant lost by Java users / programmers is installed on their machine).

It's hard to define maven on a single line (maven is more than just a "build tool"), so I've introduced a more complete definition below, taken from the first chapter of this great book: Maven: The Ultimate Guide .

Maven is a project management tool that includes a project object model, a set of standards, a project life cycle, a dependency management system, and logic for executing plugin goals at specific stages in the life cycle. When you use Maven, you describe your project using a well-defined project object model.Maven can then apply cross-cutting logic from a set of common (or custom) plugins.



Once maven is installed, the complete installation of your project (building java sources and unit tests, running tests, packaging compiled classes) is 10 seconds (really).

To get started with Eclipse, check on how to use Eclipse Guide 2.X the Maven .

+3


source


In addition to Michael's answer, many of the IDEs (IDEA, NetBeans, Eclipse) allow you to very tightly integrate your build engines with your own Ant build scripts and may give you the ability to run them.

This can be helpful at startup. However, it is helpful to consider implementing a build mechanism later to keep it running cleanly (i.e. completely separate from your IDE). This is a very good idea these days when often IDEs have built-in support for certain technologies (e.g. Spring, Hibernate). Otherwise, it's all too easy to release some JAR file that is missing some vital library, or end up with a dependency you didn't know.

0


source







All Articles