ubuntu maven 使用示例

ubuntu maven 使用示例

一、基本使用

1、安装

shell 复制代码
sudo apt update
sudo apt install maven
mvn -v

2、创建项目

shell 复制代码
mvn archetype:generate -DgroupId=com.example -DartifactId=my-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
# -DartifactId=my-project 指定项目名称
# -DinteractiveMode=false:禁用交互模式
# -DarchetypeArtifactId=maven-archetype-quickstart:快速启动原型,用于创建一个简单的Java项目

3、编译并执行

shell 复制代码
mvn compile
java -cp target/classes com.example.App

4、执行

shell 复制代码
java -cp target/classes com.example.App

5、清空编译

shell 复制代码
mvn clean

二、导入包

maven仓库地址:Maven Repository: Search/Browse/Explore (mvnrepository.com)

一、到仓库内找到指定包的xml,放入到pom.xml文件中

shell 复制代码
    <dependency>
        <groupId>redis.clients</groupId>
        <artifactId>jedis</artifactId>
        <version>5.2.0-beta1</version>
    </dependency>

二、java问价内使用

java 复制代码
package com.example;
import redis.clients.jedis.Jedis; // 导包

/**
 * Hello world!
 *
 */
public class App 
{
    Jedis jedis = new Jedis("localhost", 6379); // 使用
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
}


// 包默认下载路径:/home/${user}/.m2/repository

三、相关错误解决

编译错误一:

shell 复制代码
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project my-project: Compilation failure: Compilation failure: 
[ERROR] Source option 5 is no longer supported. Use 7 or later.
[ERROR] Target option 5 is no longer supported. Use 7 or later.
[ERROR] -> [Help 1]

xml内添加

shell 复制代码
<properties>
    <maven.compiler.source>7</maven.compiler.source>
    <maven.compiler.target>7</maven.compiler.target>
</properties>](https://mvnrepository.com/)
相关推荐
likfishdn11 分钟前
Linux的文件与目录管理
linux·运维·服务器
chian-ocean30 分钟前
Linux 文件缓冲区:高效数据访问的幕后推手
linux·运维·服务器
加油=^_^=32 分钟前
【Linux】进程优先级 | 进程调度(三)
linux·运维·服务器
若云止水41 分钟前
Ubuntu 下 nginx-1.24.0 源码分析 - ngx_init_cycle 函数 - 详解(4)
数据库·nginx·ubuntu
吃汤圆的抹香鲸1 小时前
GoLand 安装包 绿色版 Win,Mac,Linux 包含IntelliJ全家桶 专为Go语言设计的集成开发环境(IDE)
linux·windows·macos·go·intellij-idea·go1.19
追寻光1 小时前
Cannot find a valid baseurl for repo: base/7/x86_64
linux
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
陆沙1 小时前
deepseek-r1-centos-本地服务器配置方法
linux·服务器·centos
吃汤圆的抹香鲸2 小时前
Rider 安装包 绿色版 Win/Mac/Linux 适合.NET和游戏开发者使用 2025全栈开发终极指南:从零配置到企业级实战
linux·运维·windows·sql·游戏·macos·.net
sz66cm2 小时前
Linux基础 -- ARM 32 位架构动态注入代码技术文档
linux·arm开发·架构