jar包?
jar套件: 實作了特定功能的,java字節碼檔案的壓縮包。
本質上就是一個編譯後的java項目,打包成jar檔
log4j.jar , mysql-connection-8.01.jar等。
自己建立jar包,讓別人來用:
1.新java專案
2.創建實作了特定功能的類別
#3.將該專案產生為jar套件
4.將jar套件發佈出去,給別人使用
1.創建專案和驗證
1.1創建專案
創建專案名為dateUtil的project專案
#或:
#專案dateUtil建立完成:
1.3對應的程式碼
package com.aaa.util; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; /**日期转换工具类 * @author: XYT * @create-date: 2022/7/26 15:12 */ public class DateConvertUtil { /** 注释方法:/**+回车键 形参会被自动提取出来并加粗描黑。这就是为什么引用系统方法的时候,会有很多的说明 * 将字符串转为日期,默认格式为yyyy-MM-dd * @param strDate 字符串日期 * @return 返回转换的日期 */ public static Date getDate(String strDate){ //一个参数;对下方方法的一种封装;这种方式叫“语法糖”; return getDate(strDate,"yyyy-MM-dd"); //格式是默认的 getDate } /** * 将字符串转为日期类型 * @param strDate 字符串日期 * @param format 转换格式 * @return 返回转换的日期,转换失败返回null */ public static Date getDate(String strDate, String format){ //两个参数 SimpleDateFormat sdf=new SimpleDateFormat(format); //格式需要自己指定(设置) // try { //自动生成try-catch // return sdf.parse(strDate); // } catch (ParseException e) { // throw new RuntimeException(e); // } // } try { //课堂代码try-catch return sdf.parse(strDate); //注意:parse } catch (ParseException e) { e.printStackTrace(); //这里不一样 } return null; } /** * 将日期转为字符串,固定格式为yyyy-MM-dd * @param date 日期 * @return 返回转换的字符串 */ public static String getDate(Date date){ return getDate(date,"yyyy-MM-dd"); //格式是默认的 getDate } /** * 将日期转为字符串 * date 日期 * format 格式字符串 * 返回转换后的字符串 */ public static String getDate(Date date,String format){ //两个参数 SimpleDateFormat sdf=new SimpleDateFormat(format); //格式需要自己指定(设置) return sdf.format(date); //注意:format } }
package com.aaa.util; /** * @author: XYT * @create-date: 2022/7/26 16:02 */ public class StringUtils { /** * 判断字符串是否为空 * @param str * @return */ public static boolean isNullOrEmpty(String str){ return str==null || str.isEmpty(); //注意 == } }
驗證程式碼部分:
package com.aaa.test; import com.aaa.util.DateConvertUtil; import java.util.Date; /** * @author: XYT * @create-date: 2022/7/26 16:08 */ public class Test { //测试 public static void main(String[] args) { //日期转为字符串 System.out.println(DateConvertUtil.getDate(new Date())); //日期转为固定格式的字符串 System.out.println(DateConvertUtil.getDate(new Date(),"yyyy-MM-dd HH:mm:ss")); } }
測試結果:
選擇File中的Project Structure。
介紹Project Structure的工具列及具體功能:
以上是如何使用Java建立可被專案引用的JAR套件?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

JVM'SperformanceIsCompetitiveWithOtherRuntimes,operingabalanceOfspeed,安全性和生產性。 1)JVMUSESJITCOMPILATIONFORDYNAMICOPTIMIZAIZATIONS.2)c提供NativePernativePerformanceButlanceButlactsjvm'ssafetyFeatures.3)

JavaachievesPlatFormIndependencEthroughTheJavavIrtualMachine(JVM),允許CodeTorunonAnyPlatFormWithAjvm.1)codeisscompiledIntobytecode,notmachine-specificodificcode.2)bytecodeisisteredbytheybytheybytheybythejvm,enablingcross-platerssectectectectectross-eenablingcrossectectectectectection.2)

TheJVMisanabstractcomputingmachinecrucialforrunningJavaprogramsduetoitsplatform-independentarchitecture.Itincludes:1)ClassLoaderforloadingclasses,2)RuntimeDataAreafordatastorage,3)ExecutionEnginewithInterpreter,JITCompiler,andGarbageCollectorforbytec

JVMhasacloserelationshipwiththeOSasittranslatesJavabytecodeintomachine-specificinstructions,managesmemory,andhandlesgarbagecollection.ThisrelationshipallowsJavatorunonvariousOSenvironments,butitalsopresentschallengeslikedifferentJVMbehaviorsandOS-spe

Java實現“一次編寫,到處運行”通過編譯成字節碼並在Java虛擬機(JVM)上運行。 1)編寫Java代碼並編譯成字節碼。 2)字節碼在任何安裝了JVM的平台上運行。 3)使用Java原生接口(JNI)處理平台特定功能。儘管存在挑戰,如JVM一致性和平台特定庫的使用,但WORA大大提高了開發效率和部署靈活性。

JavaachievesPlatFormIndependencethroughTheJavavIrtualMachine(JVM),允許Codetorunondifferentoperatingsystemsswithoutmodification.thejvmcompilesjavacodeintoplatform-interploplatform-interpectentbybyteentbytybyteentbybytecode,whatittheninternterninterpretsandectectececutesoneonthepecificos,atrafficteyos,Afferctinginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginging

JavaispoperfulduetoitsplatFormitiondence,對象與偏見,RichstandardLibrary,PerformanceCapabilities和StrongsecurityFeatures.1)Platform-dimplighandependectionceallowsenceallowsenceallowsenceallowsencationSapplicationStornanyDevicesupportingJava.2)

Java的頂級功能包括:1)面向對象編程,支持多態性,提升代碼的靈活性和可維護性;2)異常處理機制,通過try-catch-finally塊提高代碼的魯棒性;3)垃圾回收,簡化內存管理;4)泛型,增強類型安全性;5)ambda表達式和函數式編程,使代碼更簡潔和表達性強;6)豐富的標準庫,提供優化過的數據結構和算法。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

記事本++7.3.1
好用且免費的程式碼編輯器