sql maven plugin write file in target encoding.

Sql-maven-plugin is used to execute database queries as part of build steps. It can also generate files from database queries. It is an excellent tool when it comes to generating file where certain application parameters are saved in a database and are needed by an application as properties.

Some applications save configuration parameters in the database but do not want to read it from the database at runtime, because of various business or architecture compliances.

These applications rather produce configuration files from the database as part of the build step and use them as application properties as resource bundle.

One good use is for locale messages. applications supporting multiple languages, generate message files of different locale from database tables, which are usually managed by business teams. Locale support needs specific encodings, which is not supported by out of the box by popular sql-maven-plugin from codehaus.

The maven plugin code at GitHub.com has a pull request for this additional feature but not sure why they have not merged the code.

I forked the code from their repository to create a plugin with the required feature so users can specify the encoding of an output file.

The code for the same is located at https://github.com/vbhavsingh/sql-maven-plugin

For more information on plugin visit https://www.mojohaus.org/sql-maven-plugin



<plugin>
    <groupId>net.rationalminds</groupId>
    <artifactId>sql-maven-plugin</artifactId>
    <version>1.0</version>
    <executions>
      <execution>
        <id>generate.messages</id>
        <phase>generate-resources</phase>
        <goals>
          <goal>execute</goal>
        </goals>
        <configuration>
          <autocommit>replace_me</autocommit>
          <printResultSet>true</printResultSet>
          <outputDelimiter>row</outputDelimiter>
          <srcFiles>
            <srcFile>replace_me</srcFile>
          </srcFiles>
          <outputFile>replace_me</outputFile>
          <driver>replace_me</driver>
          <url>replace_me</url>
          <username>replace_me</username>
          <password>replace_me</password> 
          <outputEncoding>UTF-8</outputEncoding>  <!-- Specify encoding out output file-->     
        </configuration>
      </execution>         
    </executions>
    <dependencies>
      <dependency>
        <groupId>replace_me</groupId>
        <artifactId>replace_me</artifactId>
        <version>replace_me</version>
        <scope>compile</scope>
      </dependency>
    </dependencies>
    <configuration>
      <driver>replace_me</driver>
      <url>replace_me</url>
      <username>replace_me</username>
      <password>replace_me</password>
    </configuration>
  </plugin>

Comments

Popular posts from this blog

Caused by: java.sql.SQLTimeoutException: ORA-01013: user requested cancel of current operation

HashiCorp Vault Integration with Ansible Etower using approle

utility to extract date from text with java