Skip to content

Instantly share code, notes, and snippets.

@IdelsTak
Last active October 12, 2023 06:29
Show Gist options
  • Save IdelsTak/c0528e8046ff0856e4e29feaa1a582df to your computer and use it in GitHub Desktop.
Save IdelsTak/c0528e8046ff0856e4e29feaa1a582df to your computer and use it in GitHub Desktop.

Revisions

  1. IdelsTak revised this gist Oct 12, 2023. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions simple-java-maven-project.md
    Original file line number Diff line number Diff line change
    @@ -26,10 +26,11 @@ cd /path/to/your/project/directory
    Run the following Maven command to generate a basic Java project using the default archetype:

    ```shell
    mvn archetype:generate -DgroupId=com.example
    \-DartifactId=my-java-project
    \-DarchetypeArtifactId=maven-archetype-quickstart
    \-DinteractiveMode=false
    mvn archetype:generate
    \-DgroupId=com.example
    \-DartifactId=my-java-project
    \-DarchetypeArtifactId=maven-archetype-quickstart
    \-DinteractiveMode=false
    ```

    Replace `com.example` with your desired Group ID and `my-java-project` with your desired Artifact ID.
  2. IdelsTak revised this gist Oct 12, 2023. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion simple-java-maven-project.md
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,10 @@ cd /path/to/your/project/directory
    Run the following Maven command to generate a basic Java project using the default archetype:

    ```shell
    mvn archetype:generate -DgroupId=com.example -DartifactId=my-java-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
    mvn archetype:generate -DgroupId=com.example
    \-DartifactId=my-java-project
    \-DarchetypeArtifactId=maven-archetype-quickstart
    \-DinteractiveMode=false
    ```

    Replace `com.example` with your desired Group ID and `my-java-project` with your desired Artifact ID.
  3. IdelsTak revised this gist Aug 24, 2023. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions simple-java-maven-project.md
    Original file line number Diff line number Diff line change
    @@ -43,6 +43,8 @@ cd my-java-project

    Open the `pom.xml` file in your project directory and add the following properties inside the `<properties>` section:

    > Note that you should change the `maven.compiler.source` and `maven.compiler.target` properties to suit the JDK version that you're running.
    ```xml
    <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
  4. IdelsTak revised this gist Aug 24, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion simple-java-maven-project.md
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ cd /path/to/your/project/directory
    Run the following Maven command to generate a basic Java project using the default archetype:

    ```shell
    mvn archetype:generate -DgroupId=com.example -DartifactId=my-java-project -DarchetypeArtifactId=maven-archetype-quickstart
    mvn archetype:generate -DgroupId=com.example -DartifactId=my-java-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
    ```

    Replace `com.example` with your desired Group ID and `my-java-project` with your desired Artifact ID.
  5. IdelsTak created this gist Aug 24, 2023.
    80 changes: 80 additions & 0 deletions simple-java-maven-project.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,80 @@
    # Creating a Simple Java Project Using Maven in Terminal

    In this tutorial, we will walk through the process of creating a simple Java project using Maven from the terminal.

    ## Prerequisites

    - Java Development Kit (JDK) installed on your system
    - Maven installed on your system

    ## Steps

    ### 1. Open Terminal

    Open your terminal or command prompt.

    ### 2. Create a Project Directory

    Navigate to the directory where you want to create your Java project using the `cd` command:

    ```shell
    cd /path/to/your/project/directory
    ```

    ### 3. Create the Maven Project

    Run the following Maven command to generate a basic Java project using the default archetype:

    ```shell
    mvn archetype:generate -DgroupId=com.example -DartifactId=my-java-project -DarchetypeArtifactId=maven-archetype-quickstart
    ```

    Replace `com.example` with your desired Group ID and `my-java-project` with your desired Artifact ID.

    ### 4. Navigate to the Project Directory

    Navigate into the newly created project directory:

    ```shell
    cd my-java-project
    ```

    ### 5. Configure Maven Properties

    Open the `pom.xml` file in your project directory and add the following properties inside the `<properties>` section:

    ```xml
    <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    ```

    These properties set the Java source and target versions to 1.8 and configure the source file encoding to UTF-8.

    ### 6. Build the Project

    Use Maven to clean and build your project:

    ```shell
    mvn clean install
    ```

    This command will compile your project, run tests, and package it into a JAR file.

    ### 7. Review the Output

    You should see output indicating that the build was successful and that tests were executed.

    ### 8. Explore the Project

    Inside your project directory, you'll find the source code under `src/main/java`, with a simple Java class named `App.java`.

    ### 9. Customize Your Project

    You can modify the source code in `App.java` and add more Java classes as needed.

    ## Conclusion

    You have successfully created a simple Java project using Maven from the terminal. By configuring Maven properties, you ensure compatibility and smooth build processes for your project. You can now continue developing your project, adding dependencies, and expanding its functionality.