How to compile Java files using Ant in Eclipse

Hi All ,
I would like to compile all Java files using Ant in Eclipse.Since am very new to Ant and Eclipse can someone help me to create a build.xml file and let me know how to compile all the java files.
For ex , I have placed my java files inside the path C:\HEC\Terab.Initially the Terab folder holds 7 jar files which i had decompiled using JD compiler and placed the unzipped 7 folders (which contains the java files ).Now i have imported the HEC project into Eclipse using New ->Project ->Java Project.after importig it throwed me an error saying missing jar files.again i copied the jar files and placed inside Terab folder with other 7 folder.
Now How i can compile the java files and convert in to class files.Then after compiling the files i will again need to jar all the 7 folder.
Please tell me the steps i need to follow.How to write an build.xml file ? where i should keep it ? only one build.xml file is enough or should i write 7 build.xml file for each folder ? Please help me out...
Thanks & Regards
Kar1983

put it another way, what I am trying to do is to compile David Brackeen's ch 18 code from his book. The java sourse files can be downloaded here:
http://www.brackeen.com/javagamebook/
my question is that how would I complie all of these file so that I can get the program in ch18src\src\com\brackeen\javagamebook\test\ to run?

Similar Messages

  • How to compile .java files in windows server

    Hi All,
    I want to compile my CO.java file in server directly how can i do that my server is windows server
    If it is Linux i can login through putty and go to java top and then file location then i use to do javac filename.java then i use to get filename.class but now same thing i did in windows server which is not working please sugget how to do its bit urgent.

    Why do you want to compile it on the server and not in jdeveloper? You should be able to issue the javac command from the prompt. Your unix account must have permissions to that command though.
    For more info on the javac command:
    http://download.oracle.com/javase/1.4.2/docs/tooldocs/windows/javac.html
    Kristofer Cruz

  • Error while compiling java file using J2SE 1.5.0

    Dear Sir,
    I'm getting the following error while compiling the java file.The code is also given.
    package test;
    public class TestRowSet {
    public TestRowSet() {
    "TestRowSet.java": cannot access java.lang.Object,bad class file: D:\Program Files\Java\jdk1.5.0\jre\lib\rt.jar\java\lang\Object.class,class file has wrong version 49.0, should be 48.0,Please remove or make sure it appears in the correct subdirectory of the classpath. at line 4, column 1
    Please help me out.
    --Suketu Naik.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    But I'm compiling within "Borland JBuilder 9.0". I've
    set the JDK path of the current project to point to
    the path of JDK 1.5.0 . I've also tried to compile at
    command prompt with "javac". I'm getting the same
    error of "Undefinedclassloader" with long StatckTrace.
    I don't know anything about JBuilder either. If you use the command prompt and enter the full path to the 1.5 javac.exe then that will prove whether the issue is using an older javac or not. For example "c:\j2sdk1.5.0_01\bin\javac HelloWorld.java"

  • How to compile java files in a bunch of drectories?

    I have a bunch of java files in a bunch of different directories. How can I compile them all at once? Please note I also do not know how to get javac to work outside the java directory.

    put it another way, what I am trying to do is to compile David Brackeen's ch 18 code from his book. The java sourse files can be downloaded here:
    http://www.brackeen.com/javagamebook/
    my question is that how would I complie all of these file so that I can get the program in ch18src\src\com\brackeen\javagamebook\test\ to run?

  • How to compile java file in Tomcat ?

    Hi all,
    I have a java file named Ch1Servlet.java under project1/src directory
    there is classes directory project1/classes and web.xml under src directory
    project1/src directory.
    Now to compile i have to give %javac -classpath /your path/tomcat/common/lib/servlet-api.jar -d classes src/Ch1Servlet.java
    What is this your path ? Tomcat 5.0 is installed in C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib with servlet-api.jar
    Please help me out.
    Best Regards
    Taton
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class Ch1Servlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    PrintWriter out = response.getWriter();
    java.util.Date today = new java.util.Date();
    out.println("<html>"+"<body>"+"<h1 align = center>HF\'s Chapter 1 Servlet</h1>"+"<br>"+today+"</body>"+"</html>");
    }

    understand 1 thing..ur tomcat is not a compiler as u
    think..its a poor web server only..
    Its not mandatory that u need to put the source files
    in tomcat folder.u can put ur java files where ever u
    want..put servlet.jar in ur classpath.
    then start compiling ur java files..once u are done
    with compiling copy the class files alone to ur
    web-inf classes folder.
    thats it!!!
    regards
    shanuservlets12.jar

  • Compiling java file in 11i

    I need to compile java file in CRM 11i .

    1003984 wrote:
    I need to compile java file in CRM 11i .Please see (HOW TO COMPILE JAVA FILES IN CRM APPLICATIONS [ID 468434.1]).
    Thanks,
    Hussein

  • Running a JUnit test case using Ant in Eclipse

    If I have a "JUnit", how can I run it using "Ant" in Eclipse?
    Thanks.

    Right-click on the ant build script and select "Run as ant build". But why bother? Eclipse has its own JUnit runners

  • How to capture output of java files using Runtime.exec

    Hi guys,
    I'm trying to capture output of java files using Runtime.exec but I don't know how. I keep receiving error message "java.lang.NoClassDefFoundError:" but I don't know how to :(
    import java.io.*;
    public class CmdExec {
      public CmdExec() {
      public static void main(String argv[]){
         try {
         String line;
         Runtime rt = Runtime.getRuntime();
         String[] cmd = new String[2];
         cmd[0] = "javac";
         cmd[1] = "I:\\My Documents\\My file\\CSM\\CSM00\\SmartQ\\src\\E.java";
         Process proc = rt.exec(cmd);
         cmd = new String[2];
         cmd[0] = "javac";
         cmd[1] = "I:\\My Documents\\My file\\CSM\\CSM00\\SmartQ\\src\\E";
         proc = rt.exec(cmd);
         //BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
         BufferedReader input = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
         while ((line = input.readLine()) != null) {
            System.out.println(line);
         input.close();
        catch (Exception err) {
         err.printStackTrace();
    public class E {
        public static void main(String[] args) {
            System.out.println("hello world!!!!");
    }Please help :)

    Javapedia: Classpath
    How Classes are Found
    Setting the class path (Windows)
    Setting the class path (Solaris/Linux)
    Understanding the Java ClassLoader
    java -cp .;<any other directories or jars> YourClassNameYou get a NoClassDefFoundError message because the JVM (Java Virtual Machine) can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.
    javac -classpath .;<any additional jar files or directories> YourClassName.javaYou get a "cannot resolve symbol" message because the compiler can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.

  • Java6: How to compile java using JavaCompiler class

    Hi all,
    Using JavaCompiler, we can run the java program thru programmaticaly using run() method.
    Could anyone please tell me how to compile a java program using JavaCompailer class? Or calling run() itself will compile java file?
    Thanks
    Shagil

    import spoon.support.input.SpoonInputStream;
    import com.sun.tools.javac.code.Symbol.ClassSymbol;
    import com.sun.tools.javac.comp.Attr;
    import com.sun.tools.javac.comp.AttrContext;
    import com.sun.tools.javac.comp.Enter;
    import com.sun.tools.javac.comp.Env;
    import com.sun.tools.javac.comp.Todo;
    import com.sun.tools.javac.tree.Tree;
    import com.sun.tools.javac.tree.Tree.ClassDef;
    import com.sun.tools.javac.tree.Tree.TopLevel;
    import com.sun.tools.javac.util.Abort;
    import com.sun.tools.javac.util.Context;
    import com.sun.tools.javac.util.List;
    import com.sun.tools.javac.util.ListBuffer;
    import com.sun.tools.javac.util.Log;
    import com.sun.tools.javac.util.Name;
    * The Spoon compiler (uses javac).
    public class SpoonCompiler extends com.sun.tools.javac.main.JavaCompiler {
         Attr attr;
         Enter enter;
         boolean hasBeenUsed = false;
         Log log;
         Todo todo;
         public SpoonCompiler(Context arg0) {
              super(arg0);
              enter = Enter.instance(arg0);
              todo = Todo.instance(arg0);
              log = Log.instance(arg0);
              attr = Attr.instance(arg0);
              sourceOutput=true;
          * Main method: compile a list of files, return all compiled classes
          * @param filenames
          *            The names of all files to be compiled.
         @SuppressWarnings("unused")
         public List<Tree> parseAndAttribute(List<SpoonInputStream> filenames)
                   throws Throwable {
              // as a JavaCompiler can only be used once, throw an exception if
              // it has been used before.
              assert !hasBeenUsed : "attempt to reuse JavaCompiler";
              hasBeenUsed = true;
              long msec = System.currentTimeMillis();
              ListBuffer<ClassSymbol> classes = new ListBuffer<ClassSymbol>();
              try {
                   // parse all files
                   ListBuffer<Tree> trees = new ListBuffer<Tree>();
                   for (List<SpoonInputStream> l = filenames; l.nonEmpty(); l = l.tail) {
                        trees.append(parse(l.head.getFileName(),l.head.getStream()));
                   // enter symbols for all files
                   List<Tree> roots = trees.toList();
                   if (errorCount() == 0)
                        enter.main(roots);
                   // If generating source, remember the classes declared in
                   // the original compilation units listed on the command line.
                   List<ClassDef> rootClasses = null;
                   if (sourceOutput || stubOutput) {
                        ListBuffer<ClassDef> cdefs = new ListBuffer<ClassDef>();
                        for (List<Tree> l = roots; l.nonEmpty(); l = l.tail) {
                             for (List<Tree> defs = ((TopLevel) l.head).defs; defs
                                       .nonEmpty(); defs = defs.tail) {
                                  if (defs.head instanceof ClassDef)
                                       cdefs.append((ClassDef) defs.head);
                        rootClasses = cdefs.toList();
                   while (todo.nonEmpty()) {
                        Env<AttrContext> env = todo.next();
                        // save tree prior to rewriting
                        Tree untranslated = env.tree;
                        // attribution phase
                        if (verbose)
                             printVerbose("checking.attribution", env.enclClass.sym);
                        Name prev = log.useSource(env.enclClass.sym.sourcefile);
                        attr.attribClass(env.tree.pos, env.enclClass.sym);
                   return trees.toList();
              } catch (Abort ex) {
                   ex.printStackTrace();
              if (verbose)
                   printVerbose("total", Long.toString(System.currentTimeMillis()
                             - msec));
              int errCount = errorCount();
              if (errCount == 1)
                   printerCount("error", errCount);
              else
                   printerCount("error.plural", errCount);
              if (log.nwarnings == 1)
                   printerCount("warn", log.nwarnings);
              else
                   printerCount("warn.plural", log.nwarnings);
              return null;
         private void printerCount(String str, int val) {
              System.err.println(str + " - " + val);
         private void printVerbose(String arg0, Object obj) {
              System.out.println(arg0 + " - " + obj.toString());
    --- NEW FILE: CtBuilder.java ---
    package spoon.support.builder;
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.List;
    import java.util.Map;
    import java.util.Set;
    import java.util.Stack;
    import java.util.TreeSet;
    import spoon.query.Query;
    import spoon.query.TypeFilter;
    import spoon.reflect.CtFactory;
    import spoon.reflect.code.BinaryOperatorKind;
    import spoon.reflect.code.CtAbstractInvocation;
    import spoon.reflect.code.CtArrayAccess;
    import spoon.reflect.code.CtAssert;
    import spoon.reflect.code.CtAssignment;
    import spoon.reflect.code.CtBinaryOperator;
    [...1760 lines suppressed...]
                var.setSimpleName(tree.sym.name.toString());
                var.setModifiers(getModifiers(tree.mods.flags));
                enter(var, tree);
                scan(tree.init);
                exit(var, tree);
        @Override
        public void visitWhileLoop(WhileLoop tree) {
            CtWhile whileLoop = new CtWhileImpl();
            enter(whileLoop, tree);
            builderContext.loopParameter = 1;
            scan(tree.cond);
            builderContext.loopParameter = 0;
            scan(tree.body);
            exit(whileLoop, tree);
    }

  • How does javac compile .java files?

    I dont know exactly what classpath javac uses to compile java files. i have set classpath to only tools.jar . and it compiles fine. i thought all standard java class files are present in tools.jar. But... when i opened tools.jar i didnt find most of the class files i expected to see there. In fact there was no java.lang, java.io ... so on packages in it. then how is that compiler compiled ? Of course i found rt.jar under jre/lib, which contained all the mentioned packages...but then i didnt give it in the classpath.
    Any body pls clear my doubts.

    Check out the doc "how classes are found" in the tool
    docs, it will explain how classes are found in
    detail.
    tool docs:
    http://java.sun.com/j2se/1.3/docs/tooldocs/tools.html
    I read the docs and understood that javac.exe loads dt.jar before it could compile .java files. but then what is the use of giving tools.jar in classpath.. i ve seen javac giving problems without it.

  • How to check the JDK version of a compiled java file

    can anybody tell me how to check the JDK version of a compiled java file ?
    Edited by: gbhatia8 on Sep 9, 2010 7:04 AM

    The major/minor version of the class file is the way to go.
    Also, it's not necessary to write a separate program to get to those. javap prints them out when being passed the -v flag.
    Note, however that "JDK version" is not a correct term, as I can create 1.4-compatible class files with a Java 6 JDK (by passing the -target flag to javac). Those won't look any different than .class files written with a 1.4 JDK.

  • How to run .jar on linux & how to create .jar file using java?

    hi, may i know how to run .jar on linux & how to create .jar file using java? Can u provide the steps on doing it.
    thanks in advance.

    Look at the manual page for jar:
    # man jar
    Also you can run them by doing:
    # java -jar Prog.jar

  • How to print PDF files using java print API

    Hi,
    I was goign throw lot of discusion and reading lot of forums related to print pdf files using java api. but nothing seems to be working for me. Can any one tell me how to print pdf files using java api.
    Thanks in advance

    Mike,
    Can't seem to get hold of the example described in your reply below. If you could let us have the URL to get then it would be great.
    My GUI application creates a pdf document which I need to print. I want to achieve this using the standard Java class PrinterJob (no 3rd party APIs I'm afraid, commercial restraints etc ..). I had a stab at it using the following code. When executed I get the pretty printer dialog then when I click ok to print, nothing happens!
    boolean showPrintDialog=true;
    PrinterJob printJob = PrinterJob.getPrinterJob ();
    printJob.setJobName ("Contract.pdf");
    try {
    if (showPrintDialog) {
    if (printJob.printDialog()) {
    printJob.print();
    else
    printJob.print ();
    } catch (Exception PrintException) {
                   PrintException.printStackTrace();
    Thank you and a happy new year.
    Cheers,
    Chris

  • How to open/read file using Java in Unix?

    Hi Friends,
    Can you please help me out how to open/read file using java in unix os? I have create one text file in "/home/test.txt" in unix environment. How to open the same file & read using java code?
    - Hiren Modi

    http://java.sun.com/docs/books/tutorial/essential/io/index.html

  • How to uncompress zip files using java program

    hai,
    please give some sample code to decompress the zip file.
    how to uncompress zip files using java program
    thanking you
    arivarasu

    http://developer.java.sun.com/developer/technicalArticles/Programming/PerfTuning/
    Scroll down to 'Compression'

Maybe you are looking for