- Published on
Start a Java project with Maven manually (Based on Ubuntu)
- Authors
- Name
- Piggy DP
- @xiaozhudxiaozhu
public class Test {
public static void main(String[] arg) {
System.out.println("Hello, Java");
}
}
When I use Neovim with the JDTLS (Java Development Tools Language Server) for writing Java code, Neovim provides reminders like the following:
Test.java is a non-project file, only syntax errors are reported.
So I start a Java project with maven.
Install Maven
Update System Packages and install Maven, you can also use apt-get
sudo apt update && sudo apt upgrade -y
sudo apt install maven
mvn -v
Create a project manually
- create a empty folder
mkdir hello-maven
cd hello-maven
- create a
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>hello-maven</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
- create project structure
mkdir -p src/main/java/com/example
cd src/main/java/com/example
- just write a simple application
vim App.java
package com.example;
public class App {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
- Navigate to the project root directory and execute the Maven command to compile and build the project.
mvn clean install
mvn exec:java -Dexec.mainClass="com.example.App"