ubuntu maven 使用示例

本文详细介绍了在Ubuntu系统上使用Maven的基本步骤,包括安装、创建Maven项目、添加依赖、编译和执行代码,以及处理编译时的版本兼容性问题。
摘要由CSDN通过智能技术生成

ubuntu maven 使用示例

一、基本使用

1、安装

sudo apt update
sudo apt install maven
mvn -v

2、创建项目

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、编译并执行

mvn compile
java -cp target/classes com.example.App

4、执行

java -cp target/classes com.example.App

5、清空编译

mvn clean

二、导入包

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

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

    <dependency>
        <groupId>redis.clients</groupId>
        <artifactId>jedis</artifactId>
        <version>5.2.0-beta1</version>
    </dependency>

二、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

三、相关错误解决

编译错误一:

[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内添加

<properties>
    <maven.compiler.source>7</maven.compiler.source>
    <maven.compiler.target>7</maven.compiler.target>
</properties>](https://mvnrepository.com/)
  • 10
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值