`
夜乡晨
  • 浏览: 37517 次
  • 性别: Icon_minigender_1
  • 来自: 重庆
社区版块
存档分类
最新评论

解决Java 调用 Ant 包含 <import> 异常:import requires support in ProjectHelper

阅读更多
package tiger;

import java.io.File;

import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;

public class AntTest {
	private Project project;

	public void init(String _buildFile, String _baseDir) throws Exception {
		project = new Project();

		project.init();

		DefaultLogger consoleLogger = new DefaultLogger();
		consoleLogger.setErrorPrintStream(System.err);
		consoleLogger.setOutputPrintStream(System.out);
		consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
		project.addBuildListener(consoleLogger); 
		
		// Set the base directory. If none is given, "." is used.
		if (_baseDir == null)
			_baseDir = new String(".");

		project.setBasedir(_baseDir);

		if (_buildFile == null)
			_buildFile = new String(
					"E:/JEE/Workspaces/MyEclipse 8.6/Study/src/tiger/a.xml");

		//ProjectHelper.getProjectHelper().parse(project, new File(_buildFile));
		// 关键点
		ProjectHelper.configureProject(project, new File(_buildFile));
	}

	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
		project.executeTarget(_target);

	}

	public static void main(String args[]) {
		try {
			AntTest mytest = new AntTest();
			mytest.init(
					"E:/JEE/Workspaces/MyEclipse 8.6/Study/src/tiger/c.xml",
					".");
			mytest.runTarget(null);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

 a.xml

<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="runtests" name="TestA">
	<target name="runtests" depends="">
		<echo message="Tiger" />
	</target>
</project>

 c.xml

<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="runtests" name="TestC">
	<import file="a.xml" />
</project>
 

 

分享到:
评论

相关推荐

    A+ Certification Practice Questions Exam Cram 2

    Que (March 20, 2004) &lt;br&gt;Language: English &lt;br&gt;ISBN-10: 0789731088 &lt;br&gt;ISBN-13: 978-0789731081 &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;The A+ certification is the most popular certification program in the world, certifying ...

    visual assist 1640

    新的版本又发布了,下载地址,&lt;br&gt;http://www.wholetomato.com/binaries/VA_X_Setup1640.exe&lt;br&gt;&lt;br&gt;这个版本已经是正式版了,稳定性没的说,中文的问题已经得到了很好的解决,已经可以正常显示了,只是包含有中文的...

    tomcat-5.5.23

    ============================================&lt;br&gt;&lt;br&gt;Out of the box, Tomcat 5.5 requires the Java 2 Standard Edition Runtime&lt;br&gt;Environment (JRE) version 5.0 or later. However, you can also run Tomcat...

    AspxBBS论坛 v2.5 正式版

    有些服务器的MDAC版本还是2.5的,如果MDAC的版本太低的话,会有如下出错信息:&lt;br&gt; The .Net Data OLE DB Provider(System.Data.OleDb) requires Microsoft Data Access Components(MDAC) version 2.6 or later....

    subclipse 1.4.1

    Subclipse 1.4.x requires Subversion 1.5.0 version of JavaHL/SVNKit &lt;br&gt;&lt;br&gt;Links for 1.4.x Release:&lt;br&gt;Changelog: http://subclipse.tigris.org/subclipse_1.4.x/changes.html&lt;br&gt;Eclipse update site URL: ...

    Using DIB Sections in VB

    &lt;br&gt;&lt;br&gt; m_hDC = CreateCompatibleDC(0) &lt;br&gt; If (m_hDC &lt;&gt; 0) Then &lt;br&gt; If (CreateDIB(m_hDC, lWidth, lHeight, m_hDIb)) Then &lt;br&gt; m_hBmpOld = SelectObject(m_hDC, m_hDIb) &lt;br&gt; Create = True &lt;br&gt; Else &lt;br...

    Android开发中LogCat工具的使用

    过滤器的格式是一个这样的串:&lt;tag&gt;[:priority],其中 `&lt;tag&gt;` 表示 log 的 component,tag (或者使用 `*` 表示所有),priority 如下所示: * `V`:Verbose * `D`:Debug * `I`:Info * `W`:Warn * `E`:Error * `...

    DIBSection Class VB

    &lt;br&gt;&lt;br&gt; m_hDC = CreateCompatibleDC(0) &lt;br&gt; If (m_hDC &lt;&gt; 0) Then &lt;br&gt; If (CreateDIB(m_hDC, lWidth, lHeight, m_hDIb)) Then &lt;br&gt; m_hBmpOld = SelectObject(m_hDC, m_hDIb) &lt;br&gt; Create = True &lt;br&gt; Else &lt;br...

    VB编程资源大全(英文源码 网络)

    &lt;END&gt;&lt;br&gt;12 , telnet.zip&lt;br&gt;Telnet Application&lt;END&gt;&lt;br&gt;13 , validip.zip&lt;br&gt;Validate an IP address&lt;br&gt;14 , dmvbtest.zip&lt;br&gt;This is a complete email sending client in Visual Basic&lt;END&gt;&lt;br&gt;15 , ...

    C++20 Concepts简介

    template&lt;&gt; struct Printer&lt;std::string&gt; { void print(std::string s) { std::cout &lt;&lt; "Printing string: " &lt;&lt; s &lt;&lt; '\n'; } }; ``` ##### 3.7 使用多个 Concepts 有时需要组合多个概念来形成更复杂的类型约束...

    VB编程资源大全(英文源码 控件)

    resizable7segment_source.zip&lt;br&gt;An Active-X control that simulates a 7 segment L.E.D display.&lt;END&gt;&lt;br&gt;18 , xartery1.zip&lt;br&gt;20 image digital art gallery in 2 galleries, housed in an mdiform.&lt;END&gt;&lt;br&gt;...

    adb错误解决方法

    解决方法包括重启adb服务器(通过命令`adb kill-server`和`adb start-server`),检查系统是否有其他占用adb端口的应用,并确保系统资源充足。 再者,当设备无法连接到电脑时,检查USB连接的稳定性是必要的。尝试...

    VB编程资源大全(英文源码 DirectX)

    &lt;END&gt;&lt;br&gt;10,DXHelp.zip&lt;br&gt;Gives some meaningful error codes instead of the traditional archaic automation errors.&lt;END&gt;&lt;br&gt;11,ColDet.zip&lt;br&gt;Detecting collisions between polygons.&lt;END&gt; &lt;br&gt;12,AscPlay....

    Alcohol 120%

    Windows 95 must be OSR2 or later version&lt;br&gt;&lt;br&gt;32MB (or more) of RAM&lt;br&gt;&lt;br&gt;10GB (or more) hard disk is recommended (a 74 minute CD image requires 650-700MB)&lt;br&gt;&lt;br&gt;One or more bus-mastering SCSI ...

    NVM(NodeJS version manager)

    - `nvm install &lt;version&gt;`:安装指定版本的Node.js。 - `nvm uninstall &lt;version&gt;`:卸载指定版本的Node.js。 - `nvm use &lt;version&gt;`:切换到指定版本的Node.js。 - `nvm current`:查看当前正在使用的Node.js版本...

    Visual assist x 10.4.1616 and crack

    Build 1616&lt;br&gt;requires software maintenance through 2007.11.08. (Release candidate.) &lt;br&gt;New! Create VA Snippet from selection. &lt;br&gt;.NET references are now parsed even when 'parse all files' is ...

    visual assist v 10.4.1632 with crack

    (case=9436) &lt;br&gt;STL list&lt;&gt; and vector&lt;&gt; member lists appear correctly following a "using namespace std::list" or "using namespace std::vector" directive. (case=12345) 7226 &lt;br&gt;Empty C++ preprocessor ...

Global site tag (gtag.js) - Google Analytics