Results 1 to 9 of 9
  1. #1
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default [SOLVED] [newbie] creating a jar file

    I'm trying to create a .jar file:

    jar cvfM Calculator.jar *.class
    adding: CalculatorFrame.class(in = 619) (out= 364)(deflated 41%)
    adding: CalculatorPanel$CommandAction.class(in = 1789) (out= 797)(deflated 55%)
    adding: CalculatorPanel$InsertAction.class(in = 1701) (out= 764)(deflated 55%)
    adding: CalculatorPanel.class(in = 3112) (out= 1486)(deflated 52%)
    adding: CalculatorTest$1.class(in = 773) (out= 445)(deflated 42%)
    adding: CalculatorTest.class(in = 607) (out= 364)(deflated 40%)

    >jar uvfm Calculator.jar *.class
    adding: CalculatorPanel$CommandAction.class(in = 1789) (out= 797)(deflated 55%)
    adding: CalculatorPanel$InsertAction.class(in = 1701) (out= 764)(deflated 55%)
    adding: CalculatorPanel.class(in = 3112) (out= 1486)(deflated 52%)
    adding: CalculatorTest$1.class(in = 773) (out= 445)(deflated 42%)
    adding: CalculatorTest.class(in = 607) (out= 364)(deflated 40%)
    java.io.IOException: invalid header field
    at java.util.jar.Attributes.read(Attributes.java:389)
    at java.util.jar.Manifest.read(Manifest.java:182)
    at java.util.jar.Manifest.<init>(Manifest.java:52)
    at sun.tools.jar.Main.update(Main.java:530)
    at sun.tools.jar.Main.run(Main.java:184)
    at sun.tools.jar.Main.main(Main.java:1022)

    However the .jar file seems corrupt when trying to load it in the OS.

    :confused:
    Attached Files Attached Files

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Making jar files is tricky. Best go back to the basics Creating a JAR File.

  3. #3
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    i have short cut for you. switches must be typed in the exact order.

    jar -vefc {classWithMain} {jarFileName.jar} {*.class}

    *braces {} are only used to guide you, do not type that in.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  4. #4
    corlettk is offline Member
    Join Date
    Apr 2009
    Location
    Brisbane
    Posts
    86
    Rep Power
    0

    Default

    Quote Originally Posted by jon80 View Post
    I'm trying to create a .jar file:
    :confused:
    "Here's one I prepared earlier." It might be of some help.

    Cheers mate. Keith.

  5. #5
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default

    Thanks for the posts, I've been trying most of them and reading through the tutorials for a couple of hours, trying to get a .jnlp up and running on Tomcat, which is quite a tricky feat.


    Well, I got as far as creating a .jar file.

    1. An error is being displayed when trying to load the .jnlp from say: http://localhost:8080/calculator/Calculator.jnlp
    I'm not sure that the .MF file is right:

    Manifest-Version: 1.0
    Created-By: 1.6.0_14 (Sun Microsystems Inc.)
    Name: homenetwork/bkr/training/
    Sealed:true
    Main-class: CalculatorTest //The filename of the .class file that contains the 'main' method is named: CalculatorTest.class

    This is the structure of the source directory where I am experimenting with loadsa kind of files:
    here.

    2. The problem seems to be that when I launch the .jnlp application on tomcat 6.0.18, an error is displayed. See screenshots.

    3. How do I create a jar file that includes the WEB-INF and META-INF subfolders with the .mf (manifest) file that I have previously prepared, so that I can simply package a single .jar file?
    (Problem 1 has to be fixed).

    4. I noticed that within the .jnlp file I got an error when changing the <j2se version="??" tag to the version I have installed
    i.e. "1.6.0_14". I changed this because I am only sure it will work on JVM 1.6 upwards, and, actually I only tested it before I updated the VM from the incorrect 32 bit version to the 64 bit version. The 32 bit version worked in most cases, though, so I wasn't bothering too much about it (it's a training server where I exploit the weirdest of my thoughts in code :-).
    Any idea why?

    <?xml version="1.0" encoding="utf-8"?>
    <jnlp spec="1.0+" codebase="http://localhost:8080/calculator/" href="Calculator.jnlp">
    <information>
    <title>Calculator demo application</title>
    <vendor>Jesus Jones</vendor>
    <description>Calculator</description>
    <offline-allowed/>
    </information>
    <resources>
    <j2se version="1.5.0+"/>
    <jar href="Calculator.jar"/>
    </resources>
    <application-desc/>
    </jnlp>


    NOTE 1: Source code here.

    NOTE 2: JVM
    Java Code:
    Microsoft Windows [Version 6.0.6001]
    Copyright (c) 2006 Microsoft Corporation.  All rights reserved.
    
    C:\Users\Administrator>java -version
    java version "1.6.0_14"
    Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
    Java HotSpot(TM) 64-Bit Server VM (build 14.0-b16, mixed mode)
    
    NOTE 3: The command line saga..er log
            at java.util.jar.Attributes.read(Attributes.java:389)
            at java.util.jar.Manifest.read(Manifest.java:182)
            at java.util.jar.Manifest.<init>(Manifest.java:52)
            at sun.tools.jar.Main.run(Main.java:132)
            at sun.tools.jar.Main.main(Main.java:1022)
    
    C:\Users\Administrator\workspace\Calculator\bin\homenetwork\bkr\training>jar -cv
    fm Calculator.jar *.class
    java.io.IOException: invalid header field
            at java.util.jar.Attributes.read(Attributes.java:389)
            at java.util.jar.Manifest.read(Manifest.java:182)
            at java.util.jar.Manifest.<init>(Manifest.java:52)
            at sun.tools.jar.Main.run(Main.java:132)
            at sun.tools.jar.Main.main(Main.java:1022)
    
    C:\Users\Administrator\workspace\Calculator\bin\homenetwork\bkr\training>dir
     Volume in drive C has no label.
     Volume Serial Number is 982D-F9F4
    
     Directory of C:\Users\Administrator\workspace\Calculator\bin\homenetwork\bkr\tr
    aining
    
    05/31/2009  11:05 AM    <DIR>          .
    05/31/2009  11:05 AM    <DIR>          ..
    05/31/2009  10:31 AM               619 CalculatorFrame.class
    05/31/2009  10:31 AM             1,789 CalculatorPanel$CommandAction.class
    05/31/2009  10:31 AM             1,701 CalculatorPanel$InsertAction.class
    05/31/2009  10:31 AM             3,112 CalculatorPanel.class
    05/31/2009  10:31 AM               773 CalculatorTest$1.class
    05/31/2009  10:31 AM               607 CalculatorTest.class
    05/31/2009  11:06 AM    <DIR>          META-INF
                   6 File(s)          8,601 bytes
                   3 Dir(s)  48,761,585,664 bytes free
    
    C:\Users\Administrator\workspace\Calculator\bin\homenetwork\bkr\training>rmdir M
    ETA-INF
    The directory is not empty.
    
    C:\Users\Administrator\workspace\Calculator\bin\homenetwork\bkr\training>rmdir /
    ?
    Removes (deletes) a directory.
    
    RMDIR [/S] [/Q] [drive:]path
    RD [/S] [/Q] [drive:]path
    
        /S      Removes all directories and files in the specified directory
                in addition to the directory itself.  Used to remove a directory
                tree.
    
        /Q      Quiet mode, do not ask if ok to remove a directory tree with /S
    
    C:\Users\Administrator\workspace\Calculator\bin\homenetwork\bkr\training>rmdir /
    S META-INF
    META-INF, Are you sure (Y/N)? Y
    
    C:\Users\Administrator\workspace\Calculator\bin\homenetwork\bkr\training>dir
     Volume in drive C has no label.
     Volume Serial Number is 982D-F9F4
    
     Directory of C:\Users\Administrator\workspace\Calculator\bin\homenetwork\bkr\tr
    aining
    
    05/31/2009  11:09 AM    <DIR>          .
    05/31/2009  11:09 AM    <DIR>          ..
    05/31/2009  10:31 AM               619 CalculatorFrame.class
    05/31/2009  10:31 AM             1,789 CalculatorPanel$CommandAction.class
    05/31/2009  10:31 AM             1,701 CalculatorPanel$InsertAction.class
    05/31/2009  10:31 AM             3,112 CalculatorPanel.class
    05/31/2009  10:31 AM               773 CalculatorTest$1.class
    05/31/2009  10:31 AM               607 CalculatorTest.class
                   6 File(s)          8,601 bytes
                   2 Dir(s)  48,761,585,664 bytes free
    
    C:\Users\Administrator\workspace\Calculator\bin\homenetwork\bkr\training>prompt
    $g
    
    >dir
     Volume in drive C has no label.
     Volume Serial Number is 982D-F9F4
    
     Directory of C:\Users\Administrator\workspace\Calculator\bin\homenetwork\bkr\tr
    aining
    
    05/31/2009  11:09 AM    <DIR>          .
    05/31/2009  11:09 AM    <DIR>          ..
    05/30/2009  09:18 PM               403 Calculator.jnlp
    05/31/2009  10:31 AM               619 CalculatorFrame.class
    05/31/2009  10:31 AM             1,789 CalculatorPanel$CommandAction.class
    05/31/2009  10:31 AM             1,701 CalculatorPanel$InsertAction.class
    05/31/2009  10:31 AM             3,112 CalculatorPanel.class
    05/31/2009  10:31 AM               773 CalculatorTest$1.class
    05/31/2009  10:31 AM               607 CalculatorTest.class
                   7 File(s)          9,004 bytes
                   2 Dir(s)  48,761,581,568 bytes free
    
    >jar cvfm Calculator.jar Calculator.mf *.class
    java.io.FileNotFoundException: Calculator.mf (The system cannot find the file sp
    ecified)
            at java.io.FileInputStream.open(Native Method)
            at java.io.FileInputStream.<init>(FileInputStream.java:106)
            at java.io.FileInputStream.<init>(FileInputStream.java:66)
            at sun.tools.jar.Main.run(Main.java:131)
            at sun.tools.jar.Main.main(Main.java:1022)
    
    >jar cvfm Calculator.jar Calculator.mf *.class
    added manifest
    adding: CalculatorFrame.class(in = 619) (out= 364)(deflated 41%)
    adding: CalculatorPanel$CommandAction.class(in = 1789) (out= 797)(deflated 55%)
    adding: CalculatorPanel$InsertAction.class(in = 1701) (out= 764)(deflated 55%)
    adding: CalculatorPanel.class(in = 3112) (out= 1486)(deflated 52%)
    adding: CalculatorTest$1.class(in = 773) (out= 445)(deflated 42%)
    adding: CalculatorTest.class(in = 607) (out= 364)(deflated 40%)
    
    >jar cvfm Calculator.jar Calculator.mf *.*
    java.io.IOException: invalid header field
            at java.util.jar.Attributes.read(Attributes.java:393)
            at java.util.jar.Manifest.read(Manifest.java:182)
            at java.util.jar.Manifest.<init>(Manifest.java:52)
            at sun.tools.jar.Main.run(Main.java:132)
            at sun.tools.jar.Main.main(Main.java:1022)
    
    >jar cvfm Calculator.jar Calculator.mf *.*
    java.io.IOException: invalid header field
            at java.util.jar.Attributes.read(Attributes.java:393)
            at java.util.jar.Manifest.read(Manifest.java:182)
            at java.util.jar.Manifest.<init>(Manifest.java:52)
            at sun.tools.jar.Main.run(Main.java:132)
            at sun.tools.jar.Main.main(Main.java:1022)
    
    >jar cvfm Calculator.jar Calculator.mf *.*
    java.io.IOException: invalid header field
            at java.util.jar.Attributes.read(Attributes.java:393)
            at java.util.jar.Manifest.read(Manifest.java:182)
            at java.util.jar.Manifest.<init>(Manifest.java:52)
            at sun.tools.jar.Main.run(Main.java:132)
            at sun.tools.jar.Main.main(Main.java:1022)
    
    >jar cvfm Calculator.jar *.*
    java.io.IOException: invalid header field
            at java.util.jar.Attributes.read(Attributes.java:389)
            at java.util.jar.Manifest.read(Manifest.java:182)
            at java.util.jar.Manifest.<init>(Manifest.java:52)
            at sun.tools.jar.Main.run(Main.java:132)
            at sun.tools.jar.Main.main(Main.java:1022)
    
    >dir
     Volume in drive C has no label.
     Volume Serial Number is 982D-F9F4
    
     Directory of C:\Users\Administrator\workspace\Calculator\bin\homenetwork\bkr\tr
    aining
    
    05/31/2009  11:19 AM    <DIR>          .
    05/31/2009  11:19 AM    <DIR>          ..
    05/30/2009  09:18 PM               403 Calculator.jnlp
    05/31/2009  11:19 AM                77 Calculator.mf
    05/31/2009  10:31 AM               619 CalculatorFrame.class
    05/31/2009  10:31 AM             1,789 CalculatorPanel$CommandAction.class
    05/31/2009  10:31 AM             1,701 CalculatorPanel$InsertAction.class
    05/31/2009  10:31 AM             3,112 CalculatorPanel.class
    05/31/2009  10:31 AM               773 CalculatorTest$1.class
    05/31/2009  10:31 AM               607 CalculatorTest.class
                   8 File(s)          9,081 bytes
                   2 Dir(s)  48,761,503,744 bytes free
    
    >jar cvfm Calculator.jar *.*
    java.io.IOException: invalid header field
            at java.util.jar.Attributes.read(Attributes.java:389)
            at java.util.jar.Manifest.read(Manifest.java:182)
            at java.util.jar.Manifest.<init>(Manifest.java:52)
            at sun.tools.jar.Main.run(Main.java:132)
            at sun.tools.jar.Main.main(Main.java:1022)
    
    >jar cvfm Calculator.jar *.*
    java.io.IOException: invalid header field
            at java.util.jar.Attributes.read(Attributes.java:389)
            at java.util.jar.Manifest.read(Manifest.java:182)
            at java.util.jar.Manifest.<init>(Manifest.java:52)
            at sun.tools.jar.Main.run(Main.java:132)
            at sun.tools.jar.Main.main(Main.java:1022)
    
    >jar cvfm Calculator.mf Calculator.jar *.*
    java.io.FileNotFoundException: Calculator.jar (The system cannot find the file s
    pecified)
            at java.io.FileInputStream.open(Native Method)
            at java.io.FileInputStream.<init>(FileInputStream.java:106)
            at java.io.FileInputStream.<init>(FileInputStream.java:66)
            at sun.tools.jar.Main.run(Main.java:131)
            at sun.tools.jar.Main.main(Main.java:1022)
    
    >jar CalculatorTest.class Calculator.jar *.class
    Illegal option: C
    Usage: jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] fil
    es ...
    Options:
        -c  create new archive
        -t  list table of contents for archive
        -x  extract named (or all) files from archive
        -u  update existing archive
        -v  generate verbose output on standard output
        -f  specify archive file name
        -m  include manifest information from specified manifest file
        -e  specify application entry point for stand-alone application
            bundled into an executable jar file
        -0  store only; use no ZIP compression
        -M  do not create a manifest file for the entries
        -i  generate index information for the specified jar files
        -C  change to the specified directory and include the following file
    If any file is a directory then it is processed recursively.
    The manifest file name, the archive file name and the entry point name are
    specified in the same order as the 'm', 'f' and 'e' flags.
    
    Example 1: to archive two class files into an archive called classes.jar:
           jar cvf classes.jar Foo.class Bar.class
    Example 2: use an existing manifest file 'mymanifest' and archive all the
               files in the foo/ directory into 'classes.jar':
           jar cvfm classes.jar mymanifest -C foo/ .
    
    
    >jar Calculator.mf Calculator.jar *.class
    Illegal option: C
    Usage: jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] fil
    es ...
    Options:
        -c  create new archive
        -t  list table of contents for archive
        -x  extract named (or all) files from archive
        -u  update existing archive
        -v  generate verbose output on standard output
        -f  specify archive file name
        -m  include manifest information from specified manifest file
        -e  specify application entry point for stand-alone application
            bundled into an executable jar file
        -0  store only; use no ZIP compression
        -M  do not create a manifest file for the entries
        -i  generate index information for the specified jar files
        -C  change to the specified directory and include the following file
    If any file is a directory then it is processed recursively.
    The manifest file name, the archive file name and the entry point name are
    specified in the same order as the 'm', 'f' and 'e' flags.
    
    Example 1: to archive two class files into an archive called classes.jar:
           jar cvf classes.jar Foo.class Bar.class
    Example 2: use an existing manifest file 'mymanifest' and archive all the
               files in the foo/ directory into 'classes.jar':
           jar cvfm classes.jar mymanifest -C foo/ .
    
    
    >dir
     Volume in drive C has no label.
     Volume Serial Number is 982D-F9F4
    
     Directory of C:\Users\Administrator\workspace\Calculator\bin\homenetwork\bkr\tr
    aining
    
    05/31/2009  11:19 AM    <DIR>          .
    05/31/2009  11:19 AM    <DIR>          ..
    05/30/2009  09:18 PM               403 Calculator.jnlp
    05/31/2009  11:23 AM               126 Calculator.mf
    05/31/2009  10:31 AM               619 CalculatorFrame.class
    05/31/2009  10:31 AM             1,789 CalculatorPanel$CommandAction.class
    05/31/2009  10:31 AM             1,701 CalculatorPanel$InsertAction.class
    05/31/2009  10:31 AM             3,112 CalculatorPanel.class
    05/31/2009  10:31 AM               773 CalculatorTest$1.class
    05/31/2009  10:31 AM               607 CalculatorTest.class
                   8 File(s)          9,130 bytes
                   2 Dir(s)  48,761,438,208 bytes free
    
    >jar cvf0 Calculator.jar *.class *.jnlp
    added manifest
    adding: CalculatorFrame.class(in = 619) (out= 619)(stored 0%)
    adding: CalculatorPanel$CommandAction.class(in = 1789) (out= 1789)(stored 0%)
    adding: CalculatorPanel$InsertAction.class(in = 1701) (out= 1701)(stored 0%)
    adding: CalculatorPanel.class(in = 3112) (out= 3112)(stored 0%)
    adding: CalculatorTest$1.class(in = 773) (out= 773)(stored 0%)
    adding: CalculatorTest.class(in = 607) (out= 607)(stored 0%)
    adding: Calculator.jnlp(in = 403) (out= 403)(stored 0%)
    
    >dir
     Volume in drive C has no label.
     Volume Serial Number is 982D-F9F4
    
     Directory of C:\Users\Administrator\workspace\Calculator\bin\homenetwork\bkr\tr
    aining
    
    05/31/2009  11:26 AM    <DIR>          .
    05/31/2009  11:26 AM    <DIR>          ..
    05/31/2009  11:26 AM            10,183 Calculator.jar
    05/30/2009  09:18 PM               403 Calculator.jnlp
    05/31/2009  11:23 AM               126 Calculator.mf
    05/31/2009  10:31 AM               619 CalculatorFrame.class
    05/31/2009  10:31 AM             1,789 CalculatorPanel$CommandAction.class
    05/31/2009  10:31 AM             1,701 CalculatorPanel$InsertAction.class
    05/31/2009  10:31 AM             3,112 CalculatorPanel.class
    05/31/2009  10:31 AM               773 CalculatorTest$1.class
    05/31/2009  10:31 AM               607 CalculatorTest.class
                   9 File(s)         19,313 bytes
                   2 Dir(s)  48,761,425,920 bytes free
    
    >jar cvf0 Calculator.jar *.class *.jnlp
    NOTE 3: The structure of the target directory:
    Java Code:
    ...
    C:\Program Files (x86)\Apache Software Foundation\Tomcat 6.0\webapps\calculator>
    prompt $g
    
    >tree /a /f
    Folder PATH listing
    Volume serial number is 982D-F9F4
    C:.
    |   Calculator.jnlp
    |
    +---homenetwork
    |   \---bkr
    |       \---training
    |           \---Calculator
    |                   CalculatorFrame.class
    |                   CalculatorPanel$CommandAction.class
    |                   CalculatorPanel$InsertAction.class
    |                   CalculatorPanel.class
    |                   CalculatorTest$1.class
    |                   CalculatorTest.class
    |
    \---META-INF
            MANIFEST.MF
    
    
    >
    Last edited by jon80; 05-31-2009 at 04:43 PM. Reason: update

  6. #6
    corlettk is offline Member
    Join Date
    Apr 2009
    Location
    Brisbane
    Posts
    86
    Rep Power
    0

    Default JNLP Example - a simple Swing Calculator

    Here's your example, slightly rejigged... and working upto the local execution stage... Dunno about tomcat, coz I use weblogic... presume all you need to do is put the JNLP in the appropriate directory... somewhere under ${TOMCAT}\webapps

    Java Code:
    :: ENVIRONMENT ----------------------------------
    
    cmd
            Microsoft Windows [Version 6.0.6000]
            Copyright (c) 2006 Microsoft Corporation.  All rights reserved.
    exit
    
    javac -version
            javac 1.6.0_12
    
    java -version
            java version "1.6.0_12"
            Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
            Java HotSpot(TM) Client VM (build 11.2-b01, mixed mode, sharing)
    
    
    :: SOURCE CODE ----------------------------------
    tree /a /f c:\java\home\src
            Folder PATH listing
            Volume serial number is 00AC-1BC7
            C:\JAVA\HOME\SRC\
            \---forums
                \---jon
                    \    Calculator.java    // see below: Source Code Listing 
    
    
    :: CLEAN ----------------------------------------
    cd /d c:\java\home\classes
    rmdir /S /Q .\forums
    
    
    :: BUILD ----------------------------------------
    cd /d c:\java\home\classes
    javac -d c:\java\home\classes -cp c:\java\home\src c:\java\home\src\forums\jon\Calculator.java
    
    :: confirm it built
    dir /s /b forums
            c:\Java\home\classes\forums\jon
            c:\Java\home\classes\forums\jon\Calculator$1.class
            c:\Java\home\classes\forums\jon\Calculator$CalculatorPanel$DigitButtonListener.class
            c:\Java\home\classes\forums\jon\Calculator$CalculatorPanel$OperationButtonListener.class
            c:\Java\home\classes\forums\jon\Calculator$CalculatorPanel.class
            c:\Java\home\classes\forums\jon\Calculator.class
    
    
    :: PACKAGE --------------------------------------
    cd /d c:\java\home\classes
    jar cfe Calculator.jar forums.jon.Calculator forums\jon\*.class
    
    :: confirm it built
    jar tvf Calculator.jar
                 0 Sat Jun 06 18:19:22 EST 2009 META-INF/
               106 Sat Jun 06 18:19:22 EST 2009 META-INF/MANIFEST.MF
               434 Sat Jun 06 17:45:30 EST 2009 forums/jon/Calculator$1.class
              1469 Sat Jun 06 17:45:30 EST 2009 forums/jon/Calculator$CalculatorPanel$DigitButtonListener.class
              2197 Sat Jun 06 17:45:30 EST 2009 forums/jon/Calculator$CalculatorPanel$OperationButtonListener.class
              3079 Sat Jun 06 17:45:30 EST 2009 forums/jon/Calculator$CalculatorPanel.class
               983 Sat Jun 06 17:45:30 EST 2009 forums/jon/Calculator.class
    
    rmdir /q /s c:\tmp\calc
    mkdir c:\tmp\calc
    copy Calculator.jar c:\tmp\calc\
            1 file(s) copied.
    
    cd /d c:\tmp\calc
    jar xvf Calculator.jar
              created: META-INF/
             inflated: META-INF/MANIFEST.MF
             inflated: forums/jon/Calculator$1.class
             inflated: forums/jon/Calculator$CalculatorPanel$DigitButtonListener.class
             inflated: forums/jon/Calculator$CalculatorPanel$OperationButtonListener.class
             inflated: forums/jon/Calculator$CalculatorPanel.class
             inflated: forums/jon/Calculator.class
    
    type META-INF\MANIFEST.MF
            Manifest-Version: 1.0
            Created-By: 1.6.0_12 (Sun Microsystems Inc.)
            Main-Class: forums.jon.Calculator
    
    :: TEST EXECUTE ----------------------------------
    java -jar Calculator.jar
    
    :: WEB START -------------------------------------
    :: see http://java.sun.com/developer/technicalArticles/Programming/jnlp/
    
    type c:\tmp\Calculator.jnlp
            <?xml version="1.0" encoding="UTF-8"?>
            <jnlp spec="1.0+" codebase="file:///c:/java/home/classes/">
              <information>
                <title>Calculator</title>
                <vendor>corlettk</vendor>
                <homepage href="/forums/jon" />
                <description>JNLP Demo - A simple Swing calculator.</description>
              </information>
              <offline-allowed/>
            <!--
              <security>
                <j2ee-application-client-permissions/>
              </security>
            -->
              <resources>
                <j2se version="1.6+" />
                <jar href="/java/home/classes/Calculator.jar"/>
              </resources>
              <application-desc main-class="forums.jon.Calculator" />
            </jnlp>
    
    firefox file:///C:/tmp/Calculator.jnlp
    
            The calculator is shown.
    Modified Source Code
    Java Code:
    package forums.jon;
    
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JButton;
    import java.text.NumberFormat;
    import java.text.DecimalFormat;
    
    public class Calculator
    {
      private static class CalculatorPanel extends JPanel
      {
        private static final long serialVersionUID = 0L;
        private static final NumberFormat DECIMAL = new DecimalFormat();
    
        private JButton display;
        private double result = 0.0;
        private char previousOperation = '=';
        private boolean start = true;
    
        public CalculatorPanel() {
          super(new BorderLayout());
    
          //add the display
          display = new JButton("0");
          display.setEnabled(false);
          add(display, BorderLayout.NORTH);
    
          //add the buttons in a 4 X 4 grid
          ActionListener digitListener = new DigitButtonListener();
          ActionListener operationListener = new OperationButtonListener();
          JPanel btns = new JPanel(new GridLayout(4,4));
          // line 1
          addButton(btns, "7", digitListener);
          addButton(btns, "8", digitListener);
          addButton(btns, "9", digitListener);
          addButton(btns, "/", operationListener);
          // line 2
          addButton(btns, "4", digitListener);
          addButton(btns, "5", digitListener);
          addButton(btns, "6", digitListener);
          addButton(btns, "*", operationListener);
          // line 3
          addButton(btns, "1", digitListener);
          addButton(btns, "2", digitListener);
          addButton(btns, "3", digitListener);
          addButton(btns, "-", operationListener);
          // line 4
          addButton(btns, "0", digitListener);
          addButton(btns, ".", digitListener);
          addButton(btns, "=", operationListener);
          addButton(btns, "+", operationListener);
          add(btns,BorderLayout.CENTER);
        }
    
        private void addButton(JPanel panel, String label, ActionListener listener) {
          JButton button = new JButton(label);
          button.addActionListener(listener);
          panel.add(button);
        }
    
        private class DigitButtonListener implements ActionListener
        {
          public void actionPerformed (ActionEvent event) {
            String digit = event.getActionCommand();
            if (start) {
              display.setText("");
              start = false;
            }
            display.setText(display.getText() + digit);
          }
        }
    
        private class OperationButtonListener implements ActionListener
        {
          public void actionPerformed (ActionEvent event) {
            char operation = event.getActionCommand().charAt(0);
            if (start) {
              if (operation == '-') {
                display.setText(String.valueOf(operation));
                start = false;
              } else {
                previousOperation = operation;
              }
            } else {
              final double num = Double.parseDouble(display.getText());
              switch (previousOperation) {
                case '+': result += num; break;
                case '-': result -= num; break;
                case '*': result *= num; break;
                case '/': result /= num; break;
                case '=': result = num;
              }
              display.setText(DECIMAL.format(result));
              previousOperation = operation;
              start = true;
            }
          }
        }
      }
    
      private static void createAndShowGUI() {
        JFrame frame = new JFrame("Calculator");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setContentPane(new CalculatorPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      }
    
      public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            createAndShowGUI();
          }
        });
      }
    
    }
    FIGJAM.... Ergo: It works for me.

    Cheers. Keith.

  7. #7
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default

    Thanks, that was helpful. I'm getting stuck in the part where I try to load the main class, and, afaik this is the problem I had before. Having tried to "fit in" the modified code within the project (and noticed a few smart behaviour tweaks in the update), I'm getting this:

    Java Code:
    >cd ..
    
    >dir
     Volume in drive C has no label.
     Volume Serial Number is 982D-F9F4
    
     Directory of C:\Users\Administrator\workspace\Calculator\bin
    
    06/06/2009  02:31 PM    <DIR>          .
    06/06/2009  02:31 PM    <DIR>          ..
    06/06/2009  02:31 PM    <DIR>          homenetwork
                   0 File(s)              0 bytes
                   3 Dir(s)  15,427,719,168 bytes free
    
    >cd ..
    
    >dir
     Volume in drive C has no label.
     Volume Serial Number is 982D-F9F4
    
     Directory of C:\Users\Administrator\workspace\Calculator
    
    06/06/2009  02:30 PM    <DIR>          .
    06/06/2009  02:30 PM    <DIR>          ..
    05/25/2009  12:01 AM               232 .classpath
    06/01/2009  08:48 PM               441 .project
    06/06/2009  02:31 PM    <DIR>          bin
    05/25/2009  12:02 AM    <DIR>          src
                   2 File(s)            673 bytes
                   4 Dir(s)  15,427,719,168 bytes free
    
    >cd src
    
    >dir
     Volume in drive C has no label.
     Volume Serial Number is 982D-F9F4
    
     Directory of C:\Users\Administrator\workspace\Calculator\src
    
    05/25/2009  12:02 AM    <DIR>          .
    05/25/2009  12:02 AM    <DIR>          ..
    05/25/2009  12:02 AM    <DIR>          homenetwork
                   0 File(s)              0 bytes
                   3 Dir(s)  15,427,719,168 bytes free
    
    >cd ..
    
    >dir
     Volume in drive C has no label.
     Volume Serial Number is 982D-F9F4
    
     Directory of C:\Users\Administrator\workspace\Calculator
    
    06/06/2009  02:30 PM    <DIR>          .
    06/06/2009  02:30 PM    <DIR>          ..
    05/25/2009  12:01 AM               232 .classpath
    06/01/2009  08:48 PM               441 .project
    06/06/2009  02:31 PM    <DIR>          bin
    05/25/2009  12:02 AM    <DIR>          src
                   2 File(s)            673 bytes
                   4 Dir(s)  15,427,719,168 bytes free
    
    >cd src
    
    >dir
     Volume in drive C has no label.
     Volume Serial Number is 982D-F9F4
    
     Directory of C:\Users\Administrator\workspace\Calculator\src
    
    05/25/2009  12:02 AM    <DIR>          .
    05/25/2009  12:02 AM    <DIR>          ..
    05/25/2009  12:02 AM    <DIR>          homenetwork
                   0 File(s)              0 bytes
                   3 Dir(s)  15,427,719,168 bytes free
    
    >cd homenetwork
    
    >cd bkr\training
    
    >dir
     Volume in drive C has no label.
     Volume Serial Number is 982D-F9F4
    
     Directory of C:\Users\Administrator\workspace\Calculator\src\homenetwork\bkr\tr
    aining
    
    06/06/2009  02:36 PM    <DIR>          .
    06/06/2009  02:36 PM    <DIR>          ..
    06/06/2009  02:36 PM             3,910 Calculator.java
    06/06/2009  01:12 PM    <DIR>          old
                   1 File(s)          3,910 bytes
                   3 Dir(s)  15,427,719,168 bytes free
    
    >dir
     Volume in drive C has no label.
     Volume Serial Number is 982D-F9F4
    
     Directory of C:\Users\Administrator\workspace\Calculator\src\homenetwork\bkr\tr
    aining
    
    06/06/2009  02:36 PM    <DIR>          .
    06/06/2009  02:36 PM    <DIR>          ..
    06/06/2009  02:36 PM             3,910 Calculator.java
    06/06/2009  01:12 PM    <DIR>          old
                   1 File(s)          3,910 bytes
                   3 Dir(s)  15,427,719,168 bytes free
    
    >javac -d Calculator.java
    javac: not a directory: Calculator.java
    Usage: javac <options> <source files>
    use -help for a list of possible options
    
    >javac Calculator.java
    
    >javac /?
    javac: invalid flag: /?
    Usage: javac <options> <source files>
    use -help for a list of possible options
    
    >javac -help
    Usage: javac <options> <source files>
    where possible options include:
      -g                         Generate all debugging info
      -g:none                    Generate no debugging info
      -g:{lines,vars,source}     Generate only some debugging info
      -nowarn                    Generate no warnings
      -verbose                   Output messages about what the compiler is doing
      -deprecation               Output source locations where deprecated APIs are u
    sed
      -classpath <path>          Specify where to find user class files and annotati
    on processors
      -cp <path>                 Specify where to find user class files and annotati
    on processors
      -sourcepath <path>         Specify where to find input source files
      -bootclasspath <path>      Override location of bootstrap class files
      -extdirs <dirs>            Override location of installed extensions
      -endorseddirs <dirs>       Override location of endorsed standards path
      -proc:{none,only}          Control whether annotation processing and/or compil
    ation is done.
      -processor <class1>[,<class2>,<class3>...]Names of the annotation processors t
    o run; bypasses default discovery process
      -processorpath <path>      Specify where to find annotation processors
      -d <directory>             Specify where to place generated class files
      -s <directory>             Specify where to place generated source files
      -implicit:{none,class}     Specify whether or not to generate class files for
    implicitly referenced files
      -encoding <encoding>       Specify character encoding used by source files
      -source <release>          Provide source compatibility with specified release
    
      -target <release>          Generate class files for specific VM version
      -version                   Version information
      -help                      Print a synopsis of standard options
      -Akey[=value]              Options to pass to annotation processors
      -X                         Print a synopsis of nonstandard options
      -J<flag>                   Pass <flag> directly to the runtime system
    
    
    >dir
     Volume in drive C has no label.
     Volume Serial Number is 982D-F9F4
    
     Directory of C:\Users\Administrator\workspace\Calculator\src\homenetwork\bkr\tr
    aining
    
    06/06/2009  02:41 PM    <DIR>          .
    06/06/2009  02:41 PM    <DIR>          ..
    06/06/2009  02:41 PM               462 Calculator$1.class
    06/06/2009  02:41 PM             1,623 Calculator$CalculatorPanel$DigitButtonLis
    tener.class
    06/06/2009  02:41 PM             2,407 Calculator$CalculatorPanel$OperationButto
    nListener.class
    06/06/2009  02:41 PM             3,275 Calculator$CalculatorPanel.class
    06/06/2009  02:41 PM             1,025 Calculator.class
    06/06/2009  02:36 PM             3,910 Calculator.java
    06/06/2009  01:12 PM    <DIR>          old
                   6 File(s)         12,702 bytes
                   3 Dir(s)  15,427,690,496 bytes free
    
    >dir
     Volume in drive C has no label.
     Volume Serial Number is 982D-F9F4
    
     Directory of C:\Users\Administrator\workspace\Calculator\src\homenetwork\bkr\tr
    aining
    
    06/06/2009  02:41 PM    <DIR>          .
    06/06/2009  02:41 PM    <DIR>          ..
    06/06/2009  02:41 PM               462 Calculator$1.class
    06/06/2009  02:41 PM             1,623 Calculator$CalculatorPanel$DigitButtonLis
    tener.class
    06/06/2009  02:41 PM             2,407 Calculator$CalculatorPanel$OperationButto
    nListener.class
    06/06/2009  02:41 PM             3,275 Calculator$CalculatorPanel.class
    06/06/2009  02:41 PM             1,025 Calculator.class
    06/06/2009  02:36 PM             3,910 Calculator.java
    06/06/2009  01:12 PM    <DIR>          old
                   6 File(s)         12,702 bytes
                   3 Dir(s)  15,427,690,496 bytes free
    
    >jar cfe Calculator.jar *.class
    
    >dir
     Volume in drive C has no label.
     Volume Serial Number is 982D-F9F4
    
     Directory of C:\Users\Administrator\workspace\Calculator\src\homenetwork\bkr\tr
    aining
    
    06/06/2009  02:42 PM    <DIR>          .
    06/06/2009  02:42 PM    <DIR>          ..
    06/06/2009  02:41 PM               462 Calculator$1.class
    06/06/2009  02:41 PM             1,623 Calculator$CalculatorPanel$DigitButtonLis
    tener.class
    06/06/2009  02:41 PM             2,407 Calculator$CalculatorPanel$OperationButto
    nListener.class
    06/06/2009  02:41 PM             3,275 Calculator$CalculatorPanel.class
    06/06/2009  02:41 PM             1,025 Calculator.class
    06/06/2009  02:42 PM             4,730 Calculator.jar
    06/06/2009  02:36 PM             3,910 Calculator.java
    06/06/2009  01:12 PM    <DIR>          old
                   7 File(s)         17,432 bytes
                   3 Dir(s)  15,427,682,304 bytes free
    
    >cd C:\Program Files (x86)\Apache Software Foundation\Tomcat 6.0\webapps\calcula
    tor
    
    >dir
     Volume in drive C has no label.
     Volume Serial Number is 982D-F9F4
    
     Directory of C:\Program Files (x86)\Apache Software Foundation\Tomcat 6.0\webap
    ps\calculator
    
    06/06/2009  02:43 PM    <DIR>          .
    06/06/2009  02:43 PM    <DIR>          ..
    06/06/2009  02:41 PM             1,623 Calculator$CalculatorPanel$DigitButtonLis
    tener.class
    06/06/2009  02:41 PM             2,407 Calculator$CalculatorPanel$OperationButto
    nListener.class
    06/06/2009  02:41 PM             3,275 Calculator$CalculatorPanel.class
    06/06/2009  02:41 PM             1,025 Calculator.class
    06/06/2009  02:42 PM             4,730 Calculator.jar
    06/06/2009  02:19 PM               468 Calculator.jnlp
    06/06/2009  02:42 PM    <DIR>          META-INF
                   6 File(s)         13,528 bytes
                   3 Dir(s)  15,427,731,456 bytes free
    
    >java -jar Calculator.jar
    Exception in thread "main" java.lang.NoClassDefFoundError: Calculator$1/class
    Caused by: java.lang.ClassNotFoundException: Calculator$1.class
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    Could not find the main class: Calculator$1.class. Program will exit.
    
    >dir
     Volume in drive C has no label.
     Volume Serial Number is 982D-F9F4
    
     Directory of C:\Program Files (x86)\Apache Software Foundation\Tomcat 6.0\webap
    ps\calculator
    
    06/06/2009  02:43 PM    <DIR>          .
    06/06/2009  02:43 PM    <DIR>          ..
    06/06/2009  02:41 PM             1,623 Calculator$CalculatorPanel$DigitButtonLis
    tener.class
    06/06/2009  02:41 PM             2,407 Calculator$CalculatorPanel$OperationButto
    nListener.class
    06/06/2009  02:41 PM             3,275 Calculator$CalculatorPanel.class
    06/06/2009  02:41 PM             1,025 Calculator.class
    06/06/2009  02:42 PM             4,730 Calculator.jar
    06/06/2009  02:19 PM               468 Calculator.jnlp
    06/06/2009  02:42 PM    <DIR>          META-INF
                   6 File(s)         13,528 bytes
                   3 Dir(s)  15,427,731,456 bytes free
    
    >type Calculator.jnlp
    <?xml version="1.0" encoding="utf-8"?>
    <jnlp spec="1.0+" codebase="http://localhost:8080/calculator/">
    <information>
    <title>Calculator demo application</title>
    <vendor>Jesus Jones</vendor>
    <description>Calculator</description>
    <homepage href="/calculator"
    <offline-allowed/>
    </information>
    <resources>
    <j2se version="1.6+"/>
    <jar href="Calculator.jar"/>
    </resources>
    <application-desc main-class="homenetwork.bkr.training" />
    <application-desc/>
    </jnlp>
    >
    Source code

    Any ideas?
    Last edited by jon80; 06-06-2009 at 06:55 PM.

  8. #8
    corlettk is offline Member
    Join Date
    Apr 2009
    Location
    Brisbane
    Posts
    86
    Rep Power
    0

    Default Webstart for dummies

    > Jesus wrote:
    > Any idea what I am doing w*ong?

    ************************************************** ************************************************** **************

    Java Code:
    :: set TOP=C:\Users\Administrator\workspace\Calculator
    :: set CLSDIR=homenetwork\bkr\training
    :: set CATALINA_HOME=C:\Program Files (x86)\Apache Software Foundation\Tomcat 6.0
    
    set TOP=C:\java\home
    set CLSDIR=forums\jon
    :: my CATALINA_HOME is already set
    
    :: CLEAN ---------------------------------------------------
    cd /d %TOP%
    rmdir /s /q %TOP%\classes
    mkdir %TOP%\classes
    cd /d %TOP%\classes
    
    :: BUILD ---------------------------------------------------
    javac -d %TOP%\classes -cp %TOP%\src %TOP%\src\%CLSDIR%\Calculator.java
    
    :: PACKAGE -------------------------------------------------
    jar cfe %TOP%\Calculator.jar forums.jon.Calculator %CLSDIR%\*.class
    
    :: DEPLOY --------------------------------------------------
    copy %TOP%\Calculator.jar %CATALINA_HOME%\webapps\calculator\
    
    :: JNLP ----------------------------------------------------
    type %CATALINA_HOME%\webapps\calculator\Calculator.jnlp
    <?xml version="1.0" encoding="utf-8"?>
    <jnlp spec="1.0+" codebase="http://localhost:8080/">
      <information>
        <title>Calculator demo application</title>
        <vendor>Jesus Jones</vendor>
        <description>Calculator</description>
        <homepage href="/calculator" />
        <offline-allowed/>
      </information>
      <resources>
        <j2se version="1.6+"/>
        <jar href="calculator/Calculator.jar"/> <!-- full path the jar file, Putz! -->
      </resources>
      <application-desc main-class="homenetwork.bkr.training.Calculator" />
    </jnlp>
    
    :: JNLP ----------------------------------------------------
    firefox http://localhost:8080/calculator/Calculator.jnlp
    ************************************************** ************

    Cheers mate. Keith.
    Last edited by CJSLMAN; 06-08-2009 at 03:30 PM. Reason: Edited by moderator.

  9. #9
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    jar -vefc Calculator Calculator.jar *.class
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

Similar Threads

  1. Creating jar file
    By Heather in forum Advanced Java
    Replies: 4
    Last Post: 02-11-2009, 10:58 AM
  2. newbie. Reading a file, deprecated method
    By Roy Gardiner in forum New To Java
    Replies: 2
    Last Post: 10-24-2008, 09:08 PM
  3. creating jar file
    By po0oker in forum Advanced Java
    Replies: 3
    Last Post: 04-04-2008, 08:49 PM
  4. creating .ear file
    By psn in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 01-06-2008, 06:01 AM
  5. Newbie help with a file parser
    By adlb1300 in forum New To Java
    Replies: 2
    Last Post: 07-24-2007, 05:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •