Maven Mirror and Repository: Configuring Multiple Repositories
Mirror and repository in Maven are two easily confused concepts, as both are used to configure the addresses of remote Maven repositories. As the name suggests, a repository directly configures the site address, while a mirror acts as a site’s mirror, proxying requests to one or several sites, achieving a complete replacement of repositories. RepositoryThere are two ways to configure multiple repositories: configuring multiple profiles or configuring multiple repositories within a single prof...
Building Executable JAR Packages with Maven Shade Plugin
What Is a Fat JarEclipse has a feature called “Export Runnable JAR File” that packages a project along with all its dependencies into a Fat JAR, with a specified Main class, so you can run the code directly using java jar xxx.jar. Maven Shade Plugin ConfigurationHowever, what if you’re not using Eclipse? Actually, with the help of Maven, we can easily achieve the same functionality. Maven provides a Shade Plugin that can be used to build Fat JARs, and it also supports specifying the Main cl...
ActiveMQ Plugin Development Guide and Examples
ActiveMQ provides a plugin development mechanism (http://activemq.apache.org/developing-plugins.html) that allows you to conveniently add various custom functionalities. The effect is similar to directly modifying ActiveMQ’s source code, but using plugins is much better than modifying source code in terms of both convenience and risk. In theory, we can implement almost any functionality imaginable through this approach. Development GuideFirst, you need to add the ActiveMQ dependency to your p...
Running Java Programs from the Command Line by Adding Third-Party Jars to the Classpath
When running a Java program directly from the command line, if you need to include third-party jar packages, the common approach is to use Maven/Gradle to build a fat jar (bundling all dependencies). However, in lightweight scenarios — such as writing a small script, doing quick prototype validation, or temporarily running Java code in a CI environment — manually setting the classpath is often more straightforward. What Is Classpath?Classpath is the search path the JVM uses to locate c...
Fixing the SecurityException: Invalid Signature File Digest for Manifest Main Attributes in Fat Jars
The ProblemRecently I encountered an error when trying to run a fat jar: 1234567891011121314151617181920Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:287) at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:240) at java.util.jar.JarVerifier.processEntry(JarVerifier.java:317) at java.util.jar.JarVerifier.updat...
Understanding Redis Cluster Through Practice
Redis Cluster is an official clustering solution provided by Redis. It has been available as a stable release since version 3.0, is widely adopted, and has stood the test of time. Personally, I believe it can fully replace other clustering solutions like Codis and Twemproxy. Cluster PrinciplesCluster implements data sharding. A Redis Cluster contains 16,384 hash slots. Any key can be mapped to a specific slot using the formula CRC16(key) % 16384. Which slot belongs to which node is predetermi...
An Approach to Storing Sets in HBase
HBase’s storage model is a simple key-value store (rowkey → column family → qualifier → value). Unlike Redis, it doesn’t natively support data structures like Set, List, or Hash. Yet in real-world applications, we often need to store collection-type data — user tag sets, product attribute sets, friend lists in social graphs, to name a few. How can we elegantly implement a Set in HBase? This article introduces an efficient approach that leverages HBase’s column (qualifier) characteristics. R...
Log4j2 XML Configuration Examples and Differences from Log4j
Complete Configuration Example1234567891011121314151617181920212223242526272829303132333435<?xml version="1.0" encoding="UTF-8" ?><configuration status="warn"> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="[%p] %d %c %l - %m%n"/> </Console> <RollingFile name="activity" fileName="/opt/fox.log" ...
Comparing Java Lists Without Implementing equals
Problem StatementIn Java, there are several ways to compare whether two Lists have the same values regardless of order, such as sorting followed by using equals, or executing containsAll in both directions, etc. All of these methods require us to implement the equals and hashCode methods for the element classes in the list. However, there are special cases where it’s not convenient for us to implement the equals method of a class — for example, when it comes from an ancient third-party JAR pa...
Implementing Redis hmsetnx Command Using Lua Scripts and Jedis
In Redis’s Hash operations, HSETNX ensures that a field is only written when it does not already exist. However, HMSET (which sets multiple fields in batch) has no corresponding HMSETNX command. If you need to batch-initialize a cache without overwriting existing data, issuing N HSETNX commands would require N network round-trips — terrible performance in batch scenarios. This can be solved elegantly with a Lua script — pushing the logic to the Redis server side and requiring only a single ne...













