gpt4 book ai didi

java - 如何在main中调用jar文件

转载 作者:行者123 更新时间:2023-12-02 04:50:34 24 4
gpt4 key购买 nike

我有很多 jar 文件,它们自己完成一些小任务。我希望创建一个带有菜单的主类并要求用户执行任务。如何从主类调用外部 jar 文件?使用系统调用?我不想重新制作所有 jar 文件以将它们合并到一个主程序中。

例如,我有这些 jar ,它们执行一项特定任务。这些很早以前就已经完成了。

myPrintToPrinter.jar 
mySendEmail.jar
myCheckBuffer.jar
myAuditTrail.jar

我想创建一个菜单:

1) Print to printer
2) SEnd email
3) ....

根据用户的选择,我调用每个 jar 文件。我相信我确实需要花钱才能调用它?

谢谢

最佳答案

一个好的方法是

1) create a folder with name lib
2) add all the required jar files there
3) Add the dependent jar files in the project (select from the lib folder,
this is a good practice to keep the jars within the project folder to avoid path
dependencies when you move the project).
4) Create your required class and perform all the checks (logic part) in the main function.

您甚至可以通过创建该创建的类的 RUNNABLE JAR 来制作最终的 jar。

关于java - 如何在main中调用jar文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29272708/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com