0

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

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

Robin
  • 36,233
  • 5
  • 47
  • 99
SURJA
  • 17
  • 7
  • Add `GetOfferSoftware.jar` to the other projects class path, import the `Offer` class into it call `getOffer` – MadProgrammer Jun 10 '13 at 10:34
  • There's just not enough information here. How are the two jars related? How is `getOffer` declared? etc., etc. – Aleks G Jun 10 '13 at 10:34
  • Can you show us the code snippet that you have tried? – Renjith Jun 10 '13 at 10:34
  • Actually there is only one jar that is GetOfferSoftware.jar and another is only java program called FinalOffer.java in oracle database and now i want to call and send parameter to Offer class (in GetOfferSoftware.jar) to retrieve related pdf's from database – SURJA Jun 10 '13 at 10:43
  • if getOffer method is public, i think it does not matter.. – Ahmad Azwar Anas Jun 10 '13 at 10:44
  • Obviously, if the visibility is `public` he only needs to add the .jar to his classpath. – Menelaos Jun 10 '13 at 10:46

1 Answers1

0

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:

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)

Community
  • 1
  • 1
Menelaos
  • 23,508
  • 18
  • 90
  • 155
  • Actually there is only one jar that is GetOfferSoftware.jar and another is only java program called FinalOffer.java in oracle database and now i want to call and send parameter to Offer class (in GetOfferSoftware.jar) to retrieve related pdf's from database – SURJA Jun 10 '13 at 10:44
  • u r right meewoK but i want to access this getOffer() function from another java program not through any jar, so how to import GetOfferSoftware.jar in that java program FinalOffer.java – SURJA Jun 10 '13 at 10:49
  • See: Adding External JARs to Eclipse Buildpath . You need to add also the `class` hosting the `getOffer` method as an import. e.g. `import org.whatever.Offer`. And if your method is not static call, `new offer().getOffer(paramsGoHere)`. If your method is static, just call offer.getOffer(paramsGoHere)`. Offer will be your class name. – Menelaos Jun 10 '13 at 10:55
  • Thank you frnd, i have FinalOffer class in oracle database and GetOfferSoftware.jar in oracle database and now i want to access that Offer class through FinalOffer so what i do, give me some code to implement this . – SURJA Jun 10 '13 at 10:58
  • Do u know how to call jar from oracle database – SURJA Jun 10 '13 at 11:21
  • Yes surely, I have implemented one project that is use to generate One final Pdf using several pdf according to user condition. for that i have develop one java desktop application and it works better. but my client have oracle apex and now i want to develop the same thing in oracle apex. for that i have use following logic , i will put that jar file in database and then i will send some parameter(user selection) to that jar main class and will generate pdf on logical directory. thats why i was confuse how to do that...if its possible then plese mail me u r email id on srdeshmukh786@gmail.com – SURJA Jun 10 '13 at 11:38
  • u dont know about this stuff. and plz mail me u r email id – SURJA Jun 10 '13 at 11:57
  • I'm saying this is a completely different question. You should include all information in a question so that other users who want to ask the same thing will be able to find it. Once you make a new question I can answer :) . – Menelaos Jun 10 '13 at 12:01