You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Chris Graham <ch...@warpspeed.com.au> on 2009/09/12 12:08:07 UTC

File Reosurce Template problems and Absolute paths

Hi All.

I am attempting to write a Maven plugin that is executed as part of a build
against other projects.

I am attempting to use Velocity to execute templates that are contained in
the *other* project, not the one that I am writing that contains the
Velocity code.


	<build>
		<plugins>
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>properties-maven-plugin</artifactId>
				<version>1.0-alpha-3-SNAPSHOT</version>
				<executions>
					<execution>
						<phase>generate-resources</phase>
						<goals>
							<goal>update-properties</goal>
						</goals>
						<configuration>
							<files>
								<file>src/main/resources/application.properties</file>
							</files>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

So my plugin receives a list of File objects, of the files in the other
project. These files are the template files that need to be processed.

I am using the FileResourceLoader, but I can not get it to correctly process
the templates. Well, not without some awful fudges. 

Can anyone suggest a reasonable way to process resources that are not local
to the plugin in question? 

Or at least suggest a way to work with absolute paths? (that obviously need
to work on Windows and Unix).

Ta.

-Chris

-- 
View this message in context: http://www.nabble.com/File-Reosurce-Template-problems-and-Absolute-paths-tp25413134p25413134.html
Sent from the Velocity - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


Re: File Reosurce Template problems and Absolute paths

Posted by Chris Graham <ch...@warpspeed.com.au>.
It would appear that setting the property "file.resource.loader.path" to an
empty string did the trick, namely:

props.setProperty("file.resource.loader.path", "");

Interestingly, simply NOT setting the value to start with, did not work.

So, now I can do this:

Velocity.mergeTemplate(file.getCanonicalPath(), "UTF-8", context, writer);

Where "file" is a java.io.File object that is passed in from Maven.

-Chris


Chris Graham wrote:
> 
> Hi All.
> 
> I am attempting to write a Maven plugin that is executed as part of a
> build against other projects.
> 
> I am attempting to use Velocity to execute templates that are contained in
> the *other* project, not the one that I am writing that contains the
> Velocity code.
> 
> 
> 	<build>
> 		<plugins>
> 			<plugin>
> 				<groupId>org.codehaus.mojo</groupId>
> 				<artifactId>properties-maven-plugin</artifactId>
> 				<version>1.0-alpha-3-SNAPSHOT</version>
> 				<executions>
> 					<execution>
> 						<phase>generate-resources</phase>
> 						<goals>
> 							<goal>update-properties</goal>
> 						</goals>
> 						<configuration>
> 							<files>
> 								<file>src/main/resources/application.properties</file>
> 							</files>
> 						</configuration>
> 					</execution>
> 				</executions>
> 			</plugin>
> 		</plugins>
> 	</build>
> 
> So my plugin receives a list of File objects, of the files in the other
> project. These files are the template files that need to be processed.
> 
> I am using the FileResourceLoader, but I can not get it to correctly
> process the templates. Well, not without some awful fudges. 
> 
> Can anyone suggest a reasonable way to process resources that are not
> local to the plugin in question? 
> 
> Or at least suggest a way to work with absolute paths? (that obviously
> need to work on Windows and Unix).
> 
> Ta.
> 
> -Chris
> 
> 

-- 
View this message in context: http://www.nabble.com/File-Reosurce-Template-problems-and-Absolute-paths-tp25413134p25413864.html
Sent from the Velocity - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org