Sunday, May 6, 2018

How to use Nablarch

Nablarch is a minor Japanese-made java framework. The error message etc can be Japanese, so I am not sure you will like it. Official document is here (Japanese). I'm sure you will find little questions & examples on internet (like stackoverflow). Official examples are here (Japanese).

According to these documents, Nablarch is supposed to be developed by IntelliJ IDEA.

I am using Windows8.1 for my OS.
Suppose we are using Windows 8.1.

The following is how to install and build Nablarch.

JDK


At first, we will install JDK.
Install from here: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html


Then set the path for Java home. Open the control panel and choose the "System and Security" --> "System".
Click the Advanced tab and the button Environment Variables.



Click New... at the System Variables or User variables.
Use JDK_HOME as the variable name and "C:\Program Files\Java\(your jdk folder)" as the path.

If you have installed wrong version of Java and want to change the version, download the right version of Java and change the path of JAVA_HOME to the new JDK's path. If this doesn't work and if you are using windows8, check if there is "C:\ProgramData\Oracle\Java\javapath" in the "Path" in System Variables. If there is, delete "C:\ProgramData\Oracle\Java\javapath" from the path. Otherwise the Java version doesn't change on the command prompt.

Check if JDK is installed successfully by running a command "java -version" on command prompt.
java -version

java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

Maven


Then install Maven.
Visit the official site of Maven: http://maven.apache.org/download.cgi
And install Maven (like "apache-maven-3.5.2-bin.zip") from there.

After the installation, add both M2_HOME and MAVEN_HOME variables in the Windows environment, and point it to your Maven folder.


Maven is a project management tool, which is aimed for Java projects.
Available commands of Maven:
install
clean
compile
package
validate
test-compile
test
integration-test
verify
deploy

Check if Mave is installed successfully by running the following command.
mvn -version

Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T16:58:1
3+09:00)
Maven home: C:\Program Files\Apache\maven\bin\..
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1_8\jre
Default locale: en_GB, platform encoding: MS932
OS name: "windows 8.1", version: "6.3", arch: "amd64", family: "windows"
'cmd' is not recognized as an internal or external command,
operable program or batch file.

You can find setting.xml here:
C:\Program Files\Apache\maven\conf

Copy the setting.xml to ${user.home}/.m2 directory.  This will be user-specific settings.

We don't use it yet. When it is necessary, configure and activate it. But how setting.xml file can be used:
<settings>
  <!-- *snip* -->
  <profiles>
    <profile>
      <id>my-repository</id>
      <repositories>
        <repository>
          <id>my-repository-release</id>
          <url><!-- URL of Project Local Release Repository--></url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
        <repository>
          <id>my-repository-snapshot</id>
          <url><!-- URL of Project Local Snapshot Repository --></url>
          <releases>
            <enabled>false</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>my-repository-release</id>
          <url><!-- URL of Project Local Release Repository --></url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </pluginRepository>
        <pluginRepository>
          <id>my-repository-snapshot</id>
          <url><!-- URL of Project Local Snapshot Repository --></url>
          <releases>
            <enabled>false</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>

  <!-- Activate this repository -->
  <activeProfiles>
    <activeProfile>my-repository</activeProfile>
  </activeProfiles>
  <!-- *snip* -->
</settings>


Nablarch example web


Create a folder and clone the project:
$ mkdir ${user.home}\Documents\nablarch-example
$ git clone https://github.com/nablarch/nablarch-example-web.git
Please replace ${user.home} with your user home directory.

And we get the example:


Now create and configure database and create entity classes:
$ cd nablarch-example-web
$ mvn generate-resources


Now build the application:
$ cd nablarch-example-web
$ mvn generate-resources


Start the application:
$ mvn waitt:run

Wait for a while and this page is opened automatically:

Use these to sign in:
Sign-in ID: 10000001
Password: pass123-

After sigining in: