-
Notifications
You must be signed in to change notification settings - Fork 2
Java Project Usage
This guide provides a step-by-step example for configuring the Templify plugin to perform automated package name replacements in Java files, particularly useful when managing multiple files under a large package structure. This example will cover how to replace package names consistently throughout a sample project.
Let's use a simple project structure to illustrate the usage of the plugin. The project structure will be as follows:
root
└── src/
| └── main/java/br/com/client/sfc/datalake/sfcdatatransferdatalake/
| └── adapters/
| └── MyAdapter.java
| └── controllers/
| └── MyAdapter.java
| └── domains/
| └── MyDomain.java
| └── exceptions/
| └── MyException.java
| └── Application.java
└── maven-templify.yml
└── pom.xml
In this project, we have Java files with the same base package br.com.client.sfc.datalake.sfcdatatransferdatalake in various directories under src/main/java.
The Templify plugin configuration for this project is set up as follows in the maven-templify.yml file:
steps:
- kind: XmlHandler
apiVersion: v1
spec:
- files:
- pom.xml
placeholders:
- match: /project/groupId
replace: templify.groupId
- match: /project/artifactId
replace: templify.artifactId
- kind: JavaHandler
apiVersion: v1
spec:
- placeholders:
- match: br.com.client.sfc.datalake.sfcdatatransferdatalake
replace: templify.package
baseDir: src/main/javaFiles under: src/main/java/*
For Java files located in src/main/java, the spec configuration enables the following operations:
-
placeholdersSpecifies the patterns in the Java files that will be replaced.
-
match:Finds occurrences of the base package name (br.com.client.sfc.datalake.sfcdatatransferdatalake). -
replace:Substitutes the found pattern with templify.package.
-
baseDirSpecifies the root directory where theJavaHandlershould apply the placeholder replacements. Here, it is set tosrc/main/java, covering all Java files in subdirectories.
package br.com.client.sfc.datalake.sfcdatatransferdatalake.adapters;
/**
* MyAdapter
*/
public class MyAdapter {
}package {{templify.package}}.adapters;
/**
* ...
*/
public class MyAdapter {package br.com.client.sfc.datalake.sfcdatatransferdatalake.domain;
import java.util.List;
import br.com.client.sfc.datalake.sfcdatatransferdatalake.controllers.*;
import br.com.client.sfc.datalake.sfcdatatransferdatalake.adapters.MyAdapter;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
/**
* MyDomain
*/
public class MyDomain {
...package {{templify.package}}.domain;
import java.util.List;
import {{templify.package}}.controllers.*;
import {{templify.package}}.adapters.MyAdapter;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
/**
* MyDomain
*/
public class MyDomain {
...After applying Templify, the structure should look like this, with the {{templify.package}} placeholder replaced by the defined package name in your templify configuration:
root
└── src/
| └── main/java/{{templify.package}}/
| └── adapters/
| └── MyAdapter.java
| └── controllers/
| └── MyAdapter.java
| └── domains/
| └── MyDomain.java
| └── exceptions/
| └── MyException.java
| └── Application.java
└── pom.xml
This setup allows the Templify plugin to handle large Java projects by updating package names automatically, making it easier to maintain a structured, adaptable codebase.