Java Build

1 minute read

Written By Young-rae Shin(https://github.com/lived1024)

IntelliJ

  1. File -> Project Structure
    First
  2. Artifacts -> JAR -> From modules with dependencies
    Second
  3. Default setting
    Third
    If you want to make executable jar
    Please check MANIFEST.MF path at Default setting
    default
    Change path! (java -> resources)
    change path

  4. A screen similar to the following is displayed
    Register artifacts
  5. Confirm Main-Class at MANIFEST.MF
    MANIFEST.MF
  6. Build -> Build Artifacts
    Build Menu
  7. First, Clean => Second, Build
    Build Popup
  8. Confirm JAR file in project base directory
    Jar File

Maven

  1. Install Maven
    The screen below can be seen after installation Maven Version
  2. Go to the project directory where you want to build module(“pom.xml” is located)
    Path
  3. Open console(like cmd, git-bash, terminal, etc…)
    Open console
  4. Start build : Use maven build command
    You need to study maven command.
      $ mvn clean package -Dmaven.test.skip=true
      $ mvn clean package spring-boot:repackage -Dmaven.test.skip=true
    

    Input build command

  5. If you see “BUILD SUCCESS”, it’s complete
    Build Success Build File Path

Add custom jar file to maven project

  1. Open pom.xml
  2. Add local repository or jar files!!
    if you want to add local repository in pom.xml
    <repositories>
      <repository>
        <id>local-repo</id>
        <name>local</name>
        <url>file://${project.basedir}/lib</url>
      </repository>
    </repositories>
    

    OR add local jar files in pom.xml like this

     <dependencies>
      <dependency>
        <groupId>org.chronotics</groupId>
        <artifactId>pandora</artifactId>
        <version>1.4-SNAPSHOT</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/lib/pandora.jar</systemPath>
      </dependency>
    
      //set scope(system) and systemPath(jar file's path)
      <dependency>
        <groupId>com.vcanus</groupId>
        <artifactId>pithos-nosql</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/lib/pithos-nosql.jar</systemPath>
      </dependency>
     <dependencies>
    

How to run jar file

  1. Go to the project directory where you want to run jar file located
  2. Open console
  3. Input command
     $ java -jar filename.jar
    

    Run jar command Run

Leave a comment