Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7601495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:10:37+00:00 2026-05-30T23:10:37+00:00

Ok, so, for some reason, my .jar wont execute even though it does in

  • 0

Ok, so, for some reason, my .jar wont execute even though it does in eclipse. Heres my code, its not the best but, im experimenting. I need some help in getting it to execute outside of eclipse as the .jar file.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Calendar;  // only need this one class
import javax.swing.*;
////////////////////////////////////////////////////////////////// TextClock
public class CopyOftheclock {
//================================================================= main
public static void main(String[] args) {
    JFrame clock = new TextClockWindow();
    clock.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    clock.setVisible(true);
}//end main
}//endclass TextClock


@SuppressWarnings("serial")
//////////////////////////////////////////////////////////// TextClockWindow
class TextClockWindow extends JFrame {
//=================================================== instance variables
private JTextField timeField;  // set by timer listener

//========================================================== constructor
public TextClockWindow() {
    // Build the GUI - only one panel
    timeField = new JTextField(7);
    timeField.setFont(new Font("sansserif", Font.PLAIN, 48));

    Container content = this.getContentPane();
    content.setLayout(new FlowLayout());
    content.add(timeField); 

    this.setTitle("Norway");
    this.pack();

    // Create a 1-second timer and action listener for it.
    // Specify package because there are two Timer classes
    javax.swing.Timer t = new javax.swing.Timer(1000,
          new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  String a = "";
                  Calendar now = Calendar.getInstance();
                  int h = now.get(Calendar.HOUR_OF_DAY);
                    if (h==24)
                    {
                        h=8;
                        a = "A.M";
                    }
                    if (h==1)
                    {
                        h=9;
                        a = "A.M";
                    }
                    if (h==2)
                    {
                        h=10;
                        a = "A.M";
                    }
                    if (h==3)
                    {
                        h=11;
                        a = "A.M";
                    }
                    if (h==4)
                    {
                        h=12;
                        a = "P.M";
                    }
                    if (h==5)
                    {
                        h=1;
                        a = "P.M";
                    }
                    if (h==6)
                    {
                        h=2;
                        a = "P.M";
                    }
                    if (h==7)
                    {
                        h=3;
                        a = "P.M";
                    }
                    if (h==8)
                    {
                        h=4;
                        a = "P.M";
                    }
                    if (h==9)
                    {
                        h=5;
                        a = "P.M";
                    }
                    if (h==10)
                    {
                        h=6;
                        a = "P.M";
                    }
                    if (h==11)
                    {
                        h=7;
                        a = "P.M";
                    }
                    if (h==12)
                    {
                        h=8;
                        a = "P.M";
                    }
                    if (h==13)
                    {
                        h=9;
                        a = "P.M";
                    }
                    if (h==14)
                    {
                        h=10;
                        a = "P.M";
                    }
                    if (h==15)
                    {
                        h=11;
                        a = "P.M";
                    }
                    if (h==16)
                    {
                        h=12;
                        a = "P.M";
                    }
                    if (h==17)
                    {
                        h=1;
                        a = "A.M";
                    }
                    if (h==18)
                    {
                        h=2;
                        a = "A.M";
                    }
                    if (h==19)
                    {
                        h=3;
                        a = "A.M";
                    }
                    if (h==20)
                    {
                        h=4;
                        a = "A.M";
                    }
                    if (h==21)
                    {
                        h=5;
                        a = "A.M";
                    }
                    if (h==22)
                    {
                        h=6;
                        a = "A.M";
                    }
                    if (h==23)
                    {
                        h=7;
                        a = "A.M";
                    }
                  int m = now.get(Calendar.MINUTE);
                  int s = now.get(Calendar.SECOND);
                  timeField.setText("" + h + ":" + m + ":" + s + " " + a);
              }

          });
    t.start();  // Start the timer
}//end constructor
}//endclass TextClock
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:10:39+00:00Added an answer on May 30, 2026 at 11:10 pm

    Making the Jar

    Export as a runnable jar

    enter image description here
    enter image description here

    If you are successful in making a jar then follow the next step.

    Running it from console

    Method 1

    java [-options] -jar jarfile [args...]

    Note: Where [-options] are the arguments for the JVM and [args...] is for your jar

    Also this will only work if your jar manifest has an entry for main class like this:

    Manifest-Version: 1.0
    Class-Path: .
    Main-Class: CopyOftheclock
    

    Method 2

    set your class path like this:

    set classpath=clock.jar;.;%classpath%
    

    and after this:

    java [-options] class [args...]
    

    Where class is your class with main method. Also class should be fully qualified i.e. if it is in package a.b.c then the class should be a.b.c.CopyOftheclock. Also, you should be firing the java command from the topmost packages parent.

    Method 3

    I am not sure about *nix based OS but on windows just right click on the jar and select run with java or javaw. But for that the manifest file must have the main class entry, otherwise it would fail.

    Note: See the java -help for more details on [options]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, Section 1 works but Section 2 does not. When run in
I am trying to clean and build a jar but for some reason when
For some reason I never see this done. Is there a reason why not?
For some reason when I create a new namespace in Visual Studio 2008 its
I have a simple project with 3 dependencies but for some reason when i
I have installed spring-security-core in a grails project, but for some reason, IDEA didn't
For some reason we need the xdb.jar from the Oracle XDK. This jar depends
For some reason Eclipse doesn't remember source lookup path for some java projects, and
I'm trying to get lein up and running. But for some reason I'm having
For some reason, when I try to run this code, all I get is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.