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/)
相关推荐
qetfw1 小时前
Debian lftp FTP 客户端使用:登录、目录切换与文件传输
linux·运维·debian
神威难绷泪1 小时前
Linux应用软件编程:线程分离属性 互斥机制 同步机制 死锁
linux·开发语言·算法·线程
2401_862880821 小时前
Linux应用层开发 --- 管道
linux·运维·c语言
NJCloud1 小时前
OpenStack(四)——进阶篇之私有网络配置与块存储服务(Cinder)部署
linux·网络·云计算·openstack
raindayinrain1 小时前
深入理解Linux内核--ext文件系统,open/write/read/close执行流程,性能优化
linux·性能优化·文件系统·文件系统调用
jing.wang_20252 小时前
制作一个带用户操作界面的精简Linux操作系统
linux·服务器
沫璃染墨2 小时前
《从零入门Linux系统篇(三十二):文件篇·五——深入理解磁盘:从物理结构到LBA寻址》
linux·运维·服务器·系统架构·硬件架构
云计算磊哥@3 小时前
运维开发宝典064-CICD_Nexus3 搭建 maven 私服
运维·maven·运维开发
卓怡学长3 小时前
w175基于springboot校园二手物品交易平台
java·spring boot·spring·maven·intellij-idea
chen<>3 小时前
malloc 和 free 背后发生了什么?
java·linux·服务器·操作系统