You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Alexey Mel'nikoff <al...@gmail.com> on 2007/09/14 13:39:47 UTC
When using ExecuteJava in other class, JVM don't allow to create streams.
I try to create ant task which launch java in separate VM with
specified paramaters.
I try to execute class, which creates output and input streams.
When I did it in <java/> task, all works, but when I try to use it
in my task, streams are not created.
And class from lib can't work with files and user inputs.
There a part of my code:
import java.io.File;
import java.util.ArrayList;
import java.util.Collection ;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ExitStatusException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.ExecuteJava ;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
public class InstallDocAppsTask extends Task {
private boolean failonerror = false;
private File docapppath;
private Reference classpathref;
private String classname;
private String docbase;
private String domain;
private String installlog;
private String username;
private String userpass;
public InstallDocAppsTask() {
super();
}
/**
* Do the execution.
*
* @throws BuildException
* if failOnError is set to true and the application returns a
* nonzero result code.
*/
public void execute() throws BuildException {
String[] files = docapppath.list();
Collection<File> dirs = new ArrayList<File>();
for (int i = 0; i < files.length; i++) {
File tmp = new File(docapppath.getAbsolutePath() + "\\" + files[i]);
if (tmp.isDirectory()) {
dirs.add(tmp);
}
}
if (dirs.size() != 0) {
int err = -1;
for (File dir : dirs) {
ExecuteJava exe = new ExecuteJava();
exe.setClasspath ((Path) classpathref.getReferencedObject());
Cmdline cmd = new Cmdline();
cmd.setExecutable(classname);
cmd.createArgument().setValue("-d " + docbase);
cmd.createArgument().setValue("-n " + username);
cmd.createArgument().setValue("-p " + userpass);
if (domain != null && domain.trim().length() != 0) {
cmd.createArgument().setValue("-m " + domain);
}
cmd.createArgument().setValue("-a " + "\"" +
dir.getAbsolutePath() + "\"");
if (installlog != null && installlog.trim().length() != 0) {
cmd.createArgument().setValue("-l " + "\"" +
(installlog.endsWith("\\") ?
installlog : installlog +
"\\") + dir.getName() + "\"");
}
exe.setJavaCommand(cmd);
err = exe.fork(this);
if (err != 0) {
if (isFailonerror()) {
throw new ExitStatusException("Java returned: " + err,
err, getLocation());
} else {
log("Java Result: " + err, Project.MSG_ERR);
}
}
}
} else {
log("Direcory " + docapppath + " does not contain
subdirectories, wich may contain DocApps", Project.MSG_ERR);
}
}
public void setDocbase(String docbase) {
this.docbase = docbase;
}
public void setUsername(String username) {
this.username = username;
}
public void setUserpass(String userpass) {
this.userpass = userpass;
}
public void setDomain(String domain) {
this.domain = domain;
}
public void setInstalllog(String installlog) {
this.installlog = installlog;
}
public void setDocapppath(File docapppath) {
this.docapppath = docapppath;
}
public void setFailonerror(boolean failonerror) {
this.failonerror = failonerror;
}
public void setClasspathref(Reference classpathref) {
this.classpathref = classpathref;
}
public void setClassname(String classname) {
this.classname = classname;
}
public class Cmdline extends Commandline {
@Override
public String describeCommand() {
return "";
}
@Override
public String describeArguments() {
return "";
}
}
public boolean isFailonerror() {
return failonerror;
}
}
---
Sorry for my bad English.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: When using ExecuteJava in other class, JVM don't allow to create streams.
Posted by Alexey Mel'nikoff <al...@gmail.com>.
Any one can help me?
I try to extend Java task, and I get same error. Class which I try to
execute cannot get output and input streams.
This my code:
package com.reksoft.documentum.tools.ant.taskdefs.dai;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ExitStatusException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Java;
import org.apache.tools.ant.types.CommandlineJava;
import org.apache.tools.ant.types.Reference;
public class InstallDocAppsTask extends Java {
private boolean failonerror = false;
private File docapppath;
private Reference classpathref;
private String classname;
private String docbase;
private String domain;
private String installlog;
private String username;
private String userpass;
private Cmdline cmdl = new Cmdline();
public InstallDocAppsTask() {
super();
}
/**
* Do the execution.
*
* @throws BuildException
* if failOnError is set to true and the
application returns a
* nonzero result code.
*/
public void execute() throws BuildException {
String[] files = docapppath.list();
Collection<File> dirs = new ArrayList<File>();
for (int i = 0; i < files.length; i++) {
File tmp = new
File(docapppath.getAbsolutePath() + "\\" + files[i]);
if (tmp.isDirectory()) {
dirs.add(tmp);
}
}
if (dirs.size() != 0) {
int err = -1;
for (File dir : dirs) {
Cmdline cmd = new Cmdline();
cmd.setClassname(classname);
cmd.createClasspath(getProject()).createPath().setRefid(classpathref);
cmd.createArgument().setValue("-d " + docbase);
cmd.createArgument().setValue("-n " + username);
cmd.createArgument().setValue("-p " + userpass);
if (domain != null &&
domain.trim().length() != 0) {
cmd.createArgument().setValue("-m " + domain);
}
cmd.createArgument().setValue("-a " +
"\"" + dir.getAbsolutePath() + "\"");
if (installlog != null &&
installlog.trim().length() != 0) {
cmd.createArgument().setValue("-l " + "\"" +
(installlog.endsWith("\\") ?
installlog : installlog + "\\") + dir.getName() +
"\"");
}
setCommandLine(cmd);
err = executeJava();
if (err != 0) {
if (isFailonerror()) {
throw new
ExitStatusException("Java returned: " + err,
err,
getLocation());
} else {
log("Java Result: " +
err, Project.MSG_ERR);
}
}
}
} else {
log("Direcory " + docapppath + " does not
contain subdirectories,
wich may contain DocApps", Project.MSG_ERR);
}
}
public void setDocbase(String docbase) {
this.docbase = docbase;
}
public void setUsername(String username) {
this.username = username;
}
public void setUserpass(String userpass) {
this.userpass = userpass;
}
public void setDomain(String domain) {
this.domain = domain;
}
public void setInstalllog(String installlog) {
this.installlog = installlog;
}
public void setDocapppath(File docapppath) {
this.docapppath = docapppath;
}
public void setFailonerror(boolean failonerror) {
this.failonerror = failonerror;
}
public void setClasspathrefId(Reference classpathref) {
this.classpathref = classpathref;
}
public void setClassname(String classname) {
this.classname = classname;
}
public class Cmdline extends CommandlineJava {
@Override
public String describeCommand() {
return "";
}
}
public boolean isFailonerror() {
return failonerror;
}
public Cmdline getCommandLine() {
return cmdl;
}
public void setCommandLine(Cmdline cmdline) {
this.cmdl = cmdline;
}
}
--
----
------
--------
----------
Как его там "виз бест регардс энд всё такое" :)
Re: When using ExecuteJava in other class, JVM don't allow to create streams.
Posted by Alexey Mel'nikoff <al...@gmail.com>.
Any one can help me?
I try to extend Java task, and I get same error. Class which I try to
execute cannot get output and input streams.
This my code:
package com.reksoft.documentum.tools.ant.taskdefs.dai;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ExitStatusException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Java;
import org.apache.tools.ant.types.CommandlineJava;
import org.apache.tools.ant.types.Reference;
public class InstallDocAppsTask extends Java {
private boolean failonerror = false;
private File docapppath;
private Reference classpathref;
private String classname;
private String docbase;
private String domain;
private String installlog;
private String username;
private String userpass;
private Cmdline cmdl = new Cmdline();
public InstallDocAppsTask() {
super();
}
/**
* Do the execution.
*
* @throws BuildException
* if failOnError is set to true and the application returns a
* nonzero result code.
*/
public void execute() throws BuildException {
String[] files = docapppath.list();
Collection<File> dirs = new ArrayList<File>();
for (int i = 0; i < files.length; i++) {
File tmp = new File(docapppath.getAbsolutePath() + "\\" + files[i]);
if (tmp.isDirectory()) {
dirs.add(tmp);
}
}
if (dirs.size() != 0) {
int err = -1;
for (File dir : dirs) {
Cmdline cmd = new Cmdline();
cmd.setClassname(classname);
cmd.createClasspath(getProject()).createPath().setRefid(classpathref);
cmd.createArgument().setValue("-d " + docbase);
cmd.createArgument().setValue("-n " + username);
cmd.createArgument().setValue("-p " + userpass);
if (domain != null && domain.trim().length() != 0) {
cmd.createArgument().setValue("-m " + domain);
}
cmd.createArgument().setValue("-a " + "\"" + dir.getAbsolutePath() + "\"");
if (installlog != null && installlog.trim().length() != 0) {
cmd.createArgument().setValue("-l " + "\"" + (installlog.endsWith("\\") ?
installlog : installlog + "\\") + dir.getName() + "\"");
}
setCommandLine(cmd);
err = executeJava();
if (err != 0) {
if (isFailonerror()) {
throw new ExitStatusException("Java returned: " + err,
err, getLocation());
} else {
log("Java Result: " + err, Project.MSG_ERR);
}
}
}
} else {
log("Direcory " + docapppath + " does not contain subdirectories,
wich may contain DocApps", Project.MSG_ERR);
}
}
public void setDocbase(String docbase) {
this.docbase = docbase;
}
public void setUsername(String username) {
this.username = username;
}
public void setUserpass(String userpass) {
this.userpass = userpass;
}
public void setDomain(String domain) {
this.domain = domain;
}
public void setInstalllog(String installlog) {
this.installlog = installlog;
}
public void setDocapppath(File docapppath) {
this.docapppath = docapppath;
}
public void setFailonerror(boolean failonerror) {
this.failonerror = failonerror;
}
public void setClasspathrefId(Reference classpathref) {
this.classpathref = classpathref;
}
public void setClassname(String classname) {
this.classname = classname;
}
public class Cmdline extends CommandlineJava {
@Override
public String describeCommand() {
return "";
}
}
public boolean isFailonerror() {
return failonerror;
}
public Cmdline getCommandLine() {
return cmdl;
}
public void setCommandLine(Cmdline cmdline) {
this.cmdl = cmdline;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org