10 Jul 2007, 9:49pm
Projects:
by

13 comments

  • Going Java 1.5 With Maven2-Based Project

    I recently made some simple updates to Wish by using Java 1.5 generics and autoboxing/unboxing. Making Java source changes was the easy part, while the time consuming part was on hunting for information on Maven-related changes.

    I started by changing maven-compiler-plugin source and target in pom.xml:

    <build>
      <plugins>
        ...
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
            <source>1.5</source>
            <target>1.5</target>
          </configuration>
        </plugin>
        ...
      </plugins>
    </build>
    

    And got this error upon running mvn site

    Caused by: net.sourceforge.pmd.ast.ParseException: Can't use generics unless running in JDK 1.5 mode!
    

    which led me to change maven-pmd-plugin targetJdk:

    <reporting>
      <plugins>
        ...
        <plugin>
          <artifactId>maven-pmd-plugin</artifactId>
          <configuration>
            <targetJdk>1.5</targetJdk>
          </configuration>
        </plugin>
        ...
      </plugins>
    </reporting>
    

    Then I found out that the angle brackets used by generics syntax resulted in checkstyle errors:

    <' is not preceded with whitespace.
    error	<;' is not followed by whitespace.
    error	'>' is not preceded with whitespace.
    

    which is fixed by adding these modules to checkstyle.xml .

    If you don’t already have any existing checkstyle rules, create checkstyle.xml file and place it on the root directory of the project (i.e. same place as pom.xml) and add configLocation to maven-checkstyle-plugin:

    <reporting>
      <plugins>
        ...
        <plugin>
          <artifactId>maven-checkstyle-plugin</artifactId>
          <configuration>
            <configLocation>checkstyle.xml</configLocation>
          </configuration>
        </plugin>
        ...
      </plugins>
    </reporting>
    

    Related Posts:

    21 Aug 2007, 7:12pm
    by Vikas Hazrati

    reply

    Very useful tip. Thanks

    Very useful.. if I could make it to work !

    I probably missed somthing. I have a specific checkstyle file and I put the new modules this way inside the treewalker module :

    <module name=”NoWhitespaceAfter”>
    <!– Default tokens and additional GENERIC_START –>
    <property name=”tokens” value=”ARRAY_INIT, BNOT, DEC, DOT, INC, LNOT,
    UNARY_MINUS, UNARY_PLUS, GENERIC_START”/>
    </module>

    <module name=”NoWhitespaceBefore”>
    <!– Default tokens and additional GENERIC_START and GENERIC_END –>
    <property name=”tokens” value=”SEMI, POST_DEC, POST_INC,
    GENERIC_START, GENERIC_END”/>
    </module>

    <module name=”WhitespaceAfter”>
    <!– Default tokens and additional GENERIC_END –>
    <property name=”tokens” value=”COMMA, SEMI, TYPECAST, GENERIC_END”/>
    </module>

    <module name=”WhitespaceAround”>
    <!– Default tokens without GENERIC_START and GENERIC_END –>
    <property name=”tokens” value=”ASSIGN, BAND, BAND_ASSIGN, BOR,
    BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV,
    DIV_ASSIGN, EQUAL, GE, GT, LAND, LCURLY, LE, LITERAL_ASSERT,
    LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY,
    LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SYNCHRONIZED,
    LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD,
    MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, RCURLY, SL,
    SLIST, SL_ASSIGN, SR, SR_ASSIGN, STAR, STAR_ASSIGN,
    TYPE_EXTENSION_AND, WILDCARD_TYPE”/>
    </module>

    It continues reporting errors for missing spaces before and after < and > in generics. Any idea about what I am doing wrong ?

    14 Sep 2007, 7:02pm
    by Grateful Visitor

    reply

    Man, thanks a bunch :) You saved my backside!

    Thanks for the tip – saved me a lot of trouble. Tip for pys: remove the existing NoWhitespaceAfter, NoWhitespaceBefore, WhitespaceAfter and WhitespaceAround modules from your checkstyle file. They probably override the new settings that you added. It should work after you do that.

    Thanks, it just be very useful for me.

    Thanks … works really well for me.

    8 Jul 2008, 6:52pm
    by børrild

    reply

    Tip for phn and pys: The genric-tokens are not valid token parameters for the checks “NoWhitespaceAfter”, “NoWhitespaceBefore” and “WhitespaceAfter”, they are simply ignored.

    I’m having trouble with the

    Any ideas if it is related to the nowhistespaceafter modules? I’ve tried changing the code around a bit but nothing is changing yet.

    29 Mar 2009, 1:51am
    by Martinez Marchand

    reply

    Weird, it didn’t show the code. I’m having issues with the whitespacearound module. The whole block of code just gives me some messed up error.

    I am getting this error when using ‘jspc-maven-plugin’ I run maven Install.

    C:/WorkSpace/msp-operations/build/WEB-INF/jsp/user/assignClients.jsp(2,0) File “/msp.tld” not found

    The path for msp.tld is specified in the web.xml file which i am not able to refer.

    thus can u please help me how to refer this .

    Got rid of the annoying build warnings for PMD. Thanks!

    Maven is something which is a tool difficult to understand, but once you understand it becomes the best thing that happened to Java.

    28 Nov 2011, 1:47pm
    by poseidonfu

    reply

    thanks,Very effective

     

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

     

    Recent Posts

    Recent Comments

    • Cliffano Subagio: Good to hear about your opportunity to visit Japan, I’m sure you will have a great...
    • Kayla: I’m going to Japan for two week this summer. Our sister city is Tsubame, Japan and my school has an...
    • poseidonfu: thanks,Very effective
    • anonymous: I really enjoyed both the last lecture and the book. I don’t think that theres anyone that I look up...
    • dioni: The thing I hate about HK is how people shove and push in the queue. Can’t they be civilized?!! I kept...

    Most Commented Posts

    Linkroll