Maven — Making both a War and Jar at the same time

Maven nicely automates building WAR files, but it places your compiled classes in WEB-INF/classes instead of making a new jar in /WEB-INF/lib.

If you want your code to be compiled as a .jar as well as a .war, you can do this by specifying the jar goal in the command line:

[shell>mvn clean jar install

Note this will make myproject.jar in target/, not in target/myproject/WEB-INF/lib, so you will need to use the Ant plugin to move this stuff around.

But this is not always an option: for deep, modular builds using the reactor, you may want to build your whole thing using one “mvn install”. To do this, do the following:

  1. Specify “war” packaging at the top of your pom.xml.
  2. Then add the following to your build section.
<?xml version="1.0" encoding="UTF-8"?>

And that’s it. Do a “maven install” and you get both a jar as well as a war.

How to install Maven on CentOS

Apache Maven is a project management software, managing building, reporting and documentation of a Java  development project. In order to install and configure Apache Maven on CentOS, follow these steps.

First of all, you need to install Java 1.7 JDK. Make sure to install Java JDK, not JRE.

Then go ahead and download the latest Maven binary from its official site. For example, for version 3.0.4:

$ wget
$ sudo tar xzf apache-maven-3.0.5-bin.tar.gz -C /usr/local
$ cd /usr/local
$ sudo ln -s apache-maven-3.0.5 maven


Next, set up Maven path system-wide:

$ sudo vi /etc/profile.d/
export M2_HOME=/usr/local/maven
export PATH=${M2_HOME}/bin:${PATH}

Finally, log out and log in again to activate the above environment variables.
To verify successful installation of maven, check the version of maven:

$ mvn -version


Optionally, if you are using Maven behind a proxy, you must do the following.

$ vi ~/.m2/settings.xml

Rotated Text in Java Swing 2D

I was, um….Googling myself….and found an old post I made to in 1999, answering someone’s question about how to draw rotated text in Swing.

I looked around, and ten years later, there still doesn’t seem to be much easily-found information on this. So, here it is again….

I just worked this one out, and thought I'd respond, since the faq wasn't
very helpful in my situation, and probably isn't for the situation that
David described.

Correct me if I'm wrong, but:

The method described in the faq works great if you want to apply a transform
to the entire graphics context. If all you want is some rotated text on top
of something that you've already drawn, this doesn't seem to be the way to do it.

What I did instead was to derive a font with the desired transform, and then use
that font in a drawText call, thusly:
private void label_line(Graphics g, double x, double y, double theta, String label) {

     Graphics2D g2D = (Graphics2D)g;

    // Create a rotation transformation for the font.
    AffineTransform fontAT = new AffineTransform();

    // get the current font
    Font theFont = g2D.getFont();

    // Derive a new font using a rotatation transform
    Font theDerivedFont = theFont.deriveFont(fontAT);

    // set the derived font in the Graphics2D context

    // Render a string using the derived font
    g2D.drawString(label, (int)x, (int)y);

    // put the original font back
 theta (the rotation angle) is in radians.

 For vertical text, use 90 * java.lang.Math.PI/180
 or  270 * java.lang.Math.PI/180

 depending on whether you want the text top-top-bottom or bottom-to-top

 I hope that this will save you hours of aggravation.

Thanks to Google Groups for saving all of this old stuff!