当前位置: 首页 > news >正文

maven项目打包成sdk后在别的项目使用

创建sdk项目

关键在于maven install和在pom文件中定义好groupId、actifactId、version。

写简单的两个类

判断回文

public class StringValidator {/*** 检查给定的字符串是否为回文。* 回文是指正读和反读都一样的字符串(忽略空格、大小写)。** @param str 要检查的字符串,可能为 null。* @return 如果字符串是回文,则返回 true;否则返回 false。*/public static boolean isPalindrome(String str) {if (str == null) {return false;}String clean = str.replaceAll("\\s+", "").toLowerCase();int length = clean.length();for (int i = 0; i < length / 2; i++) {if (clean.charAt(i) != clean.charAt(length - 1 - i)) {return false;}}return true;}}

首字母大写

public class StringFormatter {/*** 将输入字符串转换为标题格式,即每个单词首字母大写,其余字母小写。* 如果输入字符串为 null 或空字符串,则直接返回原字符串。** @param input 要转换的字符串,可能为 null。* @return 转换后的标题格式字符串。*/public static String toTitleCase(String input) {if (input == null || input.isEmpty()) {return input;}StringBuilder titleCase = new StringBuilder();boolean nextTitleCase = true;for (char c : input.toCharArray()) {if (Character.isSpaceChar(c)) {nextTitleCase = true;} else if (nextTitleCase) {c = Character.toTitleCase(c);nextTitleCase = false;} else {c = Character.toLowerCase(c);}titleCase.append(c);}return titleCase.toString();}}

pom和打包

定义好

<groupId>com.kenyi</groupId>
<artifactId>sdkDemo</artifactId>
<version>1.0-SNAPSHOT</version>

还有打包的maven插件

    <build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.11.0</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin></plugins></build>

完整的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.kenyi</groupId><artifactId>sdkDemo</artifactId><version>1.0-SNAPSHOT</version><name>kenyi SDK demo</name><description>A simple SDK demo</description><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><java.version>1.8</java.version></properties><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.11.0</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin></plugins></build></project>

打包用maven的install插件即可,会自动打包安装到本地的maven仓库中
在这里插入图片描述
在这里插入图片描述

使用sdk

在另一个项目中的pom添加依赖

        <dependency><groupId>com.kenyi</groupId><artifactId>sdkDemo</artifactId><version>1.0-SNAPSHOT</version></dependency>
package com.kenyi.demo.common;import com.kenyi.sdk.common.StringFormatter;
import com.kenyi.sdk.common.StringValidator;/*** @author BIGSHU0923* @since 2025/6/30 22:51*/
public class StringUtils {public static void main(String[] args) {// 使用SDK中的功能String title = StringFormatter.toTitleCase("hello world");// 输出: Hello WorldSystem.out.println(title);// 输出: Is palindrome: trueboolean isPal = StringValidator.isPalindrome("madam");System.out.println("Is palindrome: " + isPal);}}

结果
在这里插入图片描述

http://www.xdnf.cn/news/1284337.html

相关文章:

  • 企业级高性能WEB服务器Nginx
  • 编程技能:递归
  • B 树与 B + 树解析与实现
  • SSE流式输出分层与解耦、用户自动结束语错误处理
  • 【13-向量化-高效计算】
  • 【Redis的安装与配置】
  • 高性能Web服务器
  • CSS预处理器之Sass全面解析与实战指南
  • HTML应用指南:利用GET请求获取全国一加授权零售店位置信息
  • C5.3:发射极偏置和LED驱动电路
  • 【07-AGI的讨论】
  • 使用纯NumPy实现回归任务:深入理解机器学习本质
  • golang 基础案例_01
  • Redis 01 数据结构
  • Pytest项目_day11(fixture、conftest)
  • 【PyTorch学习笔记 - 01】 Tensors(张量)
  • C++11的历史和统一的初始化列表
  • Linux中配置DNS
  • Day01_QT编程20250811
  • MaixPy开发环境简介
  • vscode新建esp32工程,没有sample_project怎么办?
  • lesson35:数据库深度解析:从概念到MySQL实战学习指南
  • html转成markdown(1.0.0)
  • 朝花夕拾(二)-------python中字符串的3种插值方法/(函数)
  • 【openEuler构建测试环境或部署嵌入式系统】openEuler生态扩容新路径:内网穿透工具cpolar助力多场景落地
  • 【牛客刷题】REAL809 转化
  • Redis RDB和AOF 流程、优缺点详细介绍
  • 【k8s】k8s安装与集群部署脚本
  • C++高频知识点(二十一)
  • wrap cpp variant as dll for c to use