Here is the code I'm using - AntRunner.java - which attempts to spin up ant
 
import org.apache.tools.ant.*;
import java.io.*;
import java.util.*;
 
public class AntRunner {
 private Project project;
 public void init(String _buildFile, String _baseDir) throws Exception {
  project = new Project();
  try { project.init(); }
  catch (BuildException e) {
   throw new Exception("The default task list could not be loaded.");
  }
  // Set the base directory. If none is given, "." is used.
  if (_baseDir == null) _baseDir=new String(".");
  try {
   project.setBasedir(_baseDir);
  }
  catch (BuildException e) {
   throw new Exception("The given basedir doesn't exist, or isn't a directory.");
  }
  
  if (_buildFile == null) _buildFile=new String("build.xml");
  System.out.println("_baseDir=" + _baseDir);
  System.out.println("_buildFile=" + _buildFile);
  try {
   ProjectHelper.getProjectHelper().parse(project, new File(_buildFile));
  }
  catch (BuildException e) {
   throw new Exception("Configuration file "+_buildFile+" is invalid, or cannot be read.");
  }
 }

 public void runTarget(String _target) throws Exception {
  // Test if the project exists
  if (project == null) throw new Exception("No target can be launched because the project has not been initialized. Please call the 'init' method first !");
  // If no target is specified, run the default one.
  if (_target == null) _target = project.getDefaultTarget();
  // Run the target
  try {
   project.executeTarget(_target);
  }
  catch (BuildException e) {
   throw new Exception(e.getMessage());
  }
 }
 public static void main(String args[]) {
  try{
   AntRunner ar=new AntRunner();     
   ar.init("test",".");     
   ar.runTarget("main");
  }catch(Exception e) {
   e.printStackTrace();
  }
 }
}
 
 
-----Original Message-----
From: [EMAIL PROTECTED]
To: [email protected]
Sent: Tue, 25 Jul 2006 9:28 AM
Subject: Re: [Webtest] java.lang.Exception: Could not create task or type of type: testSpec.

Hi

It looks like ant isn't finding some dependencies (xml parser?).
Since you don't tell us what AntRunner.java is doing, I suggest you take a look at bin/webtest.bat to look at how to setup the classpath before calling ant.

Best
dna

On 25 juil. 06, at 14:43, [EMAIL PROTECTED] wrote:

Hello all,
 
It looks like I am missing a jar file but am not sure - I am getting this error while running java code that spins up an ant process.
 
My script works when it is run from webtest.bat.
 
When run from java.exe, I get
C:\webtest\doc\doc\samples>java AntRunner
_baseDir=.
_buildFile=test.xml
java.lang.Exception: Configuration file test.xml is invalid, or cannot be read.
        at AntRunner.init(AntRunner.java:36)
        at AntRunner.main(AntRunner.java:60)
C:\webtest\doc\doc\samples>
 
Here is my script:
<?xml version="1.0"?>
<!DOCTYPE project SYSTEM "WebTest.dtd">
<project name="test" basedir="." default="main">
    <import file="C:/webtest/lib/taskdef.xml"/>
    <target name="main">
  <testSpec name="myTest">
  </testSpec>
 </target>
</project>
I am including webtest.jar in my classpath and taskdef.xml is in c:\webtest\lib - what's going on here?
 
Thanks in advance
Doug

Check out AOL.com today. Breaking news, video search, pictures, email and IM. All on demand. Always Free.

-- 
Buy a fast box with Windows NT, and you'll spend less time
with your family.
  -- Steve Jobs

=

Reply via email to