Making jar files using API

hello!
I m trying to make a jar file using the API. When the jar tool is used for the same manifest file, it is correctly written and an executable jar is created. When I use the API, the jar file is made but it is nor executable. Here is that part of code:
jar = new File(parent, jarName);
System.out.println("Executing jar command...");
//create jar file here
Manifest mf = new Manifest(new FileInputStream(manifest));
fos = new FileOutputStream(jar);
jos = new JarOutputStream(new BufferedOutputStream(fos), mf);
BufferedInputStream reader = null;
byte[] data = new byte[BUFFER];
int byteCount = 0;
for(int i = 0; i < fileNames.length; i++)
System.out.println("Adding " + fileNames);
FileInputStream fis = new FileInputStream(fileNames);
reader = new BufferedInputStream(fis, BUFFER);
JarEntry entry = new JarEntry(new ZipEntry(fileNames));
jos.putNextEntry(entry);
while((byteCount = reader.read(data,0,BUFFER)) != -1)
jos.write(data, 0, byteCount);
}//end while
reader.close();
}//end for
jos.close();//close jar output stream
fos.close();
I m sure someone will be kind and intelligent enough to solve the problem. Thank you!
Umer

A jar file is simply a Zip file. So the two API's are quite similar. First, you create a CRC - that is a way to make sure that the file isn't corrupted and that all the bytes are there (it's a polynominal algorithm that returns a number which is written in the Zip(Jar) file as well). Each entry is a file or directory. Before writing any data to the Zip(Jar) file, you have to write info on the actual file (like name, path, length etc). That's why you use putNextEntry(). Each file can have it's storing methods, although the most common is to use the "default" methods (built in the ZipOutputStream/JarOutputStream)
But in this example you set the storing methods on the entry. You use the setMethod() method to switch between either storing or compression (don't know why, but in this example you don't compress the file - you should). I myself don't use the setSize() and setCompressedSize() methods at all (and it works fine). Don't know exactly what are the implications of using them. Neither do I use the setCrc() method (If I think a little, I've only used this API once - I don't use it that much), but it's quite straightforward. It's used to check that the data is ok, and since the CRC number is the result of an algorithm, it needs to know the bytes of UNCOMPRESSED data: that's why you use crc.update() on the bytes. After that you actually write all the info set before to the Zip (Jar) file using putNextEntry(). But remember that a ZipEntry doesn't have any data. You'll have to write it yourself: thus the need for the write method: Here are two small programs I used for Zipping and Unzipping. Changing them to work for Jar files is extremely simple:
//Zip.java
import java.io.*;
import java.util.zip.*;
public class Zip
     public static void main(String[] arg)
          try
               if (arg.length < 3)
                    System.out.println("Usage: java Zip <0-9> <zip file> <file 1> [file 2] [file 3] ...");
                    System.exit(0);
               System.out.println("Compressing files into file " + arg[1]);
               ZipOutputStream out = null;
               try
                    out = new ZipOutputStream(new FileOutputStream(arg[1]));
               catch (FileNotFoundException ex)
                    System.out.println("Cannot create file " + arg[1]);
                    System.exit(1);
               try
                    out.setLevel(Integer.parseInt(arg[0]));
               catch (IllegalArgumentException ex)
                    System.out.println("Illegal compression level");
                    new File(arg[1]).delete();
                    System.exit(1);
               for (int i=2; i<arg.length; i++)
                    System.out.println("\tCompressing file " + (i-1));
                    FileInputStream read = null;
                    try
                         read = new FileInputStream(arg);
                    catch (FileNotFoundException ex)
                         System.out.println("\tCannot find file " + arg[i]);
                         continue;
                    out.putNextEntry(new ZipEntry(arg[i]));
                    int av = 0;
                    while ((av = read.available()) != 0)
                         byte[] b = new byte[av < 64 ? av : 64];
                         read.read(b);
                         out.write(b);
                    out.closeEntry();
                    read.close();
                    System.out.println("\tDone compressing file " + i);
               System.out.println("Done compressing");
               out.finish();
               out.close();
          catch (Exception e)
               new File(arg[1]).delete();
               e.printStackTrace(System.err);
And the unzipping app:
//UnZip.java
import java.io.*;
import java.util.*;
import java.util.zip.*;
public class UnZip
     public static void main(String[] arg)
          try
               if (arg.length < 1)
                    System.out.println("Usage: java UnZip <zip file> [to dir]");
                    System.exit(0);
               String dir = "";
               if (arg.length > 1)
                    dir = arg[1] + System.getProperty("file.separator");
                    File f = new File(arg[1]);
                    if (!f.exists()) f.mkdirs();
               System.out.println("Decompressing files from file " + arg[0]);
               ZipFile read = null;
               try
                    read = new ZipFile(arg[0]);
               catch (ZipException ex)
                    System.err.println("Zip error when reading file " + arg[0]);
                    System.exit(1);
               catch (IOException ex)
                    System.err.println("I/O Exception when reading file " + arg[0]);
                    System.exit(1);
               Enumeration en = read.entries();
               while (en.hasMoreElements())
                    ZipEntry entry = (ZipEntry) en.nextElement();
                    System.out.println("\tDecompressing file " + entry.getName());
                    FileOutputStream out;
                    try
                         out = new FileOutputStream(dir + entry.getName());
                    catch (FileNotFoundException ex)
                         System.err.println("\tCannot write down to file " + dir + entry.getName());
                         continue;
                    InputStream re = read.getInputStream(entry);
                    int nRead = 0;
                    for (byte[] buffer = new byte[1024]; (nRead = re.read(buffer)) != -1; out.write(buffer, 0, nRead));
                    out.close();
                    System.out.println("\tDone decompressing file " + entry.getName());
               read.close();
               System.out.println("Done decompressing files");
          catch (Exception e)
               new File(arg[1]).delete();
               e.printStackTrace(System.err);

Similar Messages

  • Adding jar file in my gerareted jar file using netbean 4.0

    Hi,
    I write an application de process XML file using JDOM. I add the JDom package jar file to my project and everything work fine. But when I generate, my project jar file using netbean 4.0, my generated jar, is not working with the XML files anymore. Everything seems like it didn't include the JDOM jar file?
    Thanks for any help to fix the problem.

    I find that you can not use command-line such as java -classpath add classpath
    it can not work, I use netBeans4.0 i don't whether because of netbeans or java itself.
    you can add classpath in jar's Manifest.mf file
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.6.2
    Created-By: 1.5.0_01-b08 (Sun Microsystems Inc.)
    Main-Class: chat.Main
    // add this line
    Class-Path: dir\*.jar //(jar file name)
    X-COMMENT: Main-Class will be added automatically by build

  • How to run .jar on linux & how to create .jar file using java?

    hi, may i know how to run .jar on linux & how to create .jar file using java? Can u provide the steps on doing it.
    thanks in advance.

    Look at the manual page for jar:
    # man jar
    Also you can run them by doing:
    # java -jar Prog.jar

  • Can i load a class in subdirectoy  inside a jar file using applet tag?

    hi every one.. thank you for reading ... i am really in dire need for the solution..
    my problem is that i have a jar file contianing a package which inturn contains my applet class...
    i am trying to access this applet class using a applet tag in html file. this html file is in same directory as the jar file. i am having no problems in windows but when i am doing this in linux apache server i was getting class not found exception. (already checked the file permissions). and when i am successful when using simple package directory instead of jar file . so gist of my quesition is "can i load a class in subdirectoy inside a jar file using applet tag in a html file"?

    When you tested in Windows were you using Internet Explorer? On Linux you will be using a different browser, usually Mozilla of some version, or Firefox. Note that the HTML tags for applets will be different between the browsers if you are using the object tag. Principally the classid value for the object tag will differ between Firefox and Internet Explorer.

  • How to run test cases in a jar file using junit?

    Hi,
    I want to run test cases in a jar file using junit and the jar file is not in the class path. I wrote the following code, but it does not work.
    import java.net.URL;
    import java.net.URLClassLoader;
    import junit.framework.TestResult;
    import junit.textui.TestRunner;
    public class MyTestRunner {
         public static void main(String[] args) throws Exception{
              URL url = new URL("file:///d:/case.jar");
              URLClassLoader loader = new URLClassLoader(new URL[]{url});
              loader.loadClass("TestCase1");
              TestRunner runner = new TestRunner();
              TestResult result = runner.start(new String[]{"TestCase1"});
              System.out.println(result.toString());
    }Any ideas?
    Thanks a lot.

    Wouldn't it just be easier to put it on the classpath? You're trying to, anyway, with a URLClassLoader, albeit in an entirely unnecessarily complicated way

  • Problem in making "jar" file

    Hi ,
    I have to compile , preverify and make jar file using a set of J2ME files.
    And i have completed the first 2 steps (compiling and preverifying).
    I used this code to make jar file:
    jar cvfm F:\Mobile_Magazine_IDE\xxx_test3\Magazine.jar F:\Mobile_Magazine_IDE\xxx_test3\src\MANIFEST.MF  -C  F:\Mobile_Magazine_IDE\xxx_test3\preveryclasses\  . -C F:\Mobile_Magazine_IDE\xxx_test3\src\images\  .
      boolean compile_n_print_output_to_console(String command){
        boolean isCompiled = false;
        try {
          txa_console_output.setText("");
          Runtime runtime = Runtime.getRuntime();
          Process proc = runtime.exec(command);
          InputStream stderr = proc.getErrorStream();
          InputStreamReader isr = new InputStreamReader(stderr);
          BufferedReader br = new BufferedReader(isr);
          String line = null;
          while ( (line = br.readLine()) != null)
            txa_console_output.append(line + new_line);
          int exitVal = proc.waitFor();
          //If this returns any value other than zero ... compilation failed
          if(exitVal!=0){
            call_error_message("Compilation failed ");
          //If this returns zero ... compilation is successful
          else if(exitVal==0){
            isCompiled = true;
            call_info_message("Build successful !");
        catch (Exception ex) {
          isCompiled = false;
          System.out.println(ex);
          com.zone.logger.LoggerClass.log_output(ex);
        return isCompiled;
      }The program is generating the jar file but it does not return a boolean value.
    I think it's because it has not completed the process.
    But no exception is shown.
    I used the same code to compile and preverify , and they work fine.
    And one more thing when i use the same source code and compile those using well known IDE it compiles and works without a problem.
    Can anyone tell me where i have done the mistake ?
    Thanks in advance !

    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • How to record .jar file using Java Protocol

    Hi,
    I Tried to record .jar using Java protocol by using HR Loadrunner 11.0 Version tool.
    Am unable to record the application.
    Can any one suggest me the process of recording .jar file using load runner?
    Thanks,
    Venkat

    Look at the manual page for jar:
    # man jar
    Also you can run them by doing:
    # java -jar Prog.jar

  • Append to jar file using java codings

    Hi,
    I have codings which could create jar file and write datas in it. but i need to append datas to existing jar file using java codings.Here i have attached my codings which will write datas to new jar file. when ever i use this my existing contents gets overritten. wat can i add to this to append.
    FileOutputStream stream = new FileOutputStream(archiveFile,true);// archive file is jar file name
         JarOutputStream out = new JarOutputStream(stream, new Manifest());
    JarEntry jarAdd = new JarEntry(tobeJar.getName()); // tobejar is a file to write in jar.
    jarAdd.setTime(tobeJar.lastModified());
                   out.putNextEntry(jarAdd);
                   // Write file to archive
                   FileInputStream in = new FileInputStream(tobeJar);
                   while (true) {
                   int nRead = in.read(buffer, 0, buffer.length);
                   if (nRead <= 0)
                   break;
                   out.write(buffer, 0, nRead);
                   out.closeEntry();
    out.close();

    JarInputStream in = new JarInputStream(new FileInputStream(oldJarName), true); // oldJarName is the JAR that contains all the files we want to keep
    JarOutputStream out = new JarOutputStream(new FileOutputStream(tempJarName)); // this is your "out" variable
    // copy the files from the old JAR to the new, but don't close the new JAR yet
    JarEntry inEnt;
    while ((inEnt = in.getNextJarEntry()) != null) {
      JarEntry outEnt = new JarEntry(inEnt); // copy size, modification time etc.
      byte[] data = inEnt.getSize();
      in.read(data); // read data for this old entry
      in.closeEntry();
      out.putNextEntry(outEnt);
      out.write(data); // copy it to the new entry
      out.closeEntry();
    // now write an entry for the file we want to append - this is the OP's code
    JarEntry jarAdd = new JarEntry(tobeJar.getName()); // tobejar is a file to write in jar.
    jarAdd.setTime(tobeJar.lastModified());
    out.putNextEntry(jarAdd);
    // Write file to archive
    FileInputStream in = new FileInputStream(tobeJar);
    while (true) {
    int nRead = in.read(buffer, 0, buffer.length);
    if (nRead <= 0)
    break;
    out.write(buffer, 0, nRead);
    out.closeEntry();
    // and *now* we close the new JAR file.
    out.close();
    // We then delete the old JAR file...
    new File(oldJarName).delete();
    // ... and rename the new JAR file to use the old one's name.
    new File(tempJarName).renameTo(new File(oldJarName));

  • Create BPEL jar file using Bpelc via Java classes

    HI,
    I am trying to create the BPEL files ( xyz.bpel, bpel.xml, xyz.wsdl etc.. ) on the fly using Java code... Once I create all these files, I create a packaged jar (Ex : bpel_xyz_v2006_10_17__37256.jar) file and deploy the same in the Bpel PM.
    Right now, in order to create the jar file, I am running the bpelc.bat file under bpel/bin and then using the IBPELDomainHandle, I am deploying the process.
    But my requirement is to create the jar file using java rather than executing the bpelc.bat file..
    Can you please give me pointers as to how to achieve the same?
    Thanks
    Pramod

    Actually, I had figured out the part of calling the Bpelc class, but initially I was trying to create an object of the class and was not able to do so. That was where I got stuck.
    Eventually, I did something like the code snippet below and it works fine and the jar file is created. Just fyi for anyone looking in the future.
    String[] setupValues;
    setupValues = new String[]{ "-home", "D:\\product\\10.1.3.1\\OracleAS_1\\bpel", "-rev",
    "1.0", };
    Bpelc.main(setupValues);
    Thanks
    Pramod

  • How can i rename a jar file using only java code

    i have tried everything i can think of to accomplish this but nothing works.

    ghostbust555 wrote:
    In case you geniuses haven't realized I said I tried everything I can think of not that I tried everything. So help or shut up I realize that I didn't try everything but if you can't figure it out either DO NOT POST.
    And the question is how can i rename a jar file using java code? As it says in the title. Read.I would tell you to use the File.renameTo method, but surely that would have been obvious, and you would have tried it already? But maybe you didn't. You were kind of lacking in details in what you tried.
    And yes, I am a genius. Just don't confuse "genius" with "mind-reader".

  • How to access the database jar file using the derby 10.2.1.6 database ?

    Hi,
    How to access the database jar file using the derby 10.2.1.6 database ?
    I have used like below. And i am getting the following the error:
    "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'org.apache.derby.jdbc.EmbeddedDriver'
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1136)"
    My context.xml file looks like this:
    <Context crossContext="true">
    <Resource name="jdbc/derby" auth="Container"
    type="javax.sql.DataSource" driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
    url="jdbc:derby:jar(\CalypsoDemo\database.jar)samples"
    username="xxx" password="xxx" maxActive="20" maxIdle="10"
    maxWait="-1"/>
    </Context>
    What could be the reason.?
    Any suggestions will be appriciated.
    Thanks in Advance,
    Gana.

    ya, I have restarted. Can you please tell me whether the path which i am giving is right or not in the context file?
    Thanks,
    Gana.

  • Load .JAR file using SQL Developer

    Hi,
    I have couple of .JAR files on my local machine which has to be loaded on to the oracle server (11g). I tried using the load Java functionality in the SQL Developer but realised one could load a java class only if you had the source code.
    Is my understanding correct or is there a way to load a JAR file using sql developer ?
    Thanks

    K,
    Thanks for the answer.
    Do you know if you have to restart oracle after loading .jar files ? I ask this because I am not aware if oracle/jvm automatically knows that the jar files have been uploaded.
    Thanks

  • Making Executable Jar file using java Application

    Following Program creates the jar file at specified location. but, I wonder why this file does not execute on double clicking on it, in spite of that the Manifest file contain correct main class file name
    //MakJar.java
    import java.io.*;
    public class MakJar
    public static void main(String[] args)throws IOException{
    Process p;
    String str="D:\\Himesh\\JFiles";
    try {
    BufferedWriter out = new BufferedWriter(new FileWriter(str+"\\mainClass.txt"));
    out.write("Main-Class: TestFrame\n");
    out.close();
    } catch (IOException e) {
    try
         p=Runtime.getRuntime().exec("cmd /c D:\\Java6\\jdk1.6.0\\bin\\javac.exe "+str+"\\TestFrame.java");
         p=Runtime.getRuntime().exec("cmd /c D:\\Java6\\jdk1.6.0\\bin\\jar cvmf "+str+"\\mainClass.txt "+str+"\\Demo.jar "+str+"\\*.class");
    catch(IOException e)
    System.err.println("Error on exec() method");
    e.printStackTrace();
    }

    Sir,
    On execute the jar using a "java -jar. . ." command. it gives the error--
    "Exception in thread "main" java.lang.NoClassDefFoundError : TestFrame"
    On Extracting the files from jar file made by the java program,i found that the manifist file ( containing the name of main class) and t the class file are included in the jar file.
    But if I make the jar file manually it works perfectly.I have even reinstalled the java but the problem persists
    Same thing happen if i use MS-DOS batch file.
    ??????If i put the batch file in the same directory and execute it The resulting jar file works,But
    ??????if the batch file is executed from outside the directory The resulting jar file fails execute.
    what should i do???

  • Problem in Creating a jar file using java.util.jar and deploying in jboss 4

    Dear Techies,
    I am facing this peculiar problem. I am creating a jar file programmatically using java.util.jar api. The jar file is created but Jboss AS is unable to deploy this jar file. I have also tested that my created jar file contains the same files. When I create a jar file from the command using jar -cvf command, Jboss is able to deploy. I am sending the code , please review it and let me know the problem. I badly require your help. I am unable to proceeed in this regard. Please help me.
    package com.rrs.corona.solutionsacceleratorstudio.solutionadapter;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.util.jar.JarEntry;
    import java.util.jar.JarOutputStream;
    import java.util.jar.Manifest;
    import com.rrs.corona.solutionsacceleratorstudio.SASConstants;
    * @author Piku Mishra
    public class JarCreation
         * File object
         File file;
         * JarOutputStream object to create a jar file
         JarOutputStream jarOutput ;
         * File of the generated jar file
         String jarFileName = "rrs.jar";
         *To create a Manifest.mf file
         Manifest manifest = null;
         //Attributes atr = null;
         * Default Constructor to specify the path and
         * name of the jar file
         * @param destnPath of type String denoting the path of the generated jar file
         public JarCreation(String destnPath)
         {//This constructor initializes the destination path and file name of the jar file
              try
                   manifest = new Manifest();
                   jarOutput = new JarOutputStream(new FileOutputStream(destnPath+"/"+jarFileName),manifest);
              catch(Exception e)
                   e.printStackTrace();
         public JarCreation()
         * This method is used to obtain the list of files present in a
         * directory
         * @param path of type String specifying the path of directory containing the files
         * @return the list of files from a particular directory
         public File[] getFiles(String path)
         {//This method is used to obtain the list of files in a directory
              try
                   file = new File(path);
              catch(Exception e)
                   e.printStackTrace();
              return file.listFiles();
         * This method is used to create a jar file from a directory
         * @param path of type String specifying the directory to make jar
         public void createJar(String path)
         {//This method is used to create a jar file from
              // a directory. If the directory contains several nested directory
              //it will work.
              try
                   byte[] buff = new byte[2048];
                   File[] fileList = getFiles(path);
                   for(int i=0;i<fileList.length;i++)
                        if(fileList.isDirectory())
                             createJar(fileList[i].getAbsolutePath());//Recusive method to get the files
                        else
                             FileInputStream fin = new FileInputStream(fileList[i]);
                             String temp = fileList[i].getAbsolutePath();
                             String subTemp = temp.substring(temp.indexOf("bin")+4,temp.length());
    //                         System.out.println( subTemp+":"+fin.getChannel().size());
                             jarOutput.putNextEntry(new JarEntry(subTemp));
                             int len ;
                             while((len=fin.read(buff))>0)
                                  jarOutput.write(buff,0,len);
                             fin.close();
              catch( Exception e )
                   e.printStackTrace();
         * Method used to close the object for JarOutputStream
         public void close()
         {//This method is used to close the
              //JarOutputStream
              try
                   jarOutput.flush();
                   jarOutput.close();
              catch(Exception e)
                   e.printStackTrace();
         public static void main( String[] args )
              JarCreation jarCreate = new JarCreation("destnation path where jar file will be created /");
              jarCreate.createJar("put your source directory");
              jarCreate.close();

    Hi,
    I have gone through your code and the problem is that when you create jar it takes a complete path address (which is called using getAbsolutePath ) (when you extract you see the path; C:\..\...\..\ )
    You need to truncate this complete path and take only the path address where your files are stored and the problem must be solved.

  • Including a DLL in JAR file (Comm API)

    Writing a little app that interfaces with serial port device using the communications API and I'd like to bundle it into an executable JAR. JBuilder will create the JAR for me fine, but the issue is with the win32com.dll file thats part of the comms API. I need to include this, I don't think its possible to include as part of the executable, but otherwise the DLL needs to be in the windows\system folder. Could I include the dll as part of the JAR archive and then extract it upon runtime? If so how would I go about this?
    Any help much appreciated.

    There is another option. Native libraries need to reside within the java.library.path location. As it turns out, if you, at runtime, grab this property and ADD your own location to it, then set it back in to the System.setProperty() call, it will NOT work. The only way to do it is the -Djava.library.path value that tjmaven suggested.
    However, if you read up on how a native library is found, it uses the ClassLoader.loadLibrary() which calls the protected findLibrary() method. You can therefore extend ClassLoader to find a path yourself.
    One way is to extend URLClassLoader since it has the protection/security stuff AND the ability to look in .jar files for you. Your custom loader is created by a "launcher" class in your .jar file. First, your luancher uses getClass().getProtectionDomain().getCodeSource().getLocation() to get the absolute location of the .jar file its executing within. From there, you open the jar and look for your native library, extract it using the JAR api to a location of your choosing. Now, you instantiate the custom classloader and using this custom loader instance you load the rest of your classes. The main .jar file contains two classes, the launcher and the custom classloader, and contains the native library if you wish to do it this way. The custom classloader, you specify a URL[] of "classpath" entries. You bundle up the rest of your source in a second .jar file that you pass to the URL[] when creating the custom classloader. It will find all your classes in the 2nd jar no sweat. You can even "reload" these classes on the fly by recreating the custom classloader instance if you so wish to add a sort of "reload" feature.
    Now, in your custom classloader, you override the findLibrary() and return the SAME STRING PATH that you used to unjar your native files to. This way, when the JVM asks your custom loader to load the library at some path, you return the right path to find the native files in.
    I haven't verified that this works just yet, but I will soon. Primarily, my plugin engine over at www.platonos.org will support the ability to place native libraries in plugins, allowing you to effectively wrap a native library use as a plugin. Not yet working, but we'll soon have it in place.

Maybe you are looking for

  • How to retrieve date from a set type in SAP CRM in BRF+ application

    Hi, Can anybody please let me know how can I retrieve date from a set type in SAP CRM to BRF+. I need to process the data in BRF+ and then send it back to CRM. Thanks. Regards Yogesh

  • Future Support of the G5's.

    Greetings to all! I'm considering to replace my three PC's (a Dual Opteron, a Dual Xeon, and a P4) with a single Quad G5. I don't doubt that these are wicked machines, but I've got a simple question about the future of the G5's. With the switch to In

  • Selection date

    Hi ALL I have a report in which, the end user has to select the date range..................for this i created parameters for the "from date" and the "to date". But when the report is displayed, it must give the monthly summary....................ie

  • Thinkpad R50e on Windows 7

    I recently upgraded my Thinkpad R50e from Windows XP pro to Windows 7. Does anybody know where can I find the drivers for the laptop. Appreciate any information. Thanks

  • I can't sync my iPad 3 with iTunes using the new Macbook Air

    When I connect my iPad 3 with its original cable to my new MacBook Air, the charge symbol in the iPad starts to blink and the iTunes keeps connecting and disconnecting the iPad (more than one time per second). I can sync my old iPhone 3GS with the ne