Sending parameter to main class function in jar

前端 未结 1 1761
伪装坚强ぢ
伪装坚强ぢ 2021-01-26 03:35

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

1条回答
  •  别那么骄傲
    2021-01-26 04:00

    In order to use classes and methods from another jar

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

    See: Adding Classes to the JAR File's Classpath

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

    See: Controlling Access to Members of a Class

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

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

    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.

    See: Java: when to use static methods

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

    See also:

    • how to use one jar that depends on another jar

    Update

    how to include libraries in java without using an IDE

    Adding External JARs to Eclipse Buildpath

    Adding Classes to the JAR File's Classpath (via command line)

    0 讨论(0)
提交回复
热议问题