CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: jar command

Hybrid View

  1. #1
    Join Date
    Apr 2009
    Posts
    1

    jar command

    I wrote a simple program with a gui that basically took user input and made a MLA citation from it. I recently found out I can have it initialize in one click by making it a .jar file and decided it would be a good idea. However, when I try, it says that it cannot find the main method, even though I have it in one of my files. Can someone please help? Here are the files.

    I've been using the commands (I'm not sure which is right, another place I need help)
    jar cmf mainClass.txt MLA.jar webs.java books.java mlas.java
    and
    jar cmf mainClass.txt MLA.jar webs.class books.class mlas.class

    webs.java and books.java are just two files that create new JFrames with more content.

    The program works outside of the .jar file.

    Here is mlas.java
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;

    public class mlas extends JFrame implements ActionListener
    {
    private JLabel words;
    public mlas()
    {
    JPanel buttonPanel;
    JButton quitButton;
    Container contentPane;
    JButton website;
    JButton book;

    buttonPanel=new JPanel();
    quitButton=new JButton("Exit");
    book = new JButton("Book");
    website=new JButton("Website");
    words = new JLabel("Inacuracies in citation may exist. Manually double checking is reccomended. * denotes required field");
    contentPane=getContentPane();

    contentPane.setBackground(Color.LIGHT_GRAY);
    setSize(600, 320);
    setTitle("MLA Citations");

    buttonPanel.add(book);
    buttonPanel.add(website);
    buttonPanel.add(quitButton);

    contentPane.setLayout(new BorderLayout());
    contentPane.add(buttonPanel, BorderLayout.NORTH);
    contentPane.add(words, BorderLayout.LINE_END);

    website.addActionListener(this);
    quitButton.addActionListener(this);
    book.addActionListener(this);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
    }

    public void actionPerformed(ActionEvent e)
    {

    if (e.getActionCommand().equals("Book"))
    {
    Books z= new Books();
    }

    else if (e.getActionCommand().equals("Online Source"))
    {
    Webs y= new Webs();
    }

    else if (e.getActionCommand().equals("Exit"))
    {
    System.exit(0);
    }
    }
    public static void main(String[] args)
    {
    mlas x = new mlas();
    }
    }

    and heres mainClass.txt
    Main-Class: mlas

    Thank you!

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: jar command

    Quote Originally Posted by blitzkreig2 View Post
    I've been using the commands (I'm not sure which is right, another place I need help)
    jar cmf mainClass.txt MLA.jar webs.java books.java mlas.java
    and
    jar cmf mainClass.txt MLA.jar webs.class books.class mlas.class
    I suggest you read and understand the Jar tool docs and tutorial for what you want to do.

    Incidentally, the Java Naming Conventions specify that a class name begins with an upper-case letter.

    Don't ask what it means, but rather how it is used...
    L. Wittgenstein
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured