Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java library that enables ${var} substitution [closed]

Tags:

java

text

Does anyone know of a Java library that provides support for the ${var} style substitution in text files?

like image 565
Doug Knesek Avatar asked Mar 03 '10 21:03

Doug Knesek


People also ask

Which library is used in Java?

The Java Class Library (JCL) is a set of dynamically loadable libraries that Java Virtual Machine (JVM) languages can call at run time. Because the Java Platform is not dependent on a specific operating system, applications cannot rely on any of the platform-native libraries.

What are the library functions in Java?

The Functional Java library provides the usual set of types for managing data like lists, sets, arrays, and maps. The key thing to realize is that these data types are immutable. Additionally, the library provides convenience functions to convert to and from standard Java Collections classes if needed.

What are external libraries in Java?

What are External Libraries? External Libraries are pieces of pre-written code that is easy to implement. You don't really have to know exactly anything about what is inside that code, you just need to know how to use it.

What is Djava library path?

java. library. path is a System property, which is used by Java programming language, mostly JVM, to search native libraries, required by a project.


2 Answers

Use org.apache.commons.lang3.text.StrSubstitutor

Example 1 (the simplest example is to use this class to replace Java System properties):

  StrSubstitutor.replaceSystemProperties(
    "You are running with java.version = ${java.version} and os.name = ${os.name}.");

Example 2:

   Map valuesMap = HashMap();
   valuesMap.put("animal", "quick brown fox");
   valuesMap.put("target", "lazy dog");
   String templateString = "The ${animal} jumped over the ${target}.";
   StrSubstitutor sub = new StrSubstitutor(valuesMap);
   String resolvedString = sub.replace(templateString);

yielding:

   The quick brown fox jumped over the lazy dog.
  • JavaDoc
  • Apache Commons Lang
like image 180
user3444334 Avatar answered Oct 04 '22 17:10

user3444334


Velocity ( http://velocity.apache.org ), FreeMarker ( https://freemarker.apache.org/ )

like image 26
cnpfm Avatar answered Oct 04 '22 15:10

cnpfm