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/)
相关推荐
暴风游侠1 小时前
linux知识点-内核参数相关
linux·运维·服务器·笔记
CAFEBABE 346 小时前
linux离线安装docker并启动
linux·docker·eureka
OnlyEasyCode7 小时前
快速上手!查看、拷贝、编辑、远程连接Linux命令
linux·运维·服务器
dualven_in_csdn7 小时前
UDP广播接收小优化
linux·运维·服务器
Xの哲學8 小时前
Linux二层转发: 从数据包到网络之桥的深度解剖
linux·服务器·算法·架构·边缘计算
石像鬼₧魂石8 小时前
Termux ↔ Windows 靶机 反向连接实操命令清单
linux·windows·学习
啃火龙果的兔子9 小时前
如何将D:\BaiduNetdiskDownload所有目录下的所有图片复制提取到D:\bacPic
linux·运维·服务器
FF-Studio9 小时前
RTX 5060 Ti Linux 驱动黑屏避坑指南:CUDA 13.1, Open Kernel 与 BIOS 设置
linux·运维·服务器·cuda
坐吃山猪9 小时前
BrowserUse14-源码-ScreenShot模块-整理
linux·数据库·python
Jelly-小丑鱼9 小时前
Linux搭建syslog日志服务器
linux·服务器·docker·日志服务器·syslog服务器