How to compile a class from a Servlet using ant!!!

Hi I have the following problem:
I have a Servlet that must compile a java class.
Here is the code that i use to compile:
File buildFile = new File(build.xml path);
String[] arg = { "-buildfile", buildFile.toString(), "compile" };
Properties userProps = null;
ClassLoader loader = ClassLoader.getSystemClassLoader();
Main.start(arg, userProps, loader);
The build.xml file was written correctly, infact if i lunch the command ant by dos it is correctly done.
When I put my application in tomcat/webapps and try to compile with code above I have the following error:
BUILD FAILED C:\......: Could not create task or type of type: property.
Ant could not find the task or a class this task relies upon.
This is common and has a number of causes; the usual
solutions are to read the manual pages then download and
install needed JAR files, or fix the build file:
- You have misspelt 'property'.
Fix: check your spelling.
- The task needs an external JAR file to execute
and this is not found at the right place in the classpath.
Fix: check the documentation for dependencies.
Fix: declare the task.
- The task is an Ant optional task and the JAR file and/or libraries implementing the functionality were not found at the time you yourself built your installation of Ant from the Ant sources.
Fix: Look in the ANT_HOME/lib for the 'ant-' JAR corresponding to the task and make sure it contains more than merely a META-INF/MANIFEST.MF.
If all it contains is the manifest, then rebuild Ant with the needed libraries present in ${ant.home}/lib/optional/ , or alternatively,
download a pre-built release version from apache.org
- The build file was written for a later version of Ant Fix: upgrade to at least the latest release version of Ant
- The task is not an Ant core or optional task and needs to be declared using <taskdef>.
- You are attempting to use a task defined using <presetdef> or <macrodef> but have spelt wrong or not defined it at the point of use
Remember that for JAR files to be visible to Ant tasks implemented in ANT_HOME/lib, the files must be in the same directory or on the classpath
Please neither file bug reports on this problem, nor email the Ant mailing lists, until all of these causes have been explored, as this is not an Ant bug.

Java code Snippet
import org.apache.tools.ant.*;// ant.jar
String SourceDir="c:\java";
     String DestinationDir="c:\classes";
     Project project = new Project();
     try
String baseDir = getServletContext().getRealPath( "/WEB-INF/build/");//Build.xml should be in this folder or else make use of the build folder here
     File buildFile = new File( baseDir, "build.xml");
     project.setUserProperty( "SourceDir", SourceDir);
     project.setUserProperty( "DestinationDir", DestinationDir);
     project.setUserProperty( "ant.file", buildFile.getAbsolutePath());
     project.setBaseDir( new File( baseDir));
     project.init();
     ProjectHelper.configureProject( project, buildFile);
     project.executeTarget(project.getDefaultTarget());
     catch (Exception e)
Build.xml
<?xml version="1.0"?>
<project name="Sample" default="compile" basedir=".">
     <property name="SrcDir" value="${SourceDir}"/>
     <property name="DestnDir" value="${DestinationDir}"/>
     <target name="compile">
          <javac srcdir="${SrcDir}" destdir="${DestnDir">
               <classpath > <!-- If any supporting jars required to compile the file add this-->
                    <fileset dir="${SrcDir}" includes="*.jar" />
               </classpath>
          </javac>
     </target>
</project>

Similar Messages

  • How to compile and run a Java servlet using the BEA weblogic server

              Hi,
              Could you help me out as to how to compile a servlet using Web Logic server.I have written a Servlet program and have also set up the environment in the "c:\bea\wlserver6.0\config\examples" folder by giving the command setExamplesEnv.cmd.
              I have stored my GreetingServlet.java file in "c:\bea\wlserver6.0\samples\examples\servlets" folder.
              How do I compile my servlet now?
              Vid
              

    Hello,
    1. The .form file was used by Netbean's GUI builder to create the .java and is not needed for compilation.
    2..../src # javac -classpath "..." mytool/*.java
    I guess the package mytool was not coped with.
    Alternatively it is worth to use the ant build tool also used by Netbeans.
    Then you can make a jar from the class files, indicate in the manifest.mf file:
    1. the main class
    2. the library jars

  • Compiling a class from another class

    is it possible to compile a class from the code in another class?
    i.e I want to check whether code in a .java file will compile before I use it.
    Is there any methods that I could use to do this and could anyone give me advice on HOW to use the methods suggested?
    thanks in advance
    david

    i was looking at that but it seems to only run files, not commands
    is there a way to use it with command.com or cmd.exe or something to send commands to it?
    also if i used a readline on an inputstream it only returned the first line (i tried running a batch file so the only line it returned was ..> javac testscript.java but i spose if i put
    @echo off
    javac testscript.java
    if exist testscript.class (
    echo compiled correctly
    ) else (
    echo compiled incorectly
    so the first line returned would either be "compiled correctly" or the compile error, but this would be compiling it to see if it compiles so im not sure if this answers the first question anyway =p

  • How to call a Applet from a servlet and vice versa...?

    Hi all
    Can anyone help me how to call a applet from a servlet and vice versa. When the applet is called it should contact the database (oracle8i) and get the data. When i submit the applet form the data in the applet should be saved in the database.
    Thanks in advance
    Kamalakannan

    Sweep is correct about requestDispatcher being another approach for inter-servlet delegation; the only issue that i recall with this approach is that it defaults the method of the destination servlet to the one it was called from...for example, calling servlet2 from within servlet1.post() resulted in the dispatcher attempting to utilize servlet2.post() - i believe that i searched for a parameterize solution to no avail :( (ended up handling the request by placing a "fake" doPost() in servlet2 that simply called servlet2.doGet())
    however, if your application is functioning correctly on your pc/webserver then the problem may be external to servlet communication (e.g. client webserver's ports not configured or blocked, missing runtime classes, etc.)
    my suggestion would be to set aside the programmatic concerns for the moment - what is the response if you open a browser on a client's machine and access the URL in question (i.e. http://clientserver:port/stefanoServlet)? If it will not respond to access in this manner then it certainly won't when your application calls for it.
    It's possible that there is a coding error but, given the info supplied, i'd start examining the environment, first. Let us know if you have any luck with the test i recommended or not (please provide abundant detail). Or, if you've found the solution then you may want to post back with a quick blub so the next person knows how to escape the trap.
    D

  • How to load java class from jsp page?

    hi all!
    Does anyone know how to load java class from jsp page?
    I try to load java class from jsp page.
    Is it possible to load java class fom jsp page?
    thanks and have a good day!

    What I mean is How to load/open java class file from jsp page?
    I think we can open Applet from jsp page by using
    <applet code=helloApplet.class width=100 height=100>
    </applet>
    but, how to open java class which is an application made by Frame?
    thanks and have a good day

  • How to call Java class from Forms 6i?

    Hi friends,
    I need to call a Java class from my Forms 6i application.
    (It runs under WIndows XP. It's a client/server application and I have only the client and the Form builder installed on my PC)
    I don't know almost anything about Java's world so your help would be very useful for me.
    Could you tell me exactly what i have to do?
    I've read in metalink several Notes, but they supposed that the Java architecture is already installed in the computer.... I only have the default installation of Developer 6i... so I would need to know:
    - How to install/configure the neccesary to execute Java classes without problem
    - How to invoke the .class from Forms 6i.
    Thanks a lot
    Jose.

    And also this one:
    Problem Description
    Installed Forms 6i Rel 2 on a MS Windows machine. When trying to Import the Java
    Classes getting the errors
    PDE-UJI0001 Failed to create the JVM
    Solution Description
    You need to to install JDK 1.2.2 to run the Java Importer. And set the PATH's
    and classpath's correctly.
    Explanation
    1. Download and install the JDK 1.2.2.
    Possibly available at: http://java.sun.com/products/archive/
    2. Assuming the JDK 1.2.2 is installed in c:\jdk1.2.2 directory and the JRE in
    C:\PROGRA~1\JAVASOFT\JRE\1.2 directory; ORACLE_HOME=C:\Dev6iR2.
    Set the PATH to
    set PATH=c:\jdk1.2.2\bin;C:\PROGRA~1\JAVASOFT\JRE\1.2\bin;C:\PROGRA~1\JAVASOFT\JRE\1.2\bin\classic;%PATH%
    ( If you are using ias9i then the JDK 1.2.2 comes with the ias installtion ,
    in this case please set the PATH to
    D:\ias9i\Apache\jdk\bin;D:\ias9i\Apache\jdk\jre\bin;D:\ias9i\Apache\jdk\jre\bin\classic;%PATH% )
    3. Set the CLASSPATH to set CLASSPATH=%CLASSPATH%;C:\Dev6iR2\TOOLS\COMMON60\JAVA\IMPORTER.JAR;.
    (If you do not set the CLASSPATH correctly you will get the error
    PDE-UJI002 Unable to find the required java importer classes)
    4. Now run the Forms Builder by using the command.
    C:\Dev6iR2\bin\ifbld60.exe
    Now the Java Importer Should Run fine.
    Francois

  • How to download a file from the internet using terminal

    how to download a file from the internet using terminal
    does any one know how to download afile from the internet using the Terminal application?

    Use curl. Something like this:
    curl -O http://www.example.com/filename.zip
    For more info, type +man curl+.

  • How to read a data from USB port using JAVA

    hi all,
    i need to know how to read a data from USB port using java. any API are available for java ?.........please give your valuable ideas !!!!!!!!!
    Advance Thanks!!

    You can do this. Please use this link
    [http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&hs=uHu&q=java+read+data+from+usb+port&btnG=Search&meta=&aq=f&oq=]
    What research did you do of your own? Have you done some testing application and tried yourself??

  • How do i get data from a structure using join?

    hi,
    what is the actual use of a structure.?
    my problem is :
    KUAGV is an existing STRUCTURE. it has got one fields each which links to MARA, AND VBKD tables. i want to fetch all related information from KUAGV, mara, vbkd . which is the better way : using joins or views or anything else? how do i
    get data from a structure using join?

    structure temporarily holds  any data passed to it dynamically throughout the runtime but doesnot store it permanently. so
    a structure cannot be included in a join.so instead of incuding structure KUAGV's field in a join 
    search the transparent table in which same field are present and  use it in join.
    A structure if created in DDIC(Data Dictionary) is a global DATA STRUCTURE which is used to group related information, for example you would group all the details of your bank account into a structure BANK_ACCOUNT that contains fields like account_Id, account_holder_name etc.
    If you create a structure in your program then it is local to your program. So you use this structure to create data holders of this DATA TYPE to hold data in your program.
    Edited by: suja thomas on Feb 11, 2008 6:24 AM
    Edited by: suja thomas on Feb 11, 2008 6:31 AM

  • How do I extract pages from a pdf using 'Adobe PDF Pack'?

    How do I extract pages from a pdf using 'Adobe PDF Pack'?

    I think you have to buy extractor for 1.99 a month to extract PDF.  But I am having trouble activating it.  Good luck.

  • How can I get permission from imovie to use text in my uploaded monetized YouTube clips

    I am able to use imovie to edit movies. I use a small amount of text and no music from imovie. How do I obtain permission from imovie to use a text title for my monetized YouTube uploads?

    You do not need permission for this.

  • How to transfer range parameter from vb when using bapi calling

    Hi,everyone.how to transfer range parameter from vb when using BAPI calling?

    Did you get the solution to your problem?  Can you please share it with me. I have a similar problem. I have a VB program that calls RFC function. It works with a single parameter but not with a range of parameters. If you have the solution, could you please share sample codes with me? Thank you so much.

  • How to compile your flex application for Iphone Using Adobe Flash CS5?

    How to compile your flex application for Iphone Using Adobe Flash CS5?

    I'm so sorry, I'm not really familiar with the codes.

  • How can i send pictures from iphoto and use entourage

    how can i send pictures from iphoto and use entourage. I use to do it when I used Mac OS Leopard

    Click on the image in question and execute COMMAND D which will copy an image in iPhoto.
    To delete an image in iPhoto, execute COMMAND DELETE.
    Ciao.

  • How do I transfer video from gopro hero3 using a 64 GB microSDXC CARD

    How do I transfer video from gopro hero3 using a 64 GB microSDXC CARD

    iPad SD Card Reader supports SD standards up to SDHC, miniSD and microSD with adapters, and MMC.
    SDXC is not supported.

Maybe you are looking for

  • No backend PO in ECC5?

    Hi Gurus, Please can someone shed some light on the following error. We have activated extended classic scen in srm 5.0, but our srm PO does not replicate over to ECC5 as a display only doc. The checks our basis team have undertaken are: i. No idocs

  • Getting error in calling Java Script function in HTMLB page

    Hi   I am having a button in HTMLB page which calls the Java Script function for click event.I have included the Java Script in the script folder of the application. I am calling the function present in JS like this, <SCRIPT src="portalsdc.js"></SCRI

  • Mac now seeing mp4 as a document rather than a movie file

    Hi all Not sure if this is posted in the right forum. Pls point me in the right direction if it's not Over the last couple of days when I download a mp4 file it shows it as a document instead of a movie file and i can't play it with quicktime player

  • Running a command from local zone in global zone

    hi, Does anyone have a document on how I can tunnel into the global zone, run a command and receive the return value in the global zone? I am sure that there should be a mechanism for that but couldn't find any. Thanks, Babak

  • BLOB vs. LONG RAW - size restrictions?

    In the Oracle Lite 10g release notes, it states... 1.3.1 BLOB Support in the Oracle Lite Database Most of the data is stored in the Oracle Lite database file with an ODB extension; any BLOB objects-either binary or character-and the indexes are store