开发者

Traditional Open Source Java Application [closed]

Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 7 years ago.

Improve this question

I've been using Java for my "home projects" for a while and now there's a need to make some of my projects available through the repositories like github or Google Code.

As long as I'm the only developer for the project and as long as I always work in Eclipse, there are absolutely no questions about开发者_运维技巧 building and running it. Everything just work fine. The question is basically, what do I do if someone asks me to share? :-)

The first thing to do is, making the project buildable with tools like Maven. In this case, no matter if someone has Eclipse installed, or prefers IDEA, he may just download my project and build using Maven. Or, import to Eclipse/IDEA and build.

So, to clarify the question, here are 2 points:

  1. What should my directory structure look like? Folders like src, bin, anything else?
  2. What is the way my application should run? For instance, my application requires log4j in order to run. Maven resolves this dependency, when building the package. But when the package is built, you should manually provide the path to you log4j (with java -cp ...) - what's the way to eliminate this requirement if I'd like to just provide .sh and .cmd scripts for user's convenience?


If you and your peers just want to keep using Eclipse then share the projects including .project and other hidden files, and avoid from referencing external jar-files and other resources. If you need log4j.jar then put it in your project and add it to the build path.

This works very well, even for multiple programmers and is the fastest way to get up and running.


From my personal experience, maven is the best available tool for building and managing dependencies, so my answers for your questions are all about maven. Also, with maven you need to provide only pom.xml file containing definition of dependencies and project build configuration. Project you share does not need to contain any JARs inside, as it used to be with ant based projects.

What should my directory structure look like? Folders like src, bin, anything else?

As in a standard maven project :) (http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html)

  • src/main/java application sources (Java classes)
  • src/test/java application tests (unit test for class com.company.Foo should be also in the com.company package, it introduces some order and sometimes makes testing easier)
  • src/main/resources application resources, for example message.properties file serving internationalization
  • src/test/resources resources for tests, for example dumps of websites if you would like to do integration tests with http server returning some content.

There are also other directories, such as src/main/webapp - all of them are described in the maven docs.

What is the way my application should run? For instance, my application requires log4j in order to run. Maven resolves this dependency, when building the package. But when the package is built, you should manually provide the path to you log4j (with java -cp ...) - what's the way to eliminate this requirement if I'd like to just provide .sh and .cmd scripts for user's convenience?

Maven takes care about all of these things, following your configuration defined in pom.xml file. If you program requires some extra-libraries, maven will download it for you, and place in the package containing your application. If, for example some dependencies will be provided by your application server (log4j JAR), you can also set that dependency is gonna be provided and then, it will be available for running application, for unit tests, but it will not be places in the final package.

What is additional great feature provided by maven is build profiles. You can for example use some setting in the day-to-day development mode, but in case of building package for production, other settings will be used.


What should my directory structure look like? Folders like src, bin, anything else?

If you are on maven, it is taken care of. (src/main/java, src/test/java et al.)

What is the way my application should run?

I think maven exec plugin should help you here. Take a look at http://mojo.codehaus.org/exec-maven-plugin/java-mojo.html and see whether it fits the bill.


Buddy if anyone wants to work on a public or oss project they are probably capable enough in Java to get the environment setup on their own. That being said, your options are:

a) Maven (super simple, I have a GitHub project setup using this, just download with Git and import using IDE Maven Option). I've tried to use this option with every major ide and never had any issues. This is especially useful if you have a lot of dependencies.

b) Check in your eclipse project files, I know this sounds stupid, but most IDE's let you import Eclipe projects.

c) Write a README file! (obvious I know).

d) Write an ant file to do all the heavy lifting (initialize everything) if there is some processes to setup the project.

I would not worry about project structure. Again, if anyone wants to work with you, they are probably smart enough to get things up and running without bothering you much. I would not worry about compiling and running the project either, but if you really want, you can setup Ant or Maven to do it.


As Maven aficionados like to say, Maven is opinionated software. By this they mean that Maven will do more things for you with less effort if you adhere to the conventions it imposes. Directory structure is probably the most important one. I don't advise you to adopt Maven without reading about it first, you can start here.

Once you have sorted out building your project with Maven and adopted the m2eclipse plugin to get Maven to work with Eclipse, you may want to check out the Maven assembly plugin, with which you will be able to produce a zip file that packs together your project with all its dependencies and possibly a launch script that takes care of setting your CLASSPATH without invoking your project's startup class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜