AutoRes.uk logo

Annotation driven Java open source library for automating embedded resource file handling - a convenient alternative to Class.getResourceAsStream.

AutoRes.uk is a compile-time only dependency and does not need to be distributed with application code.

javadoc.io

Usage 🔗

Annotate a type or package and specify the resource files.

You can skip to distribution, compatibility, Java module system support, Maven configuration or Gradle configuration.

Examples 🔗

@Texts creates one class per text file that provides the file content as a String.


@uk.autores.@Texts({"Poule.txt", "Roses.txt"})
public class PrintRhymes {
  public static void main(String...args)  {
    System.out.println(Poule.text());
    System.out.println(Roses.text());
  }
}
      

@Messages generates typed methods from properties files that localize and format strings.


@uk.autores.Messages("msgs.properties")
public class PrintMessage {
  public static void main(String[] args) {
    var locale = java.util.Locale.getDefault();
    int planet = 4;
    var time = java.time.ZonedDateTime.now();
    var event = "a meteor strike";
    // planet-event=At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.
    // ...becomes signature...
    // static String planetEvent(Locale l, Number arg0, ZonedDateTime arg1, String arg2)
    String msg = Msgs.planetEvent(locale, planet, time, event);
    System.out.println(msg);
  }
}
      

Other annotations are @ByteArrays, @Keys, @InputStreams, and the extensible @ResourceFiles.

Distribution 🔗

Browse the central repository for a build system import snippet for the uk.autores:annotations library.

Versioning & Compatibility 🔗

Versions are split into three integers: Java version; major version; minor version.

Functionally identical Java 8 and Java 11 versions are published. The Java 11 version has marginally better encapsulation when modules are in use.

Modules 🔗

Use requires static uk.autores in module-info.java to depend on this library at compile time only.


module example.module.name {
  requires static uk.autores;
}
      

Apache Maven 🔗

Apache Maven projects should use the provided scope.


<!-- Maven 3 -->
<dependency>
  <groupId>uk.autores</groupId>
  <artifactId>annotations</artifactId>
  <version>${autores.version}</version>
  <scope>provided</scope>
</dependency>
      

If necessary make the compiler aware of the annotation processor using annotationProcessorPaths.


<!-- Maven 3 -->
<build>
  <plugins>
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>${maven.compiler.plugin.version}</version>
          <configuration>
              <annotationProcessorPaths>
                  <path>
                      <groupId>uk.autores</groupId>
                      <artifactId>annotations</artifactId>
                      <version>${autores.version}</version>
                  </path>
              </annotationProcessorPaths>
          </configuration>
      </plugin>
  </plugins>
</build>
      

Gradle 🔗

Gradle projects must add resource files to the classpath. The library must be exposed to the annotation processor.


// Gradle 8; Kotlin syntax
var autores = "uk.autores:annotations:" + autoresVersion

dependencies {
  compileOnly(files("src/main/resources"))
  compileOnly(autores)
  annotationProcessor(autores)
}