maven 项目示例

devtools/2024/9/24 4:22:53/

maven 项目

<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><properties><maven.compiler.source>7</maven.compiler.source><maven.compiler.target>7</maven.compiler.target></properties><modelVersion>4.0.0</modelVersion><groupId>com.example</groupId><artifactId>my-project2</artifactId><packaging>jar</packaging><version>1.0-SNAPSHOT</version><name>my-project2</name><url>http://maven.apache.org</url><dependencies><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.26</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version><scope>test</scope></dependency></dependencies><build><plugins><!-- 使用 maven-dependency-plugin 插件 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-dependency-plugin</artifactId><version>3.2.0</version><executions><execution><id>copy-dependencies</id><phase>package</phase><goals><goal>copy-dependencies</goal></goals><configuration><!-- 将依赖复制到 JAR 文件的 lib 目录中 --><outputDirectory>${project.build.directory}/lib</outputDirectory></configuration></execution></executions></plugin><!-- 设置 maven-jar-plugin 生成 JAR 文件的 MANIFEST.MF 文件 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><version>3.2.0</version><configuration><archive><manifest><!-- 指定类路径为 lib 目录下的所有依赖 --><addClasspath>true</addClasspath><classpathPrefix>lib/</classpathPrefix><mainClass>com.example.App</mainClass></manifest></archive></configuration></plugin></plugins></build></project>

代码

java">package com.example;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;/*** Hello world!**/
public class App 
{public static void main( String[] args ){System.out.println( "Hello World!" );try{Class.forName("com.mysql.cj.jdbc.Driver");System.out.println("====");Connection connect=DriverManager.getConnection("jdbc:mysql://10.110.17.233/db","hq","123");System.out.println("====");Statement stmt=connect.createStatement();ResultSet rs=stmt.executeQuery("select * from data");while(rs.next())System.out.println(rs.getString(1)+"  "+rs.getInt(2)+"  "+rs.getString(3));connect.close();}catch(Exception e){ System.out.println(e);}}
}

执行命令`

mvn  clean
mvn compile
mvn  package
java -jar /home/hq/java/my-project2/target/my-project2-1.0-SNAPSHOT.jar

http://www.ppmy.cn/devtools/2634.html

相关文章

Apache Storm的详细配置

Apache Storm的详细配置主要涉及以下几个方面: Zookeeper配置:Apache Storm使用Zookeeper来进行协调和配置管理。你需要配置Zookeeper集群的连接信息,包括Zookeeper服务器的主机和端口。 Storm Nimbus配置:Nimbus是Storm的主节点,负责分配任务给各个工作节点。你需要配置N…

Rust常见陷阱 | 失效的可变性

Rust 作为一门系统编程语言,最大的卖点之一在于其内存安全的保证。这种保证很大程度上得益于其变量绑定(Binding)规则中的一项核心特性:不变性(Immutability)。然而,不当的使用不变性可能会导致一些编程陷阱。在本文中,我将详细探讨 Rust 编程中的不变性陷阱,并以丰富…

K8S哲学 - 常见的资源类型

资源类型 namespace kubectl apply 和 kubectl create kubectl apply是声明式的 和 kubectl create是命令式的对吗 deployment 和 job的区别 k8s 的 lable 的意义

js如何設置滾動到元素位置

在JavaScript中&#xff0c;你可以使用window.scrollTo()方法或元素的scrollIntoView()方法来设置滚动位置。这些方法允许你将页面滚动到特定的坐标或元素。 使用 window.scrollTo() window.scrollTo() 方法接受两个参数&#xff1a;x坐标和y坐标&#xff0c;分别代表水平滚动…

「探索C语言内存:动态内存管理解析」

&#x1f320;先赞后看&#xff0c;不足指正!&#x1f320; &#x1f388;这将对我有很大的帮助&#xff01;&#x1f388; &#x1f4dd;所属专栏&#xff1a;C语言知识 &#x1f4dd;阿哇旭的主页&#xff1a;Awas-Home page 目录 引言 1. 静态内存 2. 动态内存 2.1 动态内…

大数据行业英语单词巩固20240413

Integration - 整合 Example: The integration of new software into our system will improve efficiency. 示例&#xff1a;将新软件集成到我们的系统中将提高效率。 Automation - 自动化 Example: Automation of repetitive tasks can save time and reduce errors. 示例&a…

WebApis知识总结以及案例(续3)

综合案例 小兔鲜页面注册 分析业务模块 发送验证码模块 用户点击之后&#xff0c;显示05 秒后重新获取 时间到了&#xff0c;自动改为重新获取 //1.发送短信验证码模块const codedocument.querySelector(.code)let flagtrue//通过一个变量来控制 节流阀 // 1.1 点击事件co…

【Linux】文件描述符——万字详解

目录​​​​​​​ 前言 预备知识 复习C语言的文件接口 写方式打开文件 追加方式打开文件 读方式打开文件 系统的文件接口 open close write read 文件描述符 0 & 1 & 2 理解文件描述符 文件描述符的分配规则 重定向的本质 dup2 理解Linux下一切…