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/)
相关推荐
帮帮志14 分钟前
idea整合maven环境配置
java·maven·intellij-idea
qq_339282232 小时前
centos中libc.so.6No such file的解决方式
linux·运维·centos
leoufung2 小时前
ECPF 简介
linux·网络·kernel
在肯德基吃麻辣烫3 小时前
Netdata在Ubuntu环境下的安装与配置:构建实时系统监控与性能分析平台
linux·运维·ubuntu
愚戏师4 小时前
Linux复习笔记(六)shell编程
linux·笔记·shell
大胆飞猪4 小时前
Linux操作系统--进程间通信(system V共享内存)
linux
LunarCod5 小时前
Ubuntu使用Docker搭建SonarQube企业版(含破解方法)
linux·运维·服务器·ubuntu·docker·开源·sonarqube
betazhou5 小时前
基于Linux环境实现Oracle goldengate远程抽取MySQL同步数据到MySQL
linux·数据库·mysql·oracle·ogg
什么半岛铁盒5 小时前
Linux信号的保存
linux·运维·网络
百锦再5 小时前
大数据技术的主要方向及其应用详解
大数据·linux·网络·python·django·pygame