Beginner Problem - Manifest file

Discussion in 'Java' started by William Colls, May 30, 2011.

  1. Environment:
    Ubuntu 10.04.2 64 bit
    Java 1.6.0_24
    NetbeansIDE 6.8

    I have built a small application containing two classes. When I build
    the application in the IDE, it builds without error, and creates a .jar
    file.

    When I try to run the .jar using the command

    java -jar myapp.jar

    I get the error

    Failed to load Main-Class manifest attribute from myapp.jar

    One of the class files does contain the main declaration

    public static void main(String args)

    From my reading, I understand that there should be a file with the name
    manifest.txt in the build directory that gets incorporated into the .jar
    file, but I don't know what the contents of the file should be. My
    original understanding of how the IDE worked led me to believe that it
    would create the manifest file automatically, but this doesn't seem to
    be happening.

    Any guidance would be greatly appreciated.

    Thanks for your time.
    William Colls, May 30, 2011
    #1
    1. Advertising

  2. On 05/30/2011 01:53 PM, William Colls wrote:
    >
    > Environment:
    > Ubuntu 10.04.2 64 bit
    > Java 1.6.0_24
    > NetbeansIDE 6.8
    >
    > I have built a small application containing two classes. When I build
    > the application in the IDE, it builds without error, and creates a .jar
    > file.
    >
    > When I try to run the .jar using the command
    >
    > java -jar myapp.jar
    >
    > I get the error
    >
    > Failed to load Main-Class manifest attribute from myapp.jar
    >
    > One of the class files does contain the main declaration
    >
    > public static void main(String args)
    >
    > From my reading, I understand that there should be a file with the name
    > manifest.txt in the build directory that gets incorporated into the .jar
    > file, but I don't know what the contents of the file should be. My
    > original understanding of how the IDE worked led me to believe that it
    > would create the manifest file automatically, but this doesn't seem to
    > be happening.
    >
    > Any guidance would be greatly appreciated.
    >
    > Thanks for your time.
    >


    It can be any name, doesn't matter. The line you want is;

    Main-Class: mypackage.MyClass

    From the docs on jar;

    # attribute defined for stand-alone applications
    # This attribute is used by stand-alone applications that are bundled
    into executable jar files which can be invoked by the java runtime
    directly by running "java -jar x.jar".

    * Main-Class :
    *

    The value of this attribute defines the relative path of the main
    application class which the launcher will load at startup time. The
    value must not have the .class extension appended to the class name.

    --

    Knute Johnson
    s/knute/nospam/
    Knute Johnson, May 30, 2011
    #2
    1. Advertising

  3. William Colls

    markspace Guest

    On 5/30/2011 1:53 PM, William Colls wrote:

    > One of the class files does contain the main declaration
    >
    > public static void main(String args)



    Also, this should be an array of strings:

    public static void main( String[] args )

    or

    public static void main( String... args )
    markspace, May 30, 2011
    #3
  4. In article <is103c$dnd$>,
    William Colls <> wrote:

    > Environment:
    > Ubuntu 10.04.2 64 bit
    > Java 1.6.0_24
    > NetbeansIDE 6.8
    >
    > I have built a small application containing two classes. When I build
    > the application in the IDE, it builds without error, and creates a
    > .jar file.
    >
    > When I try to run the .jar using the command
    >
    > java -jar myapp.jar
    >
    > I get the error
    >
    > Failed to load Main-Class manifest attribute from myapp.jar
    >
    > One of the class files does contain the main declaration
    >
    > public static void main(String args)
    >
    > From my reading, I understand that there should be a file with the
    > name manifest.txt in the build directory that gets incorporated into
    > the .jar file, but I don't know what the contents of the file should
    > be. My original understanding of how the IDE worked led me to believe
    > that it would create the manifest file automatically, but this
    > doesn't seem to be happening.


    Here's a simple utility that displays a manifest's contents in place:

    <http://sites.google.com/site/drjohnbmatthews/manifesto>

    The included build.xml file shows how to create the manifest using ant.
    From the command line, use `ant -p` to see the available build targets;
    use `ant test` to see a test run.

    --
    John B. Matthews
    trashgod at gmail dot com
    <http://sites.google.com/site/drjohnbmatthews>
    John B. Matthews, May 31, 2011
    #4
  5. On 11-05-30 06:30 PM, markspace wrote:
    > On 5/30/2011 1:53 PM, William Colls wrote:
    >
    >> One of the class files does contain the main declaration
    >>
    >> public static void main(String args)

    >
    >
    > Also, this should be an array of strings:
    >
    > public static void main( String[] args )
    >
    > or
    >
    > public static void main( String... args )


    Typo. the actual file does define an array.
    William Colls, May 31, 2011
    #5
  6. William Colls

    Nigel Wade Guest

    On 30/05/11 21:53, William Colls wrote:
    >
    > Environment:
    > Ubuntu 10.04.2 64 bit
    > Java 1.6.0_24
    > NetbeansIDE 6.8
    >
    > I have built a small application containing two classes. When I build
    > the application in the IDE, it builds without error, and creates a .jar
    > file.
    >
    > When I try to run the .jar using the command
    >
    > java -jar myapp.jar
    >
    > I get the error
    >
    > Failed to load Main-Class manifest attribute from myapp.jar
    >
    > One of the class files does contain the main declaration
    >
    > public static void main(String args)
    >
    > From my reading, I understand that there should be a file with the name
    > manifest.txt in the build directory that gets incorporated into the .jar
    > file, but I don't know what the contents of the file should be. My
    > original understanding of how the IDE worked led me to believe that it
    > would create the manifest file automatically, but this doesn't seem to
    > be happening.
    >
    > Any guidance would be greatly appreciated.
    >
    > Thanks for your time.
    >


    You shouldn't need to worry about manifest files in NetBeans - provided
    you create the correct type of project. If you create a project of type
    "Java Application", and in the next dialog box check "Create Main
    class", NetBeans will do everything for you. It will create the main
    class and the manifest, and since it knows which is the main class it
    will add that information to the manifest.

    What type of project did you create? It's not always possible to modify
    the project type after the fact, the attributes of some project types
    are not suitable. You may be able to do it by creating your main class
    (a class with a main method), then editing the project properties. In
    the Run category set the Main Class attribute to your main class. If
    that doesn't work, and you want NetBeans to manage the project for you
    by creating properly runnable jar files, the simplest way may well be to
    create a new project of the correct type. Then move your existing Java
    files into that project, using NetBeans to move/refactor the classes.

    --
    Nigel Wade
    Nigel Wade, May 31, 2011
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Spreitzer
    Replies:
    2
    Views:
    519
    Ken Spreitzer
    Feb 12, 2006
  2. Harpstein
    Replies:
    1
    Views:
    1,484
    Paul Beadle
    Oct 28, 2003
  3. hiwa
    Replies:
    3
    Views:
    8,419
    John C. Bollinger
    Jan 15, 2004
  4. Manish Hatwalne

    Reading manifest file from the jar file

    Manish Hatwalne, May 20, 2004, in forum: Java
    Replies:
    11
    Views:
    27,208
    tapas.adhikary
    May 14, 2009
  5. Manish Hatwalne
    Replies:
    9
    Views:
    7,703
    Michael Rauscher
    May 21, 2004
Loading...

Share This Page