How do you create a jar file with txt and classes?

Hey, I'm trying to create code to create a jar file with a text file, but I can't figure out how to add the text file. Here is what I have so far:
try {
            // Name of jar file to write
            String archiveFile = "test.jar";
            Manifest jman = new Manifest();
            try {
                // Create a manifest from a file
                //InputStream fis = new FileInputStream("manifestfile");
                //Manifest manifest = new Manifest(fis);
                // Construct a string version of a manifest
                StringBuffer sbuf = new StringBuffer();
                sbuf.append("Manifest-Version: 1.0\n");
                sbuf.append("Ant-Version: Apache Ant 1.7.1\n");
                sbuf.append("Created-By: 1.5.0_19-137 (Apple Inc.)\n");
                sbuf.append("Main-Class: Main\n");
                sbuf.append("Class-Path: lib/swing-layout-1.0.3.jar\n");
                sbuf.append("X-COMMENT: Main-Class will be added automatically by build\n");
                // Convert the string to a input stream
                InputStream is = new ByteArrayInputStream(sbuf.toString().getBytes("UTF-8"));
                // Create the manifest
                jman = new Manifest(is);
            } catch (IOException e) {
            FileOutputStream stream = new FileOutputStream(archiveFile, true);// archive file is jar file name
            JarOutputStream out = new JarOutputStream(stream, jman);
            out.putNextEntry(new JarEntry("test.txt"));
            out.closeEntry();
            out.close();
        } catch (Exception ex) {
        }It creates the .jar file with the correct manifest but I can't get it to write the test.txt or anything else into the jar file.
-Gandolf
Edited by: GanMatt on Jun 18, 2009 8:18 AM
Edited by: GanMatt on Jun 18, 2009 8:19 AM

Alright, my question has changed. Here's the code:
try {
            // Name of jar file to write
            String archiveFile = "test.jar";
            Manifest jman = new Manifest();
            try {
                // Create a manifest from a file
                //InputStream fis = new FileInputStream("manifestfile");
                //Manifest manifest = new Manifest(fis);
                // Construct a string version of a manifest
                StringBuffer sbuf = new StringBuffer();
                sbuf.append("Manifest-Version: 1.0\n");
                sbuf.append("Ant-Version: Apache Ant 1.7.1\n");
                sbuf.append("Created-By: 1.5.0_19-137 (Apple Inc.)\n");
                sbuf.append("Main-Class: Main\n");
                sbuf.append("Class-Path: lib/swing-layout-1.0.3.jar\n");
                sbuf.append("X-COMMENT: Main-Class will be added automatically by build\n");
                // Convert the string to a input stream
                InputStream is = new ByteArrayInputStream(sbuf.toString().getBytes("UTF-8"));
                // Create the manifest
                jman = new Manifest(is);
            } catch (IOException e) {
            FileOutputStream stream = new FileOutputStream(archiveFile, true);// archive file is jar file name
            JarOutputStream out = new JarOutputStream(stream, jman);
            out.putNextEntry(new JarEntry("test.txt"));
            out.write("Hi".getBytes());
            out.flush();
            out.closeEntry();
            out.close();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this,ex.toString(),"BUG!",JOptionPane.INFORMATION_MESSAGE);
        }It creates the jar file with the txt file inside it, but I can't write "Hi" inside of the text file. Any ideas?
-Gandolf

Similar Messages

  • How do you create a jar file in JDeveloper 11.1.2.0.0

    How do you create a jar file in JDeveloper 11.1.2.0.0

    1) Select the project for which you would like to generate the jar.
    2) Right Click the selected right and select 'Project Properties'
    3) Select the 'Deployment' in the left tab.
    4) Click on 'New' to create a new deployment profile and in the popup dialog, select 'Jar File' profile type and provide the name.
    5) Press 'ok' to save the changes.
    6) Select the project and right click and select 'Deploy to' and select the jar profile name you have specified.
    The Jar library is generated and the full path to the library jar is shown in the log window.
    Thanks,
    Navaneeth

  • How can I create a jar file that will run automatically on double click

    all the jars I created run only from the command-line.
    how can I make it run by double-click on it?

    First you will need to associate .jar files with the javaw.exe program in order to just be able to double click on the jar and run it from within a windows explorer application. Next you will need to set the main class attribute of the manifest file. My understanding is that the value of this attribute is used by the launcher to know which class to load. In other words, which is your main application class. To specify this attribute open your manifest file in a text editor. You will find this file located within the jar at META-INF/MANIFEST.MF. Then, add the line,
    "Main-Class:<relative path to the main class>" However, remember not to add the .class extension to the end of the class name.
    In Windows 2000 you can associate jar files with javaw by finding a jar file in Windows Explorer and right clicking it. This will give you a context menu which should have an Open With... option (if you are not using Windows 2000 and don't see the 'open with' menu item, try holding down the shift button while right click on the file). Select the Open With... option, then, when the dialog appears highlight javaw and select the "Always use this program to open these files" checkbox. When you hit the OK button you should have all your jar files associated with the javaw process.
    Once you've done this, you should be able to double click on your jar file and run your application.
    Regards,
    Daniel Walsh

  • How do you convert a jar file into a java file,  ?

    how do you convert a jar file into a java file ?
    I am new to Java ,but have a little experience in C++ and Visual Basic.
    I want to edit and maybe create my own mobile games that are written or converted into jar files.
    At the moment I am using Java NetBeans , and Easy Java( the java pad).
    However the only solution I tried was to open the JAR file in winrar and see that its made up of png picture files,
    midi music files and class files. Unfortunately when I uncompressed the JAR file , there was NO java file to be seen and the JAVA editors Do not show the class file like a Java file. So why is there no extension Java file in the mobile JAR game ?

    801283 wrote:
    how do you convert a jar file into a java file ?You generally don't. There exist decompilers, but if you're meant to have the source, you should either have it because you are the author, or you should be able to get it from the author.
    I am new to Java ,but have a little experience in C++ and Visual Basic.Does that experience include turning .exe files into C++ code? Because that's the equivalent of what you're asking
    I want to edit and maybe create my own mobile games that are written or converted into jar files.Eh?
    Are you saying you want to take existing games and modify them? If the creators allow you to modify their source, then they'll provide you with that source (the .java files). If you're allowed to add things but not modify, you don't need .java files. Just documentation, which, again, the creators should be providing.
    Or are you saying you want to create your own games and distribute them in jar files? If so, there's no need to turn jars into .java.
    However the only solution I tried was to open the JAR file in winrar and see that its made up of png picture files,
    midi music files and class files. Unfortunately when I uncompressed the JAR file , there was NO java file to be seen and the JAVA editors Do not show the class file like a Java file. So why is there no extension Java file in the mobile JAR game ?Why would you expect there to be one?

  • How can I create a jar file

    Hello!
    How can a create a jar file?
    I want to run an application just clicking in a icon.
    How can I do this?
    Thanks a lot.
    K�tia.

    Get to the command prompt
    change directories to the directory where the main class resides.
    Open your text editor and type the following in it:
    Manifest-Version: 1.0
    Main-Class: NameOfMainClass //Just name without ".class"!!!
    Created-By: Your Name Here
    Save this file as whatever you want to name it with ".mf" as the extension.
    Then go back into the command prompt and type the following:
    jar cfm "NameOfJarFile".jar "NameOfManifestFile".mf *.class
    (without the quote marks of course)
    Hit "Enter"
    This will jar it up and make it executable.
    If you have any images associated with the program you can add them in the same way as above. Just add *.gif or *.jpg after the *.class portion.
    Good luck!
    LEEMAX I. T.

  • How Do I create Windows Form file in VS and add the form to my VS project?

    C#, How Do I create Windows Form file in VS and add the form file to my VS project by using C# code?
    I like to create a Windows Form file into my VS Win Form project by using C#. I have the path and the file name.
    I need a Win Form with FileName.cs, FileName.Designer.cs, FileName.resx, and FileName (as you see it VS by adding a Win Form manually by using VS)
    Rune Brattas

    You cannot create a Form from code at run time. 
    For one thing, the user running your application will, almost certainly, not have  a copy of Visual Studio to hand with which to build anything.  (Not that you actually need 'Studio at all; Notepad and csc.exe are all you actually
    need), but that's another story).
    You can do this with an awful lot of pain, using the innards of the compiler from iside your own program, compiling the new Form's source code on the fly and then executing the resulting assembly within your application.  IMHO, that's a simply terrifying
    prospect especially as the code you will be compiling will be on someone else's machine and over which you will have absolutely no control.  If you're lucky, they'll spell something wrong and it won't compile.
    The "usual" way to do this sort of thing is to create additional, "plug-in" forms as library assemblies and have your program load and execute these at run-time. 
    Regards, Phill W.

  • I'm so confused!! I just want to create interactive pdf files (with video and flash files), but this free trial version is confusing!! help!?!

    i'm so confused!! I just want to create interactive pdf files (with video and flash files), but this free trial version is confusing!! help!?!

    Thanks for your suggestions. I checked to see if the options you suggested were set incorrectly but they were set to sync all. This led me to think the problem was actually in the iphone. I re-initialized the iphone and did not allow the system to restore any of the previous settings. In essence, I forced the phone to reset to factory settings. Then my video podcasts started syncing. All is well now. I did notice that I had seven podcasts selected that were "HD" presentations, and as such, are not compatible with the iphone. I don't know if this had anything to do with my earlier situation, but now I'm getting the video podcasts automatically. I'm happy. It wasn't much fun forcing the iphone to forget all of my preferences and I'm still customizing the phone now several days later. I think I have everything working and back to normal except I haven't identified any of my email accounts as of yet. Thanks for your help.

  • How do you share thousands of pictures with text and captions outside of PSE?  (PSE 4)

    One of my dad’s retirement passions is family genealogy and old family pictures.  Several years ago I gave my family PSE 4.0 for Christmas so that we could each have backup copies of our dad’s pictures.  Usually once per year, I made backup copies of everything and emailed the DVDs to my brothers and sisters.  Everyone knows the basic PSE 4 functions and share our dad's enjoyment with the old family photos.
    My problem is that my dad is running out of pictures to scan.  He wants to “share” or “show” his photos with others so that he can “borrow” their photo albums in order to scan their photos.  He plans to attend a hometown high school reunion later this fall.  He hopes to "collect" photo albums from cousins and classmates.  I have been struggling with this for several days without any good ideas.
    The scanned pictures lack any text (added as a layer?) or captions.  Creating a slideshow (on my dad’s computer is slow).  Also, a slideshow doesn’t let others select individual pictures to save from the slide show
    He has old pictures pre-PSE 4 that allowed him to add captions directly to the picture when it was scanned.  I never liked this approach as it "destroyed" the actual picture but these old pictures are more easily shared as individual pictures.
    How do you share thousands of pictures with text and captions outside of PSE?  Can you save or export a composite picture with all the layers?
    Thanks in advance for your help and replies.

    I think it is one of the printer option screens that gives me the choice of tabbed 4x6. All of the choices specifiy HP or Other so I am pretty sure it is printer software that offers me this choice.
    Make sure your image has a 4x6 aspect ratio. I have been quite happy with the tabbed 4x6. Just need to remember to load the paper with the tab last.
    So, in elements you set to 4x6, in printer options you should be able to choose 4x6 tabbed paper.

  • How do you create a user defined functions  UDF and passing a value like a ID to GEt a Value.

    How do you create a user defined functions UDF and passing a
    value like a ID to GEt a Value.
    using a query.
    are there example.
    Thanks

    tons of examples at cflib.org - good place to start, even
    though many
    udfs there are a bit outdated in their code...
    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com

  • How do you execute a JAR file?

    I'm sorry this is so basic, but I honestly do not know how to do this nor can I find anything online here or anywhere via Google to help me with this one.
    I have a JAR file that I created on another machine using JDK 1.6.0 and NetBeans 5.5 on WinXP.
    I copied and pasted that JAR file over to my machine at home also using JDK 1.6.0 and NetBeans 5.5 on WinXP
    I put the exact directory name where the JAR file resides, "C:\Program Files\Java\jdk1.6.0\classes", in CLASSPATH and rebooted my machine.
    However, upon CD'ing to that directory and doing "java -classpath . GUI.jar", I get a "NoClassDefFoundError" when trying to do so.
    Furthermore, I was not sure how to use NetBeans to run the JAR file to execute the classes within.
    What did I do wrong? I'm so sorry this is so basic.
    Thanx
    Phil

    You are using netbeans to build your jar. Go to your project properties (right click on the project name and choose properties). Then select "Run" from the tree. You will find a text box "Main Class" there, put the name of the class in there that has your main() method, including full package if you have one. That is WITHOUT the .class extension.
    Build your jar, it will be placed in the dist directory of your netbeans project. You can now run it from netbeans itself if you want. If ever you want to run the jar from the command line on your home machine, just navigate to the directory with the jar file and execute this:
    java -jar yourjar.jarand you're off. If your runtime environment is propertly setup you can even execute the jar by simply double clicking on it from the windows explorer. No need to change the CLASSPATH variable at all, in fact it is ignored when executing a jarred application.
    Also a note: you do not need to reboot your machine when you change an environment property. Simply change them using my computer -> properties -> advanced tab -> environmental variables. If you have any command prompts open, close and reopen them so the properties are updated properly.

  • How can I create a exe file with a tab control on it that work´s ?

    I have a VI with many controls and indicators,these are spread on a tab control.This tab control works with out any problems but if i create a exe file then the tab control is fixed. How can I create a exe file so that the tab control on it work´s ?

    I have made a new Posting with the same question but this time I added a screenshot of the VI.
    Attachments:
    project7.1.jpg ‏129 KB

  • How can I create a jar file at a Unix systems?

    Hi there,
    how what's the command to create a jar file in Unix? I'm creating a zip file and then renaming it to jar, but it's size is smaller than the one when I use the WinZip tool at a Windows system.
    Thanks,
    Andre

    Oops,
    it very easy to do. Just use the jar -cvf command
    Andre

  • Jar file with JRE and lib's

    I'd like to create a jar file that also contains the JRE that I want to use as well as some libraries I'm using. Is that possible?
    I have created in the past a batch file that points to an specific JRE that I package with my classes in a directory. But this time I'd like to package it in the jar file as well.
    Thanks!

    I'd like to create a jar file that also contains the
    JRE that I want to use as well as some libraries I'm
    using. Is that possible?Not and run that JRE. You have to extract it from the jar and put it in a directory. On Windows, this will allow you to run only Java applications from the commandline (not applets or anything associated with a browser).
    I have created in the past a batch file that points
    to an specific JRE that I package with my classes in
    a directory. But this time I'd like to package it in
    the jar file as well.
    Thanks!

  • How can I create a zip file with LabVIEW?

    I would like to compress my data (ASCII format) to an archive.
    I use LVZlib.vi to compress and decompress data but I would like to be able to read the output file with a software archiver such as PowerArchiver/WinZIP.
    Someone knows how I can create a file compatible with zip or gz standard format, thanks !

    >> Yes but I have to install a special archiver (with ms-dos ommand line ability
    >> such as pkzip,arc,rar,arj...) on the computer where I install my LV application.
    Search for "gnu tools for windows" and get zip.exe, gzip.exe, bzip2.exe and others (even the source, if you like). These are about 50kB files that run in place (no installation) - easy to include in a distributed app. Oh, since I'm logged in I'll attach a couple, though I don't have the source on this machine).
    Attachments:
    bin.zip ‏67 KB

  • How do you create a wsdl file from a FM?

    Hello friends,
    Could some one please let me know how to create a wsdl file from a function module?
    I have gone up to the stage of creating webservice  and also released it for SOAP runtime using tranasaction code wsconfig.
    But I don't know how to proceed from there and create a wsdl file.
    Your help will be greatly appreciated.
    Tks
    Ram
    Edited by: Ram Prasad on Nov 18, 2008 4:44 PM

    I was able to solve the issue with a friends help. Here are the steps
    STEPS in CREATING WSDL file from a FM:
    1.Goto SE80 Create a package or select a package in which you want to create a web service.
    2.Right click and select Create -> Enterprise Serve/Web Service -> Web Service
    3.Follow the wizard steps answering all the questions until complete. This creates the service definition.
    4.Goto transaction code <WSCONFIG> and enter the service definition name you have created in previous step. Enter the same name in both u2018service definitionu2019 and u2018variantu2019 fields.
    5.Then click on Create button and save. This releases the webservice you created in to soap Runtime.
    6.Goto transaction <WSADMIN>
    7.Open the tree structure to see the webservice that you just released and click on the right most button (Globe shape).
    8.Select u2018Document Styleu2019
    9.You have now created the wsdl file for the FM.

Maybe you are looking for

  • Reduce file size with action wizard

    (German version below) Hey, I got two questions for action wizard in Acrobat XI Pro. I try to reduze file size of many PDFs using acion wizard. My tests worked fine but now I got some problems I try to explain now: 1. I add a directory with many subd

  • Minimum connection for external hard drive

    Hopefully this is the correct subdepartment for this question. I'm shopping for an external hard drive to which I'll be saving and storing movies and digital videos. The playback method will be a Powerbook G4 (15-inch FW800 1.5GHz) running DVD Player

  • Problems upgrading system

    I'm trying to upgrade Arch, and it has been a while.. I'm really stumped on how to procede with the errors I'm getting. $ pacman -Syu error: failed to commit transaction (conflicting files) glibc: /lib exists in filesystem Reading https://wiki.archli

  • Gigaframe Q80 digital photo frame won't play video

    The bundled ArcSoft Media Converter 2.5 refuses to convert any of the video formats it should be able to(e.g. mpeg 1,2 and 4) so that the photo frame can play them. It just displays the errors"video encoder lost" or "The codec required for video conv

  • Fehler CE-33987-0 tritt immer wieder auf

    Hallo liebe Leute, ich versuche schon seit 2 Tagen mich an meiner PS4 anzumelden, aber dies geht nicht, weil andauernd der Fehler CE-33987-0 auftritt (Zeitüberschrteitung). Ich hab schon alles gemacht, vom W-Lan Router neustarten bis zum aktualisiere