Build and Version Numbering for Java Projects (ant, cvs, hudson)

For several of my projects I capture the subversion revision number, time, user who ran the build, and some system information, stuff them into a .properties file that gets included in the application jar, and read that jar at runtime. The ant code looks like this: <!– software revision number –> <property name=”version” value=”1.23″/> <target … Read more

Make ant quiet without the -q flag?

One option might be to set the logging level from within the target. You can access loggers by means of a short script task. Something like: <target … > <script language=”javascript”> var logger = project.getBuildListeners( ).firstElement( ); logger.setMessageOutputLevel( 0 ); </script> … </target> I’m not familiar with how Eclipse calls Ant, but it might be … Read more

Building a runnable jar with Maven 2

The easiest way to do this would be to create an assembly using the maven-assembly-plugin and the predefined jar-with-dependencies descriptor. You’ll also need to generate a manifest with a main-class entry for this uber jar. The snippet below shows how to configure the assembly plugin to do so: <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> … Read more

Maven: How to include jars, which are not available in reps into a J2EE project?

For people wanting a quick solution to this problem: <dependency> <groupId>LIB_NAME</groupId> <artifactId>LIB_NAME</artifactId> <version>1.0.0</version> <scope>system</scope> <systemPath>${basedir}/WebContent/WEB-INF/lib/YOUR_LIB.jar</systemPath> </dependency> just give your library a unique groupID and artifact name and point to where it is in the file system. You are good to go. Of course this is a dirty quick fix that will ONLY work on your … Read more

How do I put all required JAR files in a library folder inside the final JAR file with Maven?

The following is my solution. Test it if it works for you: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>prepare-package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/classes/lib</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <!– <classpathPrefix>lib</classpathPrefix> –> <!– <mainClass>test.org.Cliente</mainClass> –> </manifest> <manifestEntries> <Class-Path>lib/</Class-Path> </manifestEntries> </archive> </configuration> </plugin> The first plugin puts … Read more