Skip to content

Getting Started

Ryuu Mitsuki edited this page Sep 15, 2024 · 16 revisions

Table of Contents

Getting Started

If you're new to JMatrix project and want to build the project with different Java version, this page will help you get up and running quickly.


Make's Rules

Rule Name Description
help Prints the help message and list of rules.
compile Compiles all the source files (.java).
package Creates the archived package of compiled classes.
build-docs Generates the HTML pages of javadocs.
usage Prints the tree representing example usages for build the project.
check-verbose Checks whether the verbose status is ACTIVATED or DEACTIVATED.
clean Cleans up the working directories thoroughly.
cleanbin Cleans the compiled classes only.
cleandocs Cleans the generated HTML documentation pages.

Make's Options

Option Name Description Type Default Value
FLAGS Append flags or options to specific rule (⚠️ Experimental option). string ""
INCLUDE_SRC Whether to include the source files while packaging (Only for package rule). boolean false
LINT Whether to invoke the linter during the compilation. boolean false
VERBOSE Whether to activate the verbose output for debugging (Only build-docs rule that supported verbose mode all, more details). boolean | string false

Maven's Profiles

Profile Name Description
include-src Includes the source files while packaging.
lint Invokes the linter during the compilation and Javadoc generation.

For list of Maven built-in commands, please refer to this website.


Build the Project

Before build the project, the first thing that need to do is clone the repository.

git clone https://github.com/mitsuki31/jmatrix.git

Important

Branch master is always up-to-date but it looks dirty (some new features may unstable), if you want stable version, use the latest version instead.

You can also check the latest release here.

Build using Make

make [options] [...] [arguments]
make [options] VERBOSE[=<bool>] INCLUDE_SRC[=<bool>]
  1. Compile all the source files

    make compile

    All the source files are located in "src/main/java/" directory relative to project's root directory. And the generated class files typically will be stored in "target/classes/" directory.

  2. Packaging and archiving all generated class files into JAR file

    make package

    Generated JAR file would be in "target/" directory.

  3. Clear all generated class files (Optional)

    make cleanbin

    This option is to clean "target/classes/" recursively only and will never remove the generated JAR file neither other directories.

Activating Verbose Output

Syntax:

export VERBOSE[=<boolean>] && make [options] [...] [arguments]
make [options] VERBOSE[=<bool>]
  • Activate

    1. Use export keyword
    export VERBOSE=true
    1. Place it as arguments
    make [options] VERBOSE=true
  • Deactivate

    export VERBOSE=false
    VERBOSE=false

    💡 Tips: You can use VERBOSE= to deactivate it, without using export and specify value anymore. It because you have already export VERBOSE variable when you activate it, and Make only checks value of VERBOSE variable when it's equivalents to true.

Include the Source Files

Syntax:

make [options] INCLUDE_SRC[=<bool>]

This option is useful to generate a JAR file containing all source files. When using this option the build system will generated two JAR files, they are:

  • jmatrix-<VERSION>.jar (contains compiled source files .class)
  • jmatrix-<VERSION>-sources.jar (contains uncompiled source files .java)
make [options] INCLUDE_SRC=true

Note

This option was required only by package rule, it will be ignored for other rules. For example:

make package INCLUDE_SRC=true

You can also combine the Make's rules along with the options as long as you want. For example:

make check-verbose package cleanbin VERBOSE=true INCLUDE_SRC=true

Build using Maven

  1. Compile all the source files
    mvn compile
  2. Packaging and archiving all generated class files to JAR file
    mvn package
  3. Install as Maven local repository (Optional)
    mvn install

Include the Source Files

This option is useful to generate a JAR file containing all source files. When using this option the build system will generated two JAR files, they are:

  • jmatrix-<VERSION>.jar (contains compiled source files .class)
  • jmatrix-<VERSION>-sources.jar (contains uncompiled source files .java)
mvn package -P include-src

How to Use the JAR File?

It's very simple, the only need to do is:

  • Compile the Program
    javac -cp jmatrix.jar MyProgram.java
    Use -cp or -classpath switch to tell javac to compile the program with specific path to class files or JAR file.
  • Run the Program
    java -cp jmatrix.jar:. MyProgram
    Use colon (:) after JAR file (or classes directory) name to tell java to include specific directory when searching for class files.

    For Windows users, you might need to use semicolon (;) instead and enclosed it with double quotes.

    For example:

    java -cp "<jar_file>;." MyProgram

Here's a detailed guide on how to use JAR file:

  • Create an example program
    Let's assume that the MyProgram.java file is located in "test/" directory. But your current directory was in the parent directory of "test/" directory along with the JAR file.

    .
    ├── test
    │     └── MyProgram.java
    └── jmatrix.jar
    // MyProgram.java
    package test;
    
    import com.mitsuki.jmatrix.Matrix;
    
    public class MyProgram {
        public static void main(String[] args) {
            double[][] a = { {6, 7}, {1, 9}, {8, 0} };
            Matrix m = new Matrix(a);
            m.prettyDisplay();
        }
    }
  • Compile the program

    javac -cp jmatrix.jar test/MyProgram.java
  • Run the program

    • UNIX

      java -cp jmatrix.jar:test/ MyProgram
    • Windows

      java -cp "jmatrix.jar;test\" MyProgram

    In code above the package test; has been declared, so the correct way is using code below to run the program.

    • UNIX

      java -cp jmatrix.jar:. test.MyProgram
    • Windows

      java -cp "jmatrix.jar;." test.MyProgram

    The output from the example above will looks like this:

         [1]  [2]
    [1]  6.0  7.0
    [2]  1.0  9.0
    [3]  8.0  0.0

See Also