Featured image of post Using Docker to Build Legacy Java Projects and Verify WeChat Pay Certificates

Using Docker to Build Legacy Java Projects and Verify WeChat Pay Certificates

Learn how to build legacy Java projects with Docker and JDK 8 without installing multiple Java versions locally, and verify that a new WeChat Pay APIv2 merchant certificate is correctly deployed.

Using Docker to Build Legacy Java Projects and Verify WeChat Pay Certificates

When maintaining legacy Java projects, development environments can become a source of unexpected problems. A project that compiled successfully in an older environment may suddenly fail after moving to a new machine with a newer JDK.

Another common deployment task is replacing a WeChat Pay merchant certificate. Updating the certificate file alone does not necessarily mean the application is using the new certificate.

This article covers two practical scenarios:

  1. Building legacy Java projects with Docker instead of installing multiple JDK versions locally.
  2. Verifying that a newly replaced WeChat Pay APIv2 certificate is actually being used.

1. Building Legacy Java Projects with Docker

1.1 Understanding the Lombok Compilation Error

Consider the following Maven compilation error:

[ERROR] cannot find symbol
symbol: method getTplSellerPurchaseUpdate()
location: variable aliyunSmsProperties
of type AliyunSmsProperties

The affected class uses Lombok annotations:

@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Configuration
@EnableConfigurationProperties(AliyunSmsProperties.class)
@ConfigurationProperties(prefix = "aliyun.sms")
public class AliyunSmsProperties {

    private String accessKeyId;
    private String accessKeySecret;

    private String tplVerifyCode;
    private String tplGoodsCheckYes;
    private String tplGoodsCheckNo;
    private String tplSellerOrderNew;
    private String tplNewExchangeOrder;
    private String tplNewPurchaseOrder;
    private String tplBuyerPurchaseUpdate;
    private String tplSellerPurchaseUpdate;
    private String tplBuyerExchangeUpdate;
    private String tplSellerExchangeUpdate;
}

Normally, Lombok generates the corresponding getter methods during compilation.

For example:

private String tplSellerPurchaseUpdate;

Should generate:

public String getTplSellerPurchaseUpdate() {
    return tplSellerPurchaseUpdate;
}

If this method cannot be found, possible causes include:

  • Lombok annotation processing is not working.
  • The Lombok dependency is outdated or incompatible with the JDK.
  • The field or method is missing from the actual compiled class.
  • An outdated dependency or cached class is being used.

1.2 Identifying the JDK Compatibility Problem

In this particular case, the project worked in the previous development environment but failed after moving to a new machine.

Checking the Java version revealed:

java --version

Output:

openjdk 25.0.5.1
OpenJDK Runtime Environment
OpenJDK 64-Bit Server VM

The project was using an older Maven compiler plugin:

<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>

The old Lombok version used by the project was not compatible with the new JDK environment.

This explained why Lombok-generated methods could not be resolved.

The important lesson is that a project’s Java compatibility depends on more than its source code. The JDK, Maven plugins, annotation processors, and framework dependencies must also work together.

1.3 Using Docker Instead of Installing Multiple JDK Versions

One solution is to install an older JDK locally and switch between Java versions.

However, this introduces additional environment management.

A cleaner solution is to use Docker to provide an isolated build environment.

Run the following command from the project root directory, where the main pom.xml is located:

docker run -it --rm \
  -v "$PWD":/usr/src/mymaven \
  -v "$HOME/.m2":/root/.m2 \
  -w /usr/src/mymaven \
  maven:3.8.8-eclipse-temurin-8 \
  mvn clean package -DskipTests

This command uses a Maven image containing JDK 8.

Understanding the Docker Parameters

ParameterPurpose
-itRuns the container interactively
--rmAutomatically removes the container after execution
-v "$PWD":/usr/src/mymavenMounts the current project directory
-v "$HOME/.m2":/root/.m2Reuses the local Maven dependency cache
-w /usr/src/mymavenSets the working directory
maven:3.8.8-eclipse-temurin-8Provides Maven 3.8.8 and JDK 8
mvn clean package -DskipTestsCleans and packages the project without running tests

The two volume mounts are particularly important.

Project directory mounting

The container compiles the source code directly from your local project directory.

Generated files, such as:

target/*.jar

Will also appear in the local project directory.

Maven repository mounting

Mounting ~/.m2 prevents Maven from downloading all dependencies again every time a temporary container is created.

This makes subsequent builds much faster.

1.4 Creating a Convenient Maven Alias

If you frequently work with this legacy project, you can create a shell alias.

Add the following line to ~/.bashrc or ~/.zshrc:

alias mvn8='docker run -it --rm \
-v "$PWD":/usr/src/mymaven \
-v "$HOME/.m2":/root/.m2 \
-w /usr/src/mymaven \
maven:3.8.8-eclipse-temurin-8 mvn'

Reload your shell configuration:

source ~/.bashrc

Or, if you use Zsh:

source ~/.zshrc

Now you can build the project just like using the native Maven command:

mvn8 clean package -DskipTests

You can also execute other Maven commands:

mvn8 clean install -DskipTests
mvn8 dependency:tree
mvn8 test

If your project uses a custom Maven settings.xml, you can mount it into the container as well:

-v "$HOME/.m2/settings.xml":/root/.m2/settings.xml

This approach is especially useful when maintaining multiple projects that require different Java versions.

2. Verifying a New WeChat Pay Merchant Certificate

After resolving the Java environment issue, another deployment question is how to confirm that a newly replaced WeChat Pay certificate is actually being used.

Replacing a certificate file does not automatically guarantee that the running application has loaded it.

The following example uses WeChat Pay APIv2 and a .p12 merchant certificate.

2.1 Understanding the Certificate Configuration

The application uses the following configuration in application.properties:

weixin.pay.key.file=${server.home}/apiclient_cert_20261202.p12

The certificate is located in an external directory referenced by ${server.home}.

This means the certificate is not necessarily packaged inside the application JAR.

Using a date-based filename is also helpful because it makes certificate replacement easier to identify.

2.2 Verify the New Certificate Serial Number

First, inspect the new .p12 certificate using OpenSSL:

openssl pkcs12 \
  -in /path/to/apiclient_cert_20261202.p12 \
  -nodes \
  -nokeys | openssl x509 -noout -serial -dates

OpenSSL will display the certificate serial number and validity period.

For example:

serial=XXXXXXXXXXXX
notBefore=...
notAfter=...

Compare the serial number with the certificate information displayed in the WeChat Pay Merchant Platform.

This confirms that the file you are inspecting contains the expected certificate.

2.3 Verify the Configuration Inside the JAR

Because the certificate path is configured in application.properties, you must ensure that the updated configuration has been included in the newly built JAR.

First, rebuild the application:

mvn8 clean package -DskipTests

Then inspect the packaged configuration:

unzip -p target/*.jar \
  BOOT-INF/classes/application.properties \
  | grep weixin.pay.key.file

Expected output:

weixin.pay.key.file=${server.home}/apiclient_cert_20261202.p12

If the application uses multiple environment-specific configuration files, such as:

application.properties
application-prod.properties
application-test.properties

Check the active profile’s configuration as well.

A profile-specific property may override the default configuration.

2.4 Verify the External Certificate File

Next, log in to the deployment server and check whether the certificate exists in the directory referenced by ${server.home}.

For example:

ls -l /your/server/home/apiclient_cert_20261202.p12

Make sure that:

  • The file exists.
  • The Java application user has permission to read it.
  • The configured server.home points to the expected directory.
  • The filename matches the configuration exactly.

You should also inspect how server.home is defined.

It may come from an application property or a JVM startup parameter:

-Dserver.home=/your/server/home

A correct filename in the configuration is not enough if the actual directory is incorrect.

2.5 Restart the Java Application

After replacing the certificate and updating the configuration, restart the Java application.

This step is important because many WeChat Pay SDK implementations load the .p12 certificate when initializing the payment service or SSL context.

Simply replacing the file on disk may not update an already-running application.

The application may continue using the certificate that was loaded into memory during startup.

2.6 Perform an Actual APIv2 Certificate Verification

The most reliable way to verify that the new certificate works is to execute an API operation that actually requires the merchant certificate.

For WeChat Pay APIv2, the .p12 certificate is typically used for operations requiring client-side SSL authentication, such as:

  • Refund requests.
  • Order cancellation.
  • Certain merchant fund transfer operations.

A normal payment creation request does not necessarily verify that the new .p12 certificate is working.

For testing, you can use a test order and initiate a small refund.

A successful refund request, together with confirmation that the refund was processed, provides strong evidence that the application loaded a valid certificate and completed the required authentication.

Do not use a real financial operation solely as a test unless you understand its business consequences.

2.7 Confirm the Certificate in the Merchant Platform

Finally, log in to the WeChat Pay Merchant Platform.

Navigate to:

Account Center
    → API Security
        → Apply for API Certificate

Check the certificate list and verify that the new certificate is active.

Compare its serial number with the value obtained from OpenSSL.

Only after confirming that the new certificate is working should you consider revoking the old certificate.

Make sure no other application instance or deployment is still using the old certificate before doing so.

3. Common Problems and Troubleshooting

The following table summarizes several common issues encountered during these operations.

ProblemPossible CauseRecommended Action
Lombok getter cannot be foundIncompatible Lombok/JDK combinationCheck Lombok and JDK compatibility
Maven build fails after changing environmentsDifferent JDK versionsUse a consistent Docker build image
Maven downloads dependencies repeatedlyMaven cache is not mountedMount ~/.m2
Updated configuration is missing from JARApplication was not rebuiltRun mvn8 clean package
Certificate file cannot be foundIncorrect server.home or filenameCheck the resolved external path
Old certificate is still being usedApplication has not been restartedRestart the Java process
Certificate authentication failsWrong certificate, key, or merchant configurationVerify certificate details and SDK configuration

4. Conclusion

These two scenarios demonstrate how small improvements to development and deployment workflows can prevent unnecessary troubleshooting.

For legacy Java projects, Docker provides an isolated and reproducible build environment. Instead of installing and switching between multiple JDK versions on your workstation, you can use a dedicated Maven image for each project.

For WeChat Pay certificate replacement, changing a file is only one part of the process. You should also verify the packaged configuration, external file path, application restart, certificate serial number, and actual API authentication.

The key takeaway is simple:

Make your build environment reproducible, and verify deployment changes through the actual runtime behavior rather than relying only on configuration files.

comments powered by Disqus