To run the ant script, I use the exec method for the java.lang.Runtime class as follows:
Process process = Runtime.getRuntime (). Exec (JAVA_HOME ANT_HOME -jar / lib / ant -launcher.jar-BuildFile file.xml);
This method, despite its apparent simplicity, but it creates several problems and is described in javadoc as follows:
Because some proprietary platforms provide a limited buffer size for standard input and output streams, the inability to quickly write input to a stream or read the output of a subprocess. May cause blocking subprocess and even deadlock.
To solve this problem, I mentioned the following article: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=1 This method worked on non-machine (64-bit Windows 7 , Core 2 Quad Q9400 @ 2.66 GHz 2.67 GHz, 4 GB) But when I used another machine (XP SP3, Core 2 Duo 2.99 GHz at 3 GHz, 3.21 GB of memory), the process freezes when creating data schemes, and the console remains in desperate silence after reporting the following message:
[hibernatetool] Executing the Hibernate tool with the JPA setting Warning: the link is not compilation.classpath.id HAS was set to runtime, the target of WAS DURING was found parsing the assembly file, attempting to resolve. Future versions of ant May contain identifier references Defined for unfulfilled purposes.
[Hibernatetool] 1. Task: hbm2ddl (Creates a database schema).
Have you encountered such a problem? Do you have a solution for me? I am open to any decision. Note: my ant script looks like this:
<project> .. <target name="create-jpa-schema"> <tstamp> <format property="timestamp.for.sql" pattern="yyyy-MM-dd_HH-mm-ss" /> </ Tstamp> <hibernatetool destdir="${build.sql.dir}"> <classpath> <path refid="classpath.id" /> <pathelement path="${model.jar}" /> </ Classpath> <jpaconfiguration persistenceunit="studio-pu" /> <! - Export schema to SQL database and run it Against -> <Hbm2ddl drop = "false" update = "true" create = "true" export = "true" outputfilename = "$ {schema_ timestamp.for.sql}. Sql" delimiter = "" format = "true" haltOnError = "true "/> </ Hibernatetool> </ Target> .. </ Project>
EDIT: Code executing runtime.exec:
public static int executeCommand( String cmd, File directory) throws IOException, InterruptedException { Process process = Runtime.getRuntime().exec(cmd, null, directory); StreamReader outputStreamReader = new StreamReader( process.getInputStream(), "OUTPUT"); StreamReader errorStreamReader = new StreamReader(process.getErrorStream(), "ERROR"); final Thread outputThreadReader = new Thread(outputStreamReader); final Thread errorThreadReader = new Thread(errorStreamReader); outputThreadReader.start(); errorThreadReader.start(); int exitCode = process.waitFor(); System.out.println("exit code:" + exitCode); return exitCode; }
StreamReader.java
public class StreamReader implements Runnable { InputStream is; OutputStream os; String type; StreamReader(InputStream is, String type) { this.is = is; this.type = type; } StreamReader(InputStream is, OutputStream os, String type) { this.is = is; this.os = os; this.type = type; } @Override public void run() { try { PrintWriter pw = null; if (os != null) pw = new PrintWriter(os); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) { if (pw != null) { pw.println(line); pw.flush(); } else System.out.println(type + ">" + line); if(progressListener!=null) progressListener.onUpdate(line); } } catch (IOException ioe) { ioe.printStackTrace(); } } }