Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Raja Sekhar
JAR Generation
1 Answer(s)      2 years and 7 months ago
Posted in : Java Beginners


Hi,

I have done this code. Can u pls tell me how to create a jar for this in eclipse, this is only a single java file?

package com.dcp.ui;

import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.AdjustmentEvent; import java.awt.event.AdjustmentListener; import java.io.File; import java.io.FilePermission; import java.io.FilenameFilter; import java.io.IOException; import java.sql.Array; //import java.nio.file.Files; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollBar; import javax.swing.SwingUtilities; import javax.swing.filechooser.FileFilter;

import jxl.Cell; import jxl.Sheet; import jxl.Workbook; import jxl.biff.WorkspaceInformationRecord; import jxl.read.biff.BiffException; import jxl.write.Label; import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; import jxl.write.WriteException;

public class DcpRep //implements ActionListener { JLabel label = new JLabel(); private static void createAndShowGUI() { // make frame.. frame = new JFrame("Select"); frame.setDefaultCloseOperation(JFrame.EXITONCLOSE); frame.setBounds(20,30,700,700); frame.getContentPane().setLayout(null); jb = new JButton("Browse"); jb.setBounds(200, 250, 100, 50); frame.getContentPane().add(jb); jb2=new JButton("Generate"); jb2.setBounds(20, 20, 100, 50); frame.getContentPane().add(jb2); frame.setVisible(true); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {

                JFileChooser jf = new JFileChooser();
                /*FileFilter filt = new FileFilter() {

                    @Override
                    public String getDescription() {
                        // TODO Auto-generated method stub
                        return null;
                    }

                    @Override
                    public boolean accept(File arg0) {
                        // TODO Auto-generated method stub
                        return false;
                    }
                };*/
                /*FilenameFilter filter = new FilenameFilter() {

                    @Override
                    public boolean accept(File arg0, String arg1) {
                        // TODO Auto-generated method stub
                        return false;
                    }
                };
                    filter.accept(file, "xls");*/
                    //filter.addExtension("xlsx");
                    //filter.setDescription("xls & xlsx sheets");
                    //jf.setFileFilter(filt);

                //jf.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                jf.setMultiSelectionEnabled(true);
                returnVal = jf.showOpenDialog(frame);
                File[] file = jf.getSelectedFiles();

                //      int returnVal2 = jf.showSaveDialog(frame);
                //  System.out.println(returnVal2);
                flength=file.length;
                System.out.println(file.length);

                for(int f=0;f<file.length;f++)
                {

                    Workbook workbook;
                    try {
                        workbook=Workbook.getWorkbook(file[f]);
                        Sheet sheet=workbook.getSheet(0);
                        r[f]=sheet.getRows();
                        c=sheet.getColumns();

                        //arr = new String[20][c][r[f]];


                        for(int i=0;i<c;i++)
                        {
                            for(int j=0;j<r[f];j++)
                            {
                                if(j<500)
                                {
                                Cell a=sheet.getCell(i,j);  
                                arr[f][i][j]=a.getContents();
                                //System.out.println(arr[f][i][j]);
                                }
                                else if((j>500)&&(j<1000))
                                {

                                    Cell b=sheet.getCell(i,j);  
                                    brr[f][i][j-500]=b.getContents();
                                    //System.out.println(brr[f][i][j-500]);

                                }
                                else if((j>1000)&&(j<1500))
                                {

                                    Cell c=sheet.getCell(i,j);  
                                    crr[f][i][j-1000]=c.getContents();
                                    //System.out.println(brr[f][i][j-500]);

                                }

                            }
                        }

                    }catch (BiffException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                }   



        }       });
    jb2.addActionListener(new ActionListener()
    {
        public void actionPerformed(ActionEvent e)
        {if(returnVal == JFileChooser.APPROVE_OPTION) 
        {
            WritableWorkbook generate;
            try {
                generate=Workbook.createWorkbook(new File("C:/Users/Jai Badri Vishal/Desktop/opt.xls"));
                WritableSheet st=generate.createSheet("First Sheet",0);
                for(int f=0;f<flength;f++)
                {

                    System.out.println("r is "+r[f]);
                    //System.out.println("Iteration no "+f);
                    for(int k=0;k<c;k++)
                    {
                        for(int j=y, x=0;j<y+r[f];x++,j++)
                        {
                            if(x<500)
                            {
                            Label label=new Label(k,j,arr[f][k][x]);
                            st.addCell(label);
                            //System.out.println(arr[f][k][j]);
                            }
                            else if((x>500)&&(x<1000))
                            {
                                Label label=new Label(k,j,brr[f][k][x-500]);
                                st.addCell(label);
                                //System.out.println(brr[f][k][j-500]);
                            }
                            else if((x>1000)&&(x<1500))
                            {
                                Label label=new Label(k,j,crr[f][k][x-1000]);
                                st.addCell(label);
                                //System.out.println(brr[f][k][j-500]);
                            }
                        }
                    }y=y+r[f];

                }
                generate.write();
                generate.close();   
            } catch (WriteException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IOException e2) {
                // TODO Auto-generated catch block
                e2.printStackTrace();
            }
        } }
    });    
}
public static void main(String[] args) {
    // start off..
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            createAndShowGUI();
        }
    });
}
static JButton jb,jb2;
static JFrame frame;
static int c,y,flength;
static int r[]=new int[20];
static String arr[][][]=new String[100][500][500];
static String brr[][][]=new String[100][500][500];
static String crr[][][]=new String[100][500][500];
static File file,p;
static int returnVal;

}


Advertisement
View Answers

May 7, 2012 at 11:36 AM


A Jar file combines several classes into a single archive file. Basically,library classes are stored in the jar file. Through the given code you can create your own jar file.

import java.io.*;
    import java.util.jar.*;

    public class CreateJar {
      public static int buffer = 10240;
      protected void createJarArchive(File jarFile, File f) {
        try {
          byte b[] = new byte[buffer];
          FileOutputStream fout = new FileOutputStream(jarFile);
          JarOutputStream out = new JarOutputStream(fout, new Manifest());

            JarEntry addFiles = new JarEntry(f.getName());
            addFiles.setTime(f.lastModified());
            out.putNextEntry(addFiles);

            FileInputStream fin = new FileInputStream(f);
            while (true) {
              int len = fin.read(b, 0, b.length);
              if (len <= 0)
                break;
              out.write(b, 0, len);
            }
            fin.close();

          out.close();
          fout.close();
          System.out.println("Jar File is created successfully.");
        } catch (Exception ex) {}
      }
      public static void main(String[]args){
        CreateJar jar=new CreateJar();
        File folder = new File("c:/");
          File files = new File("c:/DcpRep.java");
        File file=new File("c:/Example.jar");
        jar.createJarArchive(file, files);
      }
    }


Related Tutorials/Questions & Answers:
JAR Generation
JAR Generation  Hi, I have done this code. Can u pls tell me how to create a jar for this in eclipse, this is only a single java file? package com.dcp.ui; import java.awt.BorderLayout; import java.awt.Color; import
JAR Generation
JAR Generation  Hi, I have done this code. Can u pls tell me how to create a jar for this in eclipse, this is only a single java file? package com.dcp.ui; import java.awt.BorderLayout; import java.awt.Color; import
Advertisements
pdf generation.
pdf generation.  i want to generate the data which is stored in mysql data base in pdf format with php. how i will do
generation - Maven
generation  I have 2 config files to a file "monappli.properties" and a file "log4j.xml" the problem is that I was asked to generate the JAR files and two outside the JAR! I do not know how outsourced both files Help
Barcode generation
Barcode generation  hi, I am working on a project where there is a alias no. with symbology EAN-13 for generation of barcode... now i have to write the logic for one item no if their are two or more quantities it should
report generation using jsp
report generation using jsp  report generation coding using jsp
report generation - EJB
report generation   how to create the report in java
PDF Generation for unicode characters
PDF Generation for unicode characters  Hi, How a PDF file having unicode characters is generated in JSP
jar file
jar file  how to create a jar file in java
jar file
jar file  steps to create jar file with example
jar file
jar file  jar file where it s used
jar filw
jar filw  how can i run window based program using jar file
JAR FILE
JAR FILE  WHAT IS JAR FILE,EXPLAIN IN DETAIL?   A JAR file... and applications. The Java Archive (JAR) file format enables to bundle multiple... link: Jar File Explanation
quotion on .jar
quotion on .jar  in realtime where we use .jar class files.   A Jar file combines several classes into a single archive file. Basically,library classes are stored in the jar file. For more information,please go through
jar file
jar file  how to run a java file by making it a desktop icon i need complete procedur ..through cmd
Table generation error - EJB
Table generation error  Hi friends I am using EJB3.0 with sun java system application server 9.1 with postgresql database. Actually when i make an EJB it gives the following exception and doesnt generate any table
Runnable JAR
Runnable JAR  How to create runnable JAR file in eclipse ? Please provide me step by step demo... I am windows 7 user. I have made one jar file but when I double click it,it doesn't run. Why so
Runnable JAR
Runnable JAR  How to create runnable JAR file in eclipse ? Please provide me step by step demo... I am windows 7 user. I have made one jar file but when I double click it,it doesn't run. Why so
Hibernate generation Id to postgreSQL
Hibernate generation Id to postgreSQL  Hi, I'm trying to implement a id generator in Hibernate, but I'm having a problem. Hibernate doesn't seems to reset the counting when the id is generated. For example: 1 - In PostgreSQL I
Automatic primary Generation in Hibernate - Hibernate
Automatic primary Generation in Hibernate   Hi, Ow primary key is generated automatically in hibernate.give me sample code.Thank u
Play framework dynamic form generation
Play framework dynamic form generation  I want to generate dynamic forms using play framework can any one give me some idea about dynamic form generation using play framework
Running Jar file in Windows
Running Jar file in Windows  Running Jar file in Windows
Extract Jar File
Extract Jar File  How to extract jar file?   Hi Please open the command Prompt and to the jar file and write the command jar -xvf JaraFileName.jar
Structs jar files
Structs jar files  please Post required jar files for structs. Thanks, L.Mahesh Kumar
servlet (tomcat server) and jar
servlet (tomcat server) and jar  how to create a jar file and where to place the jar file in tomecat server
jar file - Java Beginners
jar file  jar file When creating a jar file it requires a manifest... options in jar file. What is Jar File? JAR files are packaged in the zip format  What is Jar File?JAR files are packaged in the zip format making
quqtion on jar files
quqtion on jar files  give me realtime examples on .jar class files   A Jar file combines several classes into a single archive file. Basically,library classes are stored in the jar file. For more information,please go
org.apache.commons.collections15.Transformer jar file
org.apache.commons.collections15.Transformer jar file  Dear, Please can you provide me the link for the following jar file: import org.apache.commons.collections15.Transformer; tahnks too much
pom.xml local jar
pom.xml local jar  Hi, I have placed one jar file in the WEB-INF/lib folder now I wan't to use this jar in the maven build and test phases. How to use this jar file? Thanks
jar file with html
jar file with html  I have a jar file. On double click it shows an applet page. Please tell me how to connect that applet into html or jsp page
Adding Jar into Eclipse
Adding Jar into Eclipse  Hi, Please provide Step by step procedure to add jar, tld files and configurations in Eclipse Helios version and i am using Jboss5. Thanks&Regards, Shiva s
Advertisements
 

 

 

DMCA.com