5 Replies - 18476 Views - Last Post: 07 January 2012 - 02:12 PM Rate Topic: -----

#1 totalbeginner   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-January 12

Creating an executable jar (NetBeans)

Posted 06 January 2012 - 05:38 PM

OK, first things first, I am an absolute beginner when it comes to programming and java, so apologies if I sound like a complete idiot!

So far, I've just been working through some very basic programming exercises in NetBeans (e.g. this). I've been managing OK, and the programmes run fine within NetBeans. However, I'm having trouble creating a working jar file of the programme. I click 'build main project' in NetBeans, and the jar file gets created, but when I double click on it in Windows nothing happens. The JAR file type is associated with a JRE, so that isn't the problem. I've worked through this tutorial, and the jar file I created through that runs when I double click it, so I'm a bit stumped. If anyone can help I would really appreciate it.

Is This A Good Question/Topic? 0
  • +

Replies To: Creating an executable jar (NetBeans)

#2 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Creating an executable jar (NetBeans)

Posted 06 January 2012 - 10:08 PM

Don't rely on IDE to build .jar
I do not say that IDE cannot build .jar correctly :) I say that it is not easy to follow the IDE especially when you work on multiple projects at the same time. Its logic may not follow your's.
Work with the real stuff, at least you will exactly know what you put on your .jar and you will have a full understanding on how it works.
Put that link in your Favorites and use it

http://docs.oracle.c...asicsindex.html

Happy jaring :^:
Was This Post Helpful? 1
  • +
  • -

#3 totalbeginner   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-January 12

Re: Creating an executable jar (NetBeans)

Posted 07 January 2012 - 04:34 AM

Thanks for the link :) Using that information I was able to create a .jar file myself, and I was able to run it just fine in cmd. However, I'm still having the same problem when it comes to trying to run it from Windows - I double click, but nothing happens. Can you suggest anything?
Was This Post Helpful? 0
  • +
  • -

#4 CarDriver   User is offline

  • D.I.C Regular
  • member icon

Reputation: 65
  • View blog
  • Posts: 431
  • Joined: 17-February 11

Re: Creating an executable jar (NetBeans)

Posted 07 January 2012 - 08:17 AM

If your program does not use any graphical components (if it's a command-line app), nothing will happen when you double-click the JAR file. You can run any JAR file by typing the following command into the command prompt, which I assume you know how to open and use to some extent:

java -jar MyProgram.jar

Check out my tutorial on the topic, it might clear some things up for you. :smile2:

Like pbl said, you're probably better off learning to make JARs with the command prompt. With a little practice, I think you might find it easier than using your IDE.

This post has been edited by AVReidy: 07 January 2012 - 08:21 AM

Was This Post Helpful? 1
  • +
  • -

#5 totalbeginner   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-January 12

Re: Creating an executable jar (NetBeans)

Posted 07 January 2012 - 10:27 AM

Thanks, that's really helpful. I think I understand now!
Was This Post Helpful? 0
  • +
  • -

#6 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Creating an executable jar (NetBeans)

Posted 07 January 2012 - 02:12 PM

It is a question of file association

If you right click on your .jar
then Open with: it should be Java ™ Platform SE Binary

To change it system wide it depends a bit of your Windows flavor

Google windows file association

will give you all the required links

If your program is a console application you will have to put

java -jar MyProgram.jar

on a .bat file and create a shortcut to that .bat

:^:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1