oqads

 photo adv_zpsn5opiawq.gif

Monday 21 November 2016

How to make a JAR file .? JAR फाइल कैसे बनाये

b:if cond='data:blog.url == "https:\\ankitmandliya.blogspot.com\2016\8\jarfile.html"'>

How to make a JAR file .? JAR  फाइल कैसे बनाये   

दोस्तों आज हम  सीखेंगे JAR  FILE  को कैसे बनाया जाता है ,वेसे आज की हमारी यह पोस्ट उन लोगो के लिए फायदेमंद है जो   TECHNICAL  BACKGROUND  से BELONG करते है ,आज   की यह पोस्ट हमे, ब्लॉग को daily  visit  करने वाली हमारी एक visitor ,(शेफाली ठाकुर )ने हमे SEND किया  है. तो दोस्तों  सबसे पहले तो ये जान लेते है JAR  का सामान्यतः पूरा नाम क्या होता है, इसका उपयोग कहा किया जाता है ,इसको उपयोग करने के फायदे और कैसे एक JAR  FILE  को बनाया जाता है..
JAR  FILE क्या होती है 
सामान्यतः JAR  का मतलब होता है JAVA  ARCHIVE (संग्रह) .. JAVA ARCHIVE  से मतलब JAVA   की CLASSES  का संग्रह.. JAR  CODE  को हम किसी भी SYSTEM  पर RUN कर सकते है , इसके लिए यह जरुरी नहीं है की उस SYSTEM पर JAVA  INSTALLED हो.अगर आपके COMPUTER SYSTEM  पर JAVA  INSTALL  नहीं हो तो भी भी आप JAR  CODE को आसानी से RUN कर सकते है .
JAR  FILE का उपयोग कहा किया जाता है 
JAR FILE  का उपयोग कहा किया जाता है यह जानने के लिए हम एक Example  ले कर  चलते है,  मान लीजिये आप एक softwere  डेवलपर है , आपने कोई प्रोजेक्ट अपने क्लाइंट के लिए तैयार किया है ,लेकिन आप चाहते है कि आपके द्वारा code किये गए program में कोई भी दूसरा डेवलपर कुछ भी  change  न कर पाए तो आप उसकी JAR  फाइल बना कर अपनी CODING  को HIDE कर सकते है ,छुपा सकते है . तो ज्यादातर DEVELOPER  अपने  CLIENT  को PROJECT की JAR  filE  ही बना कर देते है . JAR  फाइल को RUN  करने के लिए  आपने उस पर DOUBLE  CLICK  करना होता है , DOUBLE  CLICK  करते ही JAR  filE रन होने लगती है ..

JAR  filE को कैसे बनाये 
JAR  filE को बनाने के लिए आपने अपने प्रोग्राम  का  सबसे पहले एक PACKAGE बनाना होता है , PACAKGE  का USE  कर के हम दूसरे प्रोग्राम की CLASSES को CALL कर सकते है . PACKEGE  को बनाना बहुत आसान होता है ,

 

Syntax:  package <package_name>;

 

example: package less;


यहां less एक package का नाम है



 Now here a full code of addition of two 

numbers.Further we will make jar file of 

that program.


package less;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.StringTokenizer;
import java.util.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Graphics;
import java.awt.Font;
import java.util.Collections;
import java.util.HashMap;
class add extends JFrame
{
public static void main(String args[])
{
final JFrame jf1=new JFrame("Addition of two numbers");
jf1.setSize(600,600);
jf1.setVisible(true);
JPanel panel1=new JPanel();
jf1.add(panel1);
panel1.setBackground(Color.gray);
final JLabel l1=new JLabel("Enter no 1");
final JTextField t1=new JTextField(5);
final JLabel l2=new JLabel("Enter no 2");
final JTextField t2=new JTextField(5);
final JLabel l3=new JLabel();
panel1.add(l1);
panel1.add(t1);
panel1.add(l2);
panel1.add(t2);
panel1.add(l3);
final JButton jb=new JButton("ADD");
panel1.add(jb);
jb.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
int n1=Integer.parseInt((t1.getText()));
int n2=Integer.parseInt((t2.getText()));
int n3=n1+n2;
String s1=String.valueOf(n3);
l3.setText(s1);
}
});
}
}

In our case  program name is add.java,so,we will compile and run that code and after that make jar file.
As I have saved my program in e:\more\add.java.so,in command prompt I move on to e:\more.After that complile the code as normally other java code compile but our program inside package that’s we provide –d (destination) where package folder should make.package(folder) less will automatically will get create after writing compiling code.
Javac –d e:\more add.java

After that run code:
Java –cp e:\more less.add
We always run code by java and –cp is classpath where our class file created.In our case which is created inside e:\more.
So,its inside package that’s why we have to write <package-name>.<program-name>
Ex: less.add
Finally our code successfully run so we can make its jar file now,

For creating jar file first we have to make manifest.txt file which contain which is our main class(entry point,which contain main method)
Ex: echo Main-Class: e:\more >manifest.txt
E:\more is path where our main class located.
By this a manifest.txt file will get created which contain path of our main class.
Next step is to create jar ,
Syntax: Jar cfe <jar file name>  <package_name>.<main_class_name> <package_name>/*.class
#you can give any name to jar file and you can rename it after creating jar file.
Now run our jar file,
Syntax: java –jar <jar file name>
Now the jar file has create inside e:\more.
After successfully run :
On desktop addition is an jar file,which can easily run by double clicking on this icon.

The above whole process we have shown of single program(one .class file)
But when we have any project which contain many classes in that case also the same process will follow because all class file will inside a same package.
Always set write classpath(-cp)
Have funnnnnn….
Keep CodingJ


दोस्तों  अगर  आपको  पोस्ट  अच्छी  लगे  तो शेयर  करें , और  कंमेंट  में  अपना अनुभव   शेयर  करे !

आप  के  मन  में कोई  और  प्रश्न  या कोई QUERY  हो  तो आप मुझे कमेंट बॉक्स में कमेंट कर के बता  सकते है, या मुझे 7415587271 पर  WHATSAPP कर के भी बता  सकते हैं !! 


visit this shortlearner.com




 photo images 14_zpsaabtcc5x.jpg

click there

No comments:

Post a Comment

want to online earning click me