Possible to create a JAR file from within a java app?

Is it possible to create a jar file from within a java application?
Can it be done more elegantly than by spawning-off another
process with the Runtime and exec() portions of the api?
Thanks
Scott

Thanks! I was mislead by the API notes for java.util.jar:
The JarOutputStream class is used to write the contents
of a JAR file to any output stream.
I was looking for a class or method to make jar files.
Seems this is it ;)
Thanks
Scott

Similar Messages

  • Problem with creation of a jar file from inside a java program

    Hi,
    I am trying to create a jar file at runtime from within a java program.
    I am able to create a jar file just fine using:
    String[] jarArgs = new String[3];
    jarArgs[0] = "cvf";
    jarArgs[1] = "C:\temp\myjar.jar";
    jarArgs[2] = "C:\temp\this";
    sun.tools.jar.Main main1 = new sun.tools.jar.Main(System.out, System.err, "jar");
    main1.run(jarArgs);However, when I look at the jar it puts the absolute path to the files inside such as:
    C:\temp\this\is\my\package\Class.class
    instead of only this\is\my\package\Class.class
    When running the jar command from the command line it works just fine and I have the relative paths in my jar file.
    Does anyone have any experience with this and could help me out?
    Thanks in advance
    Edited by: mruf on Apr 11, 2008 1:51 AM

    Shouldn't jarArgs[2] = "-C C:\temp\this"

  • 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

  • Possible to create multiple pdf files from links?

    In Acrobat X Pro, is there a way to apply the option "create pdf file from link" to several links on the same website at once?.thanks

    About the closest you can get is to use the Tools > Document Processing > Web Capture > Append all links on page command, which will traverse the links and append them to your existing PDF that has been captured from a web site.

  • Creating windows .bat file from within an oracle .prc or .sql file

    I am currently converting a series of batch jobs on a windows server to use an Oracle db rather than a MS sql server db. In ms sql, I could call \mssql80\binn\isql and it allowed me to pass in .prc files and have a .bat file returned. the .bat file is then executed in the calling bat to set variable value returned in the sql call...
    I am thinking I can spool a bat file, however, i do not know how to populate this file with the literals and query values needed to create the bat file which sets values used for further processing in the original calling bat file...
    Does that make sense? any help is greatly appreciated.

    Hi,
    There can be various ways to do this.
    First and simple way is simply spooling out the batch file. Suppose you have a .sql file with all the queries, run the .sql from DOS prompt like this,
    c:\> sqlplus -s username/password@tnsname @mysqlfile.sql
    the contents of mysqlfile.sql can be,
    rem ---------------------
    set echo off feedback off head off
    spool c:\batch_files\mybatch.bat
    select 'start \w ' || win_app_name from mytable ;
    spool off
    rem ----------------------
    exit
    So, you can get the batch file created with desired name in desired directory. The '-s' mentioned in the sqlplus command is important.
    There is another difficult/tedious way, but that can give you exact output. With UTL_FILE package you can write an operating system file from pl/sql code, stored procedure/package. Its look more like C-language code, but is usefull. So, write a sql or stored procedure and create the batch file. For that matter, you can write any type of file, just you can write whatever you want to a file.
    Cheers

  • Creating an xml file from the Basic java Object

    how to create an XML file using the values available in the object with reference to an xsd or dtd file..
    (OR )
    is it possible to write the contents of an object to an xml file without knowing the dtd or xsd file .......

    how to create an XML file using the values available in the object with reference to an xsd or dtd file..
    (OR )
    is it possible to write the contents of an object to an xml file without knowing the dtd or xsd file .......

  • Cannot execute Microsoft HTML Help file from within Eclipse managed app.

    I took an easy solution and created a help system for a large Java application using the Microsoft HTML Help Workshop as the IDE. The Help System does exactly what the client wants, but when I tried to integrate it into the application I ran into a brick wall.
    I wrote a very small Java app to see if I could execute the compiled help file (RAS_Help.chm) under the simplest circumstances. The code, which runs fine under VJ++ throws the following exception when run from Eclipse
    e: java.io.IOException: CreateProcess: RAS_Help.chm error=193
    * Created on Mar 20, 2004
    * To change the template for this generated file go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    package pkgTesting;
    import java.io.*;
    * @author Owner
    * To change the template for this generated type comment go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    public class ExeTest {     
         public static void showHelp() {
              Runtime rt = Runtime.getRuntime();
              String prog = "C:\\SCA\\RAS_Help.chm";
              try {
                   rt.exec(prog);
              } catch (IOException e) {
                   System.err.println("e: " + e);
         public static void main(String args[]) {
              showHelp();
    I assume the problem is in launching .chm files, since if I change the program I want to execute from the RAS_Help.chm file to the Windows Solitare game (sol.exe) the program works like a charm with no errors thrown.
    Can anyone give me some guidence on this? If it is impossible to run the HTML Help file I created, I'd be ammenable to redoing it in some other package, if that would guarentee my being able to use it in the client's large application.

    Try this;-*/class OpenBrowser{
       final String WIN_ID = "Win";
    * @throws java.lang.Exception
       OpenBrowser(java.io.File file){
          if(isWindowsPlatform() ){
             try{
                Runtime.getRuntime().exec(tryCommand1()+file);
             }catch(Exception exc1) {
               try{
                   Runtime.getRuntime().exec(tryCommand2()+file);
                }catch(Exception exc2) {
                   try{
                      Runtime.getRuntime().exec(tryCommand3()+file);
                   }catch(Exception exc3) {
                      if(MainEditor.getOpenBrowserHelper() ) new OpenBrowserHelper(file);
          else {
             try{
                Runtime.getRuntime().exec(tryCommand3()+file);
             }catch(Exception exc4) { if(MainEditor.getOpenBrowserHelper() ) new OpenBrowserHelper(file); }
    * @return true if this is a Windows OS
       private boolean isWindowsPlatform(){
          String os = System.getProperty("os.name");
          if ( os != null && os.startsWith(WIN_ID))
             return true;
             return false;
    * @return String path /protocal to open the Internet Explorer browser
       private String tryCommand1(){
          return "C:\\Program Files\\Internet Explorer\\Iexplore.exe file://";
    * @return  String path /protocal to open the default browser
       private String tryCommand2(){
          return "start rundll32 url.dll,FileProtocolHandler file://";
    * @return  String path /protocal to open the default browser
       private String tryCommand3(){
          return "file://";
    }

  • How to use .dbf files zipped into a .zip file from within a java program

    i have a .zip file containing several .dbf files.
    the zip file is automatically downloaded regularly and data from the .dbf files is inserted into the database.
    how do i facilitate automatic extraction of a zip file or how do i fetch data from the .dbf file? (this cannot be done manually)
    anu.

    you could write a little polling class checking the zip file. you can use the java.util.jar package to extract the zip file (http://java.sun.com/docs/books/tutorial/jar/api/index.html). you could also use Jakarta ant (http://ant.apache.org/manual/index.html) to do this job (core task "zip") and call ant's target file on a regular basis (dependend on the OS you use, you can set os tasks/schedules).

  • Why aren't deployed jar files from forte for java CE recognized by iplanet server?

     

    At 09:33 AM 4/20/01, Rottier, Pascal wrote:
    Forte 4GL is:
    1) A language, TOOL (Compare to Java)
    2) An IDE (Compare to e.g. JBuilder or FJCE)
    3) A collaborative development environment, with central repository (Compare
    to ????)
    4) A distributed application server / object request broker (Compare to J2EE
    servers and/or CORBA)Let's not forget WebEnterprise, Express, and especially Fusion.
    I think, SUN is not al all interested in TOOL.If TOOL were just a language and had no market yet, you are probably
    right. But, not only is TOOL the key to the Forte environment, but it has
    an existing and profitable market. Sun still sells FORTRAN, after all, and
    continues to put money into ADE development for all its language
    products. The real kicker, though, is that I think iPlanet is very clear
    that Fusion, now iIS, is a very key product for them. There may be those
    who wish it were written in Java and who might lobby for doing a Java
    version, but it was clear at the conference that the iPlanet management
    recognize that Java just isn't up to the task at this point. It isn't as
    if all the iPlanet tools are actually written in Java, after all.
    They will only support them for as long as they need.Or, more likely, for as long as they make money.
    Now, in response to Microsofts .NET stratagy. We have yet to see how
    succesfull this will be, but I expect Microsoft to push this down the
    throats of developers and companies quite succesfully.Like they did DCOM?
    =========================================================================
    Thomas Mercer-Hursh, Ph.D email: [email protected]
    Computing Integrity, Inc. sales: 510-233-9329
    550 Casey Drive - Cypress Point support: 510-233-9327
    Point Richmond, CA 94801-3751 fax: 510-233-6950

  • Running .jar files from Java code

    Hi.
    I am designing a sort of platform to run some games which are saved in .jar files. Basically this platform is a menu from which the user can select the game which he/she wants to run. It also has the feature of adding new games.
    Is is possible to run the .jar file from within java code?
    Thanks for any help!
    Krt_malta

    Just list the jar in the classpath list and call the class in the jar.

  • Creating a JAR File for a program that depends on other JAR files

    Hi, I'm pretty new to this so it shouldn't be terribly hard to answer:
    I have a program which uses JGoodies. There are 2 JGoodies .jar files in the same directory as my program. So I compile it by doing:
    javac -extdirs . NameOfMyProgram.java
    First off, is this the best way to do it? Is there any way of 'calling' these JAR files from within NameOfMyProgram.java?
    Secondly, if I then try to run it by doing java NameOfMyProgram, it doesn't work; can't find the JGoodies stuff. I end up having to add the classpaths of the unzipped JGoodies directories.
    So I have 2 questions:
    1. How can I execute my file so that it reads from the JAR files, not the big expanded folders that I unzipped?
    2. How can I create a JAR file that reads the JGoodies files properly? Right now, I have a Manifest.txt file that looks like:
    Main-Class: NameOfMyProgram
    Class-Path: forms-1.0.5.jar
    Class-Path: looks-1.3.1.jar
    Thanks a lot for your help!

    - learn how to use mysql JDBC
    - pack JDBC driver only
    - remotely access your DB
    - set proper security level for your app

  • 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.

  • Creating an xml file from recordset

    Hi...
    XML newbie here - so.
    Is it possible to create and xml file from a recordset?
    I need to create a datafeed of our e-commerce products.
    Also, some of the db data contains HTML Code (product
    description field),
    how will this effect the xml file?
    Another problem is that my xml file needs to contain url's
    for the products
    and product images. My ASP pages contain these URL in hard
    code and then
    pull the actual file names from the db
    Hope that makes some sense
    Thanks for any help
    Andy

    Hi David
    Thanks for your help.
    I think it will have to be option 1 as i am using Access DB.
    I don't know how to go about it but will serach good old
    Google.
    Here is my recordset below, that pulls the required data from
    Access.
    The product and product image URL's need to be in the xml
    file but only the
    product image name and product id are in the database, e.g
    image name
    (imagename.jpg) productid (21)
    The actual URL's are hardcoded in my ASP pages, e.g <img
    src="products/medium/<%=(RSDetails.Fields.Item("Image").Value)%>"
    Not sure if this makes things any clearer :-|
    Thanks Again
    Andy
    <%
    Dim RSdatafeed
    Dim RSdatafeed_numRows
    Set RSdatafeed = Server.CreateObject("ADODB.Recordset")
    RSdatafeed.ActiveConnection = MM_shoppingcart_STRING
    RSdatafeed.Source = "SELECT Products.Product,
    Products.Description,
    Products.Image, Products.image2, Products.ListPrice,
    Products.Price,
    Products.xml_feed, Manufacturers.Manufacturer,
    Shipping.ShippingCost FROM
    Shipping, Products INNER JOIN Manufacturers ON
    Products.ManufacturerID =
    Manufacturers.ManufacturerID WHERE
    (((Products.xml_feed)=No));"
    RSdatafeed.CursorType = 0
    RSdatafeed.CursorLocation = 2
    RSdatafeed.LockType = 1
    RSdatafeed.Open()
    RSdatafeed_numRows = 0
    %>
    "DEPearson" <[email protected]> wrote in
    message
    news:[email protected]...
    > Andy,
    >
    > There are two ways you can create a xml file from a
    recordset
    >
    > 1. Is to code it using Server.CreateObject(XMLDOM)
    > 2. If you are using SQL server 2005, just request the RS
    returns as XML
    > data. using FOR XML AUTO after the where cause ( the
    best way with 2005
    > and
    > higher sql server)
    >
    > The db data containing HTML code should not effect your
    xml file, unless
    > it
    > is bad markup. You could wrap the data with
    <![CDATA[the data or html
    > markup, or javascript]]>
    >
    > If the url is a recordset field, then it will return
    with the xml data.
    > If
    > not you can create a storage procedure that will build
    your URL from the
    > data
    > in the database.
    >
    > It is best to use storage procedure (SP )for security
    reason when pulling
    > data
    > from a MS Sql server, make all calls to the database in
    a SP. Also be sure
    > to
    > validate the values in the querystrings before accepting
    them, check for
    > hack
    > code.
    >
    > David
    >

  • Creating a jar file

    Hello all. I am trying to create a jar file for a *"hello world"* program. I compiled the code using netbeans and created the jar file from the HelloWorld.class. I added the main class to the manifest with the following line
    Main-Class: helloworld.HelloWorld
    Ensured there was a carriage return just before the end of the file.
    When I run the program I get the following error:
    h1Exception in thread "main" java.lang.NoClassDefFoundError: helloworld/HelloWorld*
    Please help

    I tried the last command it produced this error
    *C:\Documents and Settings\oshonowo\My Documents\Projects\DOS>set JAVA_HOME=c:/Pr
    ogram Files/Java/jdk1.6.0_03
    C:\Documents and Settings\oshonowo\My Documents\Projects\DOS>set classpath=C:\Pr
    ogram Files\Java\jdk1.6.0_03\lib\;C:\Program Files\Java\jre1.6.0_03\lib\ext\QTJa
    va.zip;C:\Program Files\Java\jdk1.6.0_03\jre\lib;C:\Program Files\Java\jre1.6.0_
    03\lib;%CLASSPATH%;.;C:\Documents and Settings\oshonowo\HelloWorld\build\classes
    \helloworld\Hello.jar
    C:\Documents and Settings\oshonowo\My Documents\Projects\DOS>"c:/Program Files/J
    ava/jdk1.6.0_03\bin\java" helloworld.HelloWorld
    Exception in thread "main" java.lang.NoClassDefFoundError: helloworld/HelloWorld
    C:\Documents and Settings\oshonowo\My Documents\Projects\DOS>pause
    Press any key to continue . . .*
    Please help

  • Launching/executing files from within AIR

    Hi.
    Just wanted to know if I can launch files from within my AIR
    app...for instance I would like the user to click a button which
    then opens a Microsoft Word doc...the Word doc doesn't have to open
    in the AIR app, it can open on the desktop (Windows XP).
    Thanks for the help.

    Mike provided a good proof here:
    http://www.mikechambers.com/blog/2008/01/17/commandproxy-net-air-integration-proof-of-conc ept/
    HTH

Maybe you are looking for

  • How can I highlight text in iPages with a 'virtual' fluorescent marker

    How can I highlight text in iPages with a virtual fluorescent marker?

  • Apple monitor options for pismo?

    hi all, i'm thinking of getting an external monitor for my pismo - to give the lcd a rest and as an extended display for fcp etc. i was thinking of a 17" crt apple studio display - the clear backed ones - as it wouldn't bee too expensive and they loo

  • OS X Mavericks not downloading from app store

    When I try to download the free upgrade through the app store, nothing happens. OS X Mavericks shows in my purchases list and has the option to download but again, not happens. I have a Mid-2010 MacBook using Mac OS X Lion 10.7.5 Any ideas?

  • Large number of concurrent sessions

    What optimizations are used to provide a large number of concurrent sessions?

  • SolidWorks 2007 Files

    Hi, I just installed the trial version of Acrobat 3D. By reading some tech notes, I did a capture of a Solidworks 2007 assembly by doing a screenprint in the eDrawings viewer. When I eventually opened the assembly in 3D Toolbox, it came through as on