Search code examples
javasqljames

Unable to use HashMap when compiling apache james server 2.3.1


I am unable to use a synchronized HashMap because it seems like james apache server 2.3.1 doesn't allow so.

This is the error message I am getting:

error: generics are not supported in -source 1.4
Map<String, String> list = new HashMap<String, String>();
       ^
(use -source 5 or higher to enable generics)
1 error
1 warning

This is a shorter version of where I am using it in my code. I am basically just storing some SQL results into this list.

try {
    conn = ......);
    String SQL = "SELECT * FROM list";

    getListRS = conn.prepareStatement(SQL);

    ResultSet rsListResult = getListRS.executeQuery();

    Map<String, String> list = new HashMap<String, String>();

    while (rsListResult.next()) {
        list.put(rsListResult.getString(0), rsListResult.getString(1));
    }

    rsListResult.close();
    conn.close();
} 
catch (SQLException se) {
    se.printStackTrace();
}
catch (Exception e) {
    e.printStackTrace();
}
finally {
    try {
        if (getListResult != null) {
            getListResult.close();
        }
    }
    catch (SQLException se2) {
        se2.printStackTrace();
    }
    try {
        if (conn != null) {
            conn.close();
        }
    }
    catch (SQLException se) {
        se.printStackTrace();
    }
}

if (this.list.containsKey(mail.getSender()+"="+mail.getRecipients())) {
    System.out.println(list);
    return mail.getRecipients();
} else {
    System.out.println(listlist);
    return null;
}

What other list can I use to achieve this since James is not letting me compile.

The error is at here:

      <javac destdir="${build.classes}" debug="${debug}" optimize="${optimize}" deprecation="${deprecation}" target="${jdk.target}" source="${jdk.source}">

Solution

  • This is an error from java compiler. In ant you define source level in javac tag, e.g.:

    <javac target="1.5" source="1.5" .....>
    

    (alternatively check default.properties file for jdk.target and jdk.source and change those to 1.5).

    Use at least 1.5 level to allow generics.

    BTW. To check what java version you have you can call java -version when you go to the jdk bin folder.