您的位置:程序门 -> java -> j2ee / ejb / jms



编程调用ant javac api出错


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


编程调用ant javac api出错[已结贴,结贴人:ptqw]
发表于:2007-03-30 21:28:14 楼主
以编程方式调用ant编译源文件(不用xml),代码如下:
    javac   compiler   =   new   javac();
                compiler.setproject(new   project());
                file   destfile   =   new   file(buildfillepath);
                path   srcpath   =   new   path(compiler.getproject(),   srcfilepath);
                compiler.setsrcdir(srcpath);
                compiler.setdestdir(destfile);
                compiler.setcompiler( "extjavac ");
                try   {
                        compiler.EXECute();
                }
                catch   (buildexception   e)   {
                        e.printstacktrace();
                }

报错如下:

error   running   javac.exe   compiler
at   org.apache.tools.ant.taskdefs.compilers.defaultcompileradapter.EXECuteexternalcompile(defaultcompileradapter.java:473)
at   org.apache.tools.ant.taskdefs.compilers.javacexternal.EXECute(javacexternal.java:47)
at   org.apache.tools.ant.taskdefs.javac.compile(javac.java:931)
at   org.apache.tools.ant.taskdefs.javac.EXECute(javac.java:757)
at   hello_world.actions.sampleaction.testantcompile(sampleaction.java:172)
at   hello_world.actions.sampleaction.run(sampleaction.java:85)
at   org.eclipse.ui.internal.pluginaction.runwithevent(pluginaction.java:254)
at   org.eclipse.ui.internal.wwinpluginaction.runwithevent(wwinpluginaction.java:229)
at   org.eclipse.jface.action.actioncontributionitem.handlewidgetselection(actioncontributionitem.java:539)
at   org.eclipse.jface.action.actioncontributionitem.access$2(actioncontributionitem.java:488)
at   org.eclipse.jface.action.actioncontributionitem$6.handleevent(actioncontributionitem.java:441)
at   org.eclipse.swt.widgets.eventtable.sendevent(eventtable.java:66)
at   org.eclipse.swt.widgets.widget.sendevent(widget.java:928)
at   org.eclipse.swt.widgets.display.rundeferredevents(display.java:3348)
at   org.eclipse.swt.widgets.display.readanddispatch(display.java:2968)
at   org.eclipse.ui.internal.workbench.runeventloop(workbench.java:1930)
at   org.eclipse.ui.internal.workbench.runui(workbench.java:1894)
at   org.eclipse.ui.internal.workbench.createandrunworkbench(workbench.java:422)
at   org.eclipse.ui.platformui.createandrunworkbench(platformui.java:149)
at   org.eclipse.ui.internal.ide.ideapplication.run(ideapplication.java:95)
at   org.eclipse.core.internal.runtime.platformactivator$1.run(platformactivator.java:78)
at   org.eclipse.core.runtime.internal.adaptor.eclipseapplauncher.runapplication(eclipseapplauncher.java:92)
at   org.eclipse.core.runtime.internal.adaptor.eclipseapplauncher.start(eclipseapplauncher.java:68)
at   org.eclipse.core.runtime.adaptor.eclipsestarter.run(eclipsestarter.java:400)
at   org.eclipse.core.runtime.adaptor.eclipsestarter.run(eclipsestarter.java:177)
at   sun.reflect.nativemethodaccessorimpl.invoke0(native   method)
at   sun.reflect.nativemethodaccessorimpl.invoke(unknown   source)
at   sun.reflect.delegatingmethodaccessorimpl.invoke(unknown   source)
at   java.lang.reflect.method.invoke(unknown   source)
at   org.eclipse.core.launcher.main.invokeframework(main.java:336)
at   org.eclipse.core.launcher.main.basicrun(main.java:280)
at   org.eclipse.core.launcher.main.run(main.java:977)
at   org.eclipse.core.launcher.main.main(main.java:952)
caused   by:   java.io.ioexception:   createprocess:   javac.exe   -d   e:\study\test2   -classpath   "e:\study\test2;d:\eclipse   ide\wtp-sup\eclipse\startup.jar "   -sourcepath   e:\study\test1   -g:none   e:\study\test1\student.java   e:\study\test1\bobo\prepareteststudentmanager.java   e:\study\test1\bobo\reflectmanager.java   e:\study\test1\bobo\student.java   e:\study\test1\bobo\studentmanager.java   e:\study\test1\bobo\synchronizedaccord.java   e:\study\test1\bobo\testmain.java   e:\study\test1\bobo\reflect\reflectmain.java   e:\study\test1\bobo\reflect\reflectmanager.java   e:\study\test1\bobo\reflect\student.java   e:\study\test1\bobo\util\propetiesmanager.java   e:\study\test1\bobo\util\testpropertiesmanager.java   error=2
at   java.lang.processimpl.create(native   method)
at   java.lang.processimpl. <init> (unknown   source)
at   java.lang.processimpl.start(unknown   source)
at   java.lang.processbuilder.start(unknown   source)
at   java.lang.runtime.EXEC(unknown   source)
at   sun.reflect.nativemethodaccessorimpl.invoke0(native   method)
at   sun.reflect.nativemethodaccessorimpl.invoke(unknown   source)
at   sun.reflect.delegatingmethodaccessorimpl.invoke(unknown   source)
at   java.lang.reflect.method.invoke(unknown   source)
at   org.apache.tools.ant.taskdefs.EXECute$java13commandlauncher.EXEC(EXECute.java:834)
at   org.apache.tools.ant.taskdefs.EXECute.launch(EXECute.java:435)
at   org.apache.tools.ant.taskdefs.EXECute.EXECute(EXECute.java:449)
at   org.apache.tools.ant.taskdefs.compilers.defaultcompileradapter.EXECuteexternalcompile(defaultcompileradapter.java:470)
...   32   more

请教下各位大大问题出在哪?最好给出修改过的源码,谢谢!


发表于:2007-04-02 11:31:401楼 得分:20
java.io.ioexception,
应该是你调用的java文件有问题。
发表于:2007-04-02 14:18:042楼 得分:20
该回复于2007-12-28 11:55:16被管理员或版主删除
发表于:2007-04-02 15:32:293楼 得分:0
问题已解决

javac   compiler   =   new   javac();
                compiler.setproject(new   project());
                file   destfile   =   new   file(buildfillepath);
                path   srcpath   =   new   path(compiler.getproject(),   srcfilepath);
                compiler.setfork(true);
                compiler.setsrcdir(srcpath);
                compiler.setdestdir(destfile);
                try   {
                        compiler.EXECute();
                }
                catch   (buildexception   e)   {
                        e.printstacktrace();
                }

这样就对了,会报以上的错是因为classpath没设,汗。。。


快速检索

最新资讯