Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: How to execute a Java program independent of Netbeans.

  1. #1
    Member
    Join Date
    Dec 2009
    Location
    UK
    Posts
    58
    My Mood
    Sleepy
    Thanks
    2
    Thanked 3 Times in 2 Posts

    Default How to execute a Java program independent of Netbeans.

    Helloes,

    Does anyone have any tips here, ie, a Windows machine.

    I created a batch file that is something like:

    java ExecuteThis

    which works on some Windows machines in College, but it won't work on my machine at home.

    Do I need some sort of extension, dll or something like that?

    Any useful hints or tips would be appreciated.

    Shaun.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: How to execute a Java program independent of Netbeans.

    Here are some requirements you'll need to make sure your java program will work correctly:

    1. Make sure the correct version of Java is installed
    2. Make sure you're referencing the correct path of the Java installation

    There's no dll's required, they're a windows specific library and as such aren't necessary. I would recommend against using a batch file to execute your program, instead I would create an executable jar file. See This page for information on how to do this. The jar file will in essence function as an .exe file in windows, but it can also be run on any other system that has java installed.

  3. #3
    Junior Member
    Join Date
    Jan 2010
    Posts
    6
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: How to execute a Java program independent of Netbeans.

    If you're using an IDE, creating executable jar file is very easy. You just have to have one class with main()

  4. #4
    Junior Member
    Join Date
    Jan 2010
    Location
    Orpington, Kent, UK
    Posts
    18
    Thanks
    0
    Thanked 9 Times in 8 Posts

    Default Re: How to execute a Java program independent of Netbeans.

    Also make sure ExecuteThis class is on the classpath, and fully qualify the package/classname.
    using the default package is generally not a good idea.

    eg. if ExecuteThis class resided in package my.package and was located @ c:\dist\my\package\ExecuteThis.class

    then ensure that c:\dist is on the classpath, and use java my.package.ExecuteThis to execute it from the command line.

  5. #5
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: How to execute a Java program independent of Netbeans.

    You can and should of course add a manifest file to your jar if you want it to be an executable jar file.

    Working with Manifest Files: The Basics (The Java™ Tutorials > Deployment > Packaging Programs in JAR Files)

    // Json

Similar Threads

  1. how to execute a simple display without a main method
    By chronoz13 in forum Java Theory & Questions
    Replies: 5
    Last Post: January 13th, 2010, 06:28 AM
  2. Replies: 0
    Last Post: December 3rd, 2009, 03:43 PM
  3. Netbeans help
    By [Kyle] in forum Java IDEs
    Replies: 2
    Last Post: September 20th, 2009, 06:32 PM
  4. Java ME / Netbeans : Device Name
    By Drakenmul in forum Java ME (Mobile Edition)
    Replies: 0
    Last Post: July 27th, 2009, 02:37 PM
  5. Are We seriously Ignoring NetBeans?
    By javacrazed in forum Java IDEs
    Replies: 4
    Last Post: November 12th, 2008, 04:08 PM