You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by hdockter <st...@dockter.de> on 2007/02/13 09:58:52 UTC

Re: [m2] Getting SNAPSHOT information into a webapp

Hi Mark, 

I'm having the same requirement. I'm wondering if you have found a solution
on how to access the snapshot timestamp value.

Thanks,

- Hans 


Mark Chaimungkalanont wrote:
> 
> Guys,
> 
> We're using Maven2 and wanted to know the best way to get version
> information (including 
> the SNAPSHOT timestamp, e.g. 1-0-SNAPSHOT-20050622 or sth) into a webapp
> that was built 
> with the "mvn package"?
> 
> My guess is that there is a property ${maven.snapshot.version} or
> something that we can 
> use to generate a properties file so that the app can read this
> information. Perhaps a 
> filter copy plugin against one of the goals?
> 
> Does anything know any references around this area? Have anyone got
> examples they can share?
> 
> Thanks,
> 
> Mark C
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-m2--Getting-SNAPSHOT-information-into-a-webapp-tf1666684s177.html#a8940653
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [m2] Getting SNAPSHOT information into a webapp

Posted by Steve Shucker <ss...@vmsinfo.com>.
Here's the source for my homebrew plugin to add a version file to my 
artifacts.  It's just writing a date and hostname, but you can easily 
change it to include other information such as version.

package com.vms.maven;

import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;


/**
 * Goal which creates/updates a version file
 *
 * @goal versionPage
 * @phase generate-resources
 */
public class VersionMojo extends AbstractMojo {
   
    /**
     * @parameter default-value="version.html"
     */
    private String filename;

    /**
     * @parameter default-value="MM/dd/yyyy HH:mm:ss"
     */
    private String dateFormat;

    /**
     * @parameter expression="${project}"
     * @required @readonly
     */
    protected MavenProject project;
       
    public void execute() throws MojoExecutionException {
        String outputDirectory;
        if ("jar".equals(project.getPackaging())) {
            outputDirectory = project.getBuild().getDirectory() + 
"/classes";
        } else {
            outputDirectory = project.getBuild().getDirectory() + "/" + 
project.getBuild().getFinalName();
        }
        File directory = new File(outputDirectory);
        if (!directory.exists()) {
            directory.mkdirs();
        }
        String fullFilename = outputDirectory + "/" + filename;
        File versionFile = new File(fullFilename);
        if (versionFile.exists()) {
            versionFile.delete();
        }
        SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
        try {
            String versionString = "built " + formatter.format(new 
Date()) + " on " + InetAddress.getLocalHost().getHostName();
            FileOutputStream output = new FileOutputStream(fullFilename);
            new PrintStream(output).println(versionString);
            output.close();
            getLog().info("Wrote version \"" + versionString + "\" to 
file " + fullFilename);
        } catch (Exception e) {
            throw new MojoExecutionException("FAILURE", e);
        }
    }
}

-Steve

hdockter wrote:
> Hi Mark, 
>
> I'm having the same requirement. I'm wondering if you have found a solution
> on how to access the snapshot timestamp value.
>
> Thanks,
>
> - Hans 
>
>
> Mark Chaimungkalanont wrote:
>   
>> Guys,
>>
>> We're using Maven2 and wanted to know the best way to get version
>> information (including 
>> the SNAPSHOT timestamp, e.g. 1-0-SNAPSHOT-20050622 or sth) into a webapp
>> that was built 
>> with the "mvn package"?
>>
>> My guess is that there is a property ${maven.snapshot.version} or
>> something that we can 
>> use to generate a properties file so that the app can read this
>> information. Perhaps a 
>> filter copy plugin against one of the goals?
>>
>> Does anything know any references around this area? Have anyone got
>> examples they can share?
>>
>> Thanks,
>>
>> Mark C
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>>
>>     
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org