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 8497431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:07:27+00:00 2026-06-11T00:07:27+00:00

Coming from a c++/make background, I’m used to doing something like this to build

  • 0

Coming from a c++/make background, I’m used to doing something like this to build and run small/medium programs:

make
./foobar

However, with java/ant I’m finding I have to do something like this:

ant
java -ea -cp build/ foobar

Typing out java -ea -cp build/ foobar every time I want to test my program is pretty annoying, I’d much rather be able to do something simple like ./foobar.

I came up with two possible solutions to this problem, but neither seems very good. The first is to just have the compile target create a file called run:

#!/bin/bash

java -ea -cp build/ foobar

And then just use ./run to run the program, however this seems to go against ant’s cross-platform nature, and also just seems like a bit of a hack.

The second option is to create a run target, for example:

<target name="run" depends="compile">
   <java classname="foobar" fork="true">
      <classpath>
         <pathelement path="${build}"/>
         <pathelement path="${java.class.path}"/>
      </classpath>
      <assertions>
         <enable/>
      </assertions>
   </java>
</target>

This method also works, and seems a bit cleaner, but is incredibly slow! For example:

$ time ant run
Buildfile: /somepath/build.xml

init:

compile:

run:
     [java] /* program output */

BUILD SUCCESSFUL
Total time: 1 second

real    0m2.683s
user    0m2.548s
sys     0m0.136s

The above is almost 20 times slower (!) than this:

$ time ./run
/* program output */

real    0m0.143s
user    0m0.124s
sys     0m0.020s

So is there a better/more standard way of running a small/medium java program from the command line? Or should I just use one of the methods I posted here?

  • 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-06-11T00:07:29+00:00Added an answer on June 11, 2026 at 12:07 am

    It seems to me you want to build/run during development phase.

    If so, then get an Eclipse and use it to debug/run, it’s the most effective way of developping under java.

    Usually:

    • Ant is used for packaging phase

    • shell is used for running program, and you would write one per environment (Linux/Windows/Mac OS)

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

Sidebar

Related Questions

Coming from a PHP background, I'm used to writing small functions that return a
Coming from a C# Background I never used any pointers. I'm creating a vector
Coming from a C++ background, this came as a surprise to me. In C++
Coming from Java background I am guessing this is expected. I would really love
Coming from a C++ background, I'm used to sticking the const keyword into function
Coming from a Delphi background, I am used to be able to have class
I'm trying to learn xQuery coming from a php background, I have this expression
I'm coming from a web-development background and I am wondering how I would make
I'm coming from a Rails background and doing some work on a ASP.NET project
I'm coming from a Linux background, but I'd like to provide a version of

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.