Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Ant, how do I open a file in a browser?

Tags:

ant

I have an Ant task that creates an HTML report. Is it possible to load that report automatically in a browser from the Ant task? If so, is it possible to do so in a user-independent way or would it require the use of custom user properties?

Thanks,

Paul

like image 516
Paul Avatar asked Jan 14 '11 21:01

Paul


2 Answers

I used <script> with javascript:

<property name="mydirectory" location="target/report"/>

<script language="javascript"><![CDATA[
    location = "file:///"+project.getProperty("mydirectory").toString().replaceAll("\\\\","/")+"/index.html";
    java.awt.Desktop.getDesktop().browse(java.net.URI.create(location));
]]></script>
like image 99
Gabor Imre Avatar answered Sep 30 '22 12:09

Gabor Imre


There is an independent way, like we do in java:

Desktop.getDesktop.open(new File("file.html")) ?

I see no exit without ant optional tasks. From all the scripts beanshell looks most lightweight and does not require any new knowledge. So I did it this way:

<property name="bshJar" value="
  C:\lang\java\bsh-1.3.0.jar:
  C:\lang\java\bsf.jar:
  C:\lang\java\commons-logging-1.1.1.jar" />
<script manager="bsf" language="beanshell" classpath="${bshJar}">
  java.awt.Desktop.getDesktop().open(
    new java.io.File("c:\\temp\\1\\stackoverflow\\DVD FAQ.htm"));
</script>

And this is an answer about getting script task running. However javascript language is indeed a better option, as it needs no classpath (and no manager) in JDK 6. And the code inside remains the same.

like image 21
Jarekczek Avatar answered Sep 30 '22 12:09

Jarekczek