Showing posts with label apache-ant. Show all posts
Showing posts with label apache-ant. Show all posts

Friday, 24 February 2012

Installing ANT on AWS EC2: Unable to locate tools.jar

When I try and use ANT, I get this message:
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/lib/tools.jar
Most forum posts say to just install Sun Java. Loads of other ones said to check your JAVA_HOME variable and to ensure you had installed the JDK, and not just the JRE. Ultimately, the solution to this problem for me was installing the devel version of the JDK:
sudo yum install java-1.6.0-openjdk-devel

Get Eclipse to automatically compile your Sass

Using the Aptana plugin for Eclipse, I was able to get syntax highlighting working in Sass files (*.sass and now *.scss). It also allows you to compile a Sass file at the click of a button, which is great, but what we all really want is automatic compilation every time we make save a change.

Automatic compilation can be done using the sass --watch command, but this requires you to set it up every time you start working on a project. In Eclipse, I couldn't find an existing way to automate the compile process, so I wrote an ant build script to do it, and then set that as a Project Builder and set it to run on "Auto Build", meaning every time a change is saved.

1) The ant build script. Put this in a file called build.xml in the root of your project. It just says to run sass (/var/lib/gems/1.9.1/bin/sass) on the directory "scss" and output the result to the directory "css". Don't forget to update the path to your sass executable, as well as your css and scss directories.


    
        
            <srcfile/>
            <targetfile/>
            <fileset dir="scss" includes="*.scss"/>
            <mapper from="*.scss" to="*.css" type="glob"/>
        
    

Update: bare in mind you can add an <arg> element inside the element in order to send any additional arguments to Sass e.g. <arg value="--style=compressed"/> will output compressed CSS (useful for your production server).

2) Add it as a Project Builder: in the project properties, click Builders, then New, and select Ant Builder. Give it a name, and select the Buildfile (click Browse Workspace and navigate to your build.xml). Under Targets, click the Set Targets button next to Auto Build, and select sass and click OK. Finally, under Build Options, check "Specify working set of relevant resources" and click the button to specify only your scss directory - this ensures the build script will only be run when you change your Sass files.

Monday, 4 October 2010

Apache Ant error: restrict doesn't support the nested "name" element

System: Ant 1.7.1 and Sun Java 1.6 on Ubuntu Lucid 10.04

Code snippet:
<target name="jar">
<jar basedir="${bin}" destfile="${project.name}.jar">
<restrict>
<name name="**/*" />
<archives>
<zips>
<fileset dir="/opt/project_jars">
<include name="file.jar" /> 
</fileset> 
</zips> 
</archives> 
</restrict> 
</jar> 
</target>

From googling the error, I found this thread: http://markmail.org/message/y2ly5gykzbpab7p7. The suggested solution of adding namespace information got rid of the original error, but introduced a new one:
restrict doesn't support the nested "archives" element

Actual solution: upgrade Ant to 1.8
sudo apt-get install ant1.8