Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are some additional directory conventions for Maven projects?

Maven 2 uses a standard directory layout for projects, documented here:

http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

What I'm wondering is: are there recommended conventions for other projects besides the plain-vanilla Java library, Java EE and WebApp projects? Specifically, where to place ant files, start scripts, configuration files, sample applications, etc.

In addition, what is the convention for placing files outside of the src/ directory tree? For example, is it common to place documentation under doc/ (as sibling of src)?

Is there a page where these conventions are compiled? If not, can other readers provide examples from their own projects?

like image 946
noahlz Avatar asked Feb 06 '09 21:02

noahlz


2 Answers

The main folder I place extra config files in is under src/main/java/resources. Usually I created sub directories under there. The tests can have their own config files src/test/resources.

You can use directives in the build section of the pom.xml to specify additional resources directories and where to copy files to specific places in the target directory. Usually a convention arises for the language or framework you are trying to use. In which case the mess can be hidden in a parent pom.xml

See http://maven.apache.org/pom.html#Resources

like image 194
mxc Avatar answered Sep 23 '22 06:09

mxc


I don't think there is an official layout for desktop applications, but this is the layout we use for ours.

  • src/main/config - Config files, copied and filtered to ${project.build.directory}/config.
  • src/main/scripts - sh, bat, README and other plain-text files that are copied and filtered to ${project.build.directory}.
  • src/main/bin - Binary files that are not filtered and copied to ${project.build.directory}.
  • src/main/build - Any additional scripts, ant files, or resources used by the build process but not included in the application.
  • src/main/assembly - Assembly descriptor to create application assembly.
  • Copy dependencies to ${project.build.directory}/lib using maven-dependency plugin.
  • Bonus points if you use a shared assembly descriptor jar which includes the config and lib directories along with standard file types to share with all your projects. A good set of default file types to include is .sh, .bat, and .exe with executable permissions; .jar, .zip, .txt, .pdf, .xml, .properties, .conf, .ico, .png, .jpg with standard permissions.
  • Add the config directory and lib/ prefix to the classpath using the maven-jar plugin to make a runnable jar.
  • Add a installer profile that builds an assembly of your application using the maven-assembly plugin and your assembly descriptor. This assembly can then be consumed by a separate installer project if needed.
  • Avoid putting anything else at the src/ level. Instead put documentation inside the src/site/ directory (eg. src/site/sphinx) or src/doc if you really need to.
  • Put all the above configuration in a parent/corporate pom to share with all your projects. Simply reference the maven-dependency, maven-resources, maven-jar, and maven-assembly plugins in you project to build an entire application with almost no configuration (don't forget to set the main-class for the maven-jar plugin).
like image 25
Brian Blonski Avatar answered Sep 20 '22 06:09

Brian Blonski