Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Haikal Saadh http://tunaranch.net

« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS 

Fixing wagon failure when deploying to dav.

Stick this in your pom if wagon fails when deploying to DAV.

(Maven 2.0.9)

   1  
   2  <project>
   3    <build>
   4      <extensions>
   5        <extension>
   6          <groupId>org.apache.maven.wagon</groupId>
   7          <artifactId>wagon-webdav</artifactId>
   8          <version>1.0-beta-2</version>
   9        </extension>
  10      </extensions>
  11    </build>
  12  </project>

Sample Ant script for building a webapp.

// Sample ant script to build a webapp.

   1  
   2  <project name="Combine Enrolments" default="dist" basedir=".">
   3  <!-- Note that you'll need ant 1.7 for this build, as 1.6.5 doesn't have comprehensive filelist support -->
   4  	
   5  	<!-- Pull in properties -->
   6  	<property file="build.properties" />
   7  	
   8  	<!-- DEFINITIONS -->
   9  	<!-- Run time jars. These ones will get distributed alongside this app -->
  10  	<filelist id="dist_jars" dir="${lib.dir}"> 
  11  		<file name="${commons-cli.jar}" />
  12  		<file name="${log4j.jar}" />
  13  	</filelist>
  14  
  15  	<!-- Build time jars -->
  16  	<filelist id="misc_jars">
  17  		<file name="${servlet-api.jar}" />
  18  	</filelist> 
  19  
  20  	<path id="classpath">
  21          <pathelement location="${build.classes.dir}"/>
  22   		<filelist refid="dist_jars" />
  23  		<filelist refid="misc_jars" /> 
  24  	 </path>
  25  	
  26  	<!-- TARGETS -->
  27  	<target name="javadoc" depends="init" description="Generate javadoc">
  28  		<echo>Generating javadoc</echo>
  29  		<javadoc packagenames="au.edu.qut.*"
  30  				sourcepath="${src.dir}"
  31  				destdir="${doc.dir}" >
  32  			<classpath refid="classpath"/>
  33  		</javadoc>
  34  	</target>
  35  	
  36  	<target name="dist" depends="build,copy_libs" description="Generate an executable jar, ready for distribution">
  37  		<copy file="log4j.properties" todir="${build.classes.dir}"  />
  38  
  39  		<pathconvert property="jar.classpath" pathsep=" ">
  40  		    <mapper>
  41  		      <chainedmapper>
  42  			    <!-- remove absolute path -->
  43  		        <flattenmapper />
  44  
  45  		        <!-- add lib/ prefix -->
  46  		        <globmapper from="*" to="lib/*" />
  47  		      </chainedmapper>
  48  		    </mapper>
  49  
  50  	    	<path>
  51  		  	<!-- lib.home contains all jar files, in several subdirectories -->
  52  	    		<filelist refid="dist_jars" />
  53  			</path>
  54  		</pathconvert>
  55  		
  56  		<jar basedir="${build.classes.dir}" destfile="${dist.dir}/${jar.name}">
  57  			<manifest>
  58  				<attribute name="Main-Class" value="${jar.main.class}"/>
  59  			</manifest>
  60  		</jar>
  61  	</target>
  62  
  63  	<target name="build" depends="init,copy_libs" description="Compile the thing already">
  64  		<echo>Building ${ant.project.name}</echo>
  65  		<javac srcdir="${src.dir}" destdir="${build.classes.dir}" debug="${build.debug}" >
  66  			<classpath refid="classpath"/>
  67  		</javac>
  68  	</target>
  69  	
  70  	<target name="copy_libs" depends="init" description="Copy runtime  dependencies to the dist directory">
  71  		<echo>Copying Dependencies</echo>
  72  		<copy todir="${dist.lib.dir}" >
  73  			<filelist refid="dist_jars" />
  74  			<mapper type="flatten" />
  75  		</copy>
  76  		<copy todir="${build.lib.dir}" >
  77  			<filelist refid="dist_jars" />
  78  			<mapper type="flatten" />
  79  		</copy>
  80  	</target>
  81  	
  82  	<target name="clean" depends="init"  description="Clean up build structure">
  83  		<echo>Cleaning...</echo>
  84  		<delete dir="${build.dir}" includeEmptyDirs="true"/>
  85  		<delete dir="${dist.dir}" includeEmptyDirs="true" />
  86  		<delete dir="${doc.dir}" includeEmptyDirs="true" />
  87  	</target>
  88  	
  89  	<target name="init" description="Initialise build process">
  90  		<tstamp/>
  91  		<echo> Building ${ant.project.name} with Ant Version ${ant.version}</echo>
  92  		<mkdir dir="${build.classes.dir}" />
  93  		<mkdir dir="${build.lib.dir}"/>
  94  		<mkdir dir="${doc.dir}"/>
  95  		<mkdir dir="${dist.dir}" />
  96  		<mkdir dir="${dist.lib.dir}" />
  97  	</target>
  98  </project>

Parsing simple command line arguments in java, using the the Commons CLI library.

// Skeleton to read in two command line arguments, one mandatory, one optional

   1  
   2  package snippets;
   3  
   4  import org.apache.commons.cli.*;
   5  
   6  /* 
   7   * Stub program that reads command line arguments
   8   */
   9  public class CommandLineProgram {
  10  
  11  	private static Options options = null; // Command line options
  12  	
  13  	private static final String PROPERTIES_LOCATION_OPTION = "f";
  14  	private static final String OUTPUT_FILE_OPTION = "o";
  15  	private static final String DEFAULT_OUTPUT_FILE = "out.feed";
  16  	
  17  	private CommandLine cmd = null; // Command Line arguments
  18  	
  19  	private String outputFile = DEFAULT_OUTPUT_FILE;
  20  	
  21  	static{
  22  		options = new Options();
  23  		options.addOption(PROPERTIES_LOCATION_OPTION, true, 
  24  				"Data file location");
  25  		options.addOption(OUTPUT_FILE_OPTION, false, "Output file. " + DEFAULT_OUTPUT_FILE + " by default ");
  26  		
  27  	}
  28  	
  29  	/**
  30  	 * @param args
  31  	 */
  32  	public static void main(String[] args) {
  33  		
  34  		CommandLineProgram cliProg = new CommandLineProgram();
  35  		cliProg.loadArgs(args);
  36  	}
  37  	
  38  	/**
  39  	 * Validate and set command line arguments.
  40  	 * Exit after printing usage if anything is astray
  41  	 * @param args String[] args as featured in public static void main()
  42  	 */
  43  	private void loadArgs(String[] args){
  44  		CommandLineParser parser = new PosixParser();
  45  		try {
  46  			cmd = parser.parse(options, args);
  47  		} catch (ParseException e) {
  48  			System.err.println("Error parsing arguments");
  49  			e.printStackTrace();
  50  			System.exit(1);
  51  		}
  52  		
  53  		// Check for mandatory args
  54  		
  55  		if (! cmd.hasOption(PROPERTIES_LOCATION_OPTION)){
  56  			HelpFormatter formatter = new HelpFormatter();
  57  			formatter.printHelp("java -jar this_jar.jar", options);
  58  			System.exit(1);
  59  		}
  60  		
  61  		// Look for optional args.
  62  		
  63  		if (cmd.hasOption(OUTPUT_FILE_OPTION)){
  64  			outputFile = cmd.getOptionValue(OUTPUT_FILE_OPTION);
  65  			
  66  		}
  67  	}
  68  }
  69  

Actionscript Component getter/setter

// Inspectable getter and setter

   1  
   2  	[Inspectable(type=Number, defaultValue="10")]
   3  	public function set points(p:Number){
   4  		__points = p;
   5  	}
   6  	
   7  	public function get points():Number{
   8  		return __points;
   9  	}

Coding a tween

//Tween an object's _y property. This is within the context of a v2 Component, but the same principles also apply elsewhere. Just replace 'this' with the movie clip you want to tween.

   1  
   2  import mx.transitions.Tween;
   3  import mx.transitions.easing.*;
   4  
   5  
   6  var tween = new Tween(this, "_y", Elastic.easeOut, y, yToMoveTo, 1, true);
   7  tween.onMotionFinished = mx.utils.Delegate.create(this, motionFinished);
« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS