User Tools

Site Tools


public:javabestpractises

Java Best Practises

These guidelines help our many different Java projects and libraries to work together.

GitHub Repository

For easier collaboration, visibility, backup and version control, please create a repository at https://github.com/AKSW. Please only create a public repository if possible, as the number of private ones is limited.

Maven

Maven makes it easier to include dependencies and to let other people depend and work on your code.

Maven 3 pom.xml template (change the compiler source to your liking):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelversion>4.0.0</modelversion>
    <groupid>org.aksw.projectname</groupid>
    <artifactid>projectname</artifactid>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
<!-- remove repositories you don't use-->
     <repositories>
            <repository>
                <id>maven.aksw.internal</id>
                <name>University Leipzig, AKSW Maven2 Repository</name>
                <url>http://maven.aksw.org/repository/internal</url>
            </repository>
            <repository>
                <id>maven.aksw.snapshots</id>
                <name>University Leipzig, AKSW Maven2 Repository</name>
                <url>http://maven.aksw.org/repository/snapshots</url>
            </repository>
            <repository>
                <id>UK</id>
                <name>UK Central</name>
                <url>http://uk.maven.org/maven2</url>
            </repository>
        </repositories>

    <dependencies>
        <dependency>
            <groupid>junit</groupid>
            <artifactid>junit</artifactid>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupid>org.slf4j</groupid>
            <artifactid>slf4j-log4j12</artifactid>
            <version>1.7.13</version>
        </dependency>
        <dependency>
            <groupid>org.slf4j</groupid>
            <artifactid>slf4j-api</artifactid>
            <version>1.7.13</version>
        </dependency>
    </dependencies>
</project>

If you have a stable project, create a release (non-snapshot) version, as it decrease network traffic and increase speed tremendously.

Logging

SLF4j is a collection of interfaces for logger abstraction and offers bridges, which makes it easier to handle libraries with different logging frameworks.

Encoding and Line Endings

Please always use UTF-8 encoding. Line endings will usually handled by git so that you can choose those as you prefer.

Further Reading

For general (not AKSW-specific) guidelines, see http://www.javapractices.com/home/HomeAction.do and https://github.com/cxxr/better-java.

public/javabestpractises.txt · Last modified: 2015/12/07 13:49 by KonradHoeffner