将参数发送到jar中的主类函数 [英] Sending parameter to main class function in jar

查看:147
本文介绍了将参数发送到jar中的主类函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在该jar中创建了一个名为 GetOfferSoftware jar 文件,我有一个名为商品
的Main类,此商品类包含以下函数

i have make one jar file called GetOfferSoftware in that jar i have Main class called Offer and this Offer class contain following function

           getOffer(String name1,String name2){

           }//Offer class function

现在我想从另一个java程序调用此函数GetOfferSoftware jar
所以我的问题是如何从另一个java类访问和发送参数到getOffer()函数。
伙计提前感谢

now i want to call this function from another java program that not related to GetOfferSoftware jar So my question is how to access and sent parameter to getOffer() function from another java class . Guys Thanks in advance

推荐答案

为了使用其他jar中的类和方法

In order to use classes and methods from another jar

1)您需要将它们包含在类路径中。实质上,您将它们添加为库/引用。

1) You need to include them in the classpath. In essence you add them as libraries/references.

请参阅:将类添加到JAR文件的类路径

2)有问题的方法需要具有与可见性相关的适当修饰符,例如不受保护或私密。

2) The method in question needs to have the appropriate modifiers related to visibility, e.g. to not be protected or private.

参见:控制对类成员的访问

- A)如果方法受到保护:您自己的jar / .class必须具有相同的包声明。

--A)If the method is protected: your own jar/.class must have the same package declaration.

- B)如果方法是 static ,你可以直接调用它。

--B)If the method is static you can directly call it.

3)如果方法不是 static ,则需要创建一个声明方法的类的新Object in,并将其调用。

3) If the method is not static you need to create a new Object of the class the method is declared in, and call it.

请参阅: Java:何时使用静态方法

Object whatever = new MyClass();
whatever.getOffer(paramsGoHere);

参见:

  • how to use one jar that depends on another jar

如何在没有java的情况下包含库使用IDE

how to include libraries in java without using an IDE

将外部JAR添加到Eclipse Buildpath

将类添加到JAR文件的类路径(通过命令行)

这篇关于将参数发送到jar中的主类函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆