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/)
相关推荐
www_pp_16 分钟前
# Linux:开源的力量与应用
linux
(:满天星:)1 小时前
ELK技术栈全面解析与部署方案
linux·运维·服务器·elk·docker·centos
ViatorSun1 小时前
「解析」docker容器起服务,外部访问失败
linux·ubuntu·docker·容器·postman
梦游钓鱼2 小时前
Ubuntu:20.04中安装docker
ubuntu·docker·eureka
Mrdaliang2 小时前
【无标题】
linux·运维·服务器·网络
耳边轻语9992 小时前
欧拉系统 nginx ./configure: No such file or directory
linux·运维·服务器
浪小满2 小时前
怎样解决在ubuntu 22.04上QT: DataVisualization控件显示黑屏的问题
linux·qt·ubuntu
我要升天!3 小时前
Linux -- Ext系列文件系统介绍
linux·运维·服务器
山岚的运维笔记3 小时前
如何将 MX Linux 的垂直任务栏面板移到底部
linux·运维·服务器·mx linux·任务栏面板
MrGaomq3 小时前
软件测试用例(二)
linux·c语言·c++·经验分享·笔记·测试用例