0

We have several Liferay 6.2 portlets in different Maven projects. Some of these are imported as dependencies by others. While this allows me to access the java classes, I can't figure out how to import Freemarker files from one project in another project.

I assume I would need to access the resources from the dependency project, and then tell Freemarker how to find and include them. Assuming that's true, that leaves me with two questions:

  1. How can I access resources, like FTL files and images, from another project that is list as a dependency in the Maven pom file of my Liferay project, especially in the server-side code?

  2. How can I tell Freemarker where to look for the FTL files in the project that is listed as a dependency in the Mavan pom file?

If I'm wrong about what I need to be doing, then what is the correct way to give Freemarker access to the FTL files?

EDIT: I have a way around the first problem (though it's not a great way, I feel there's probably a better solution). I've tried to set up a Freemarker configuration using the path of the external FTL files, but I don't really know what to DO with the configuration; it doesn't look like it's actually being used.

SolS
  • 11
  • 4

1 Answers1

0

I eventually found this question:

Maven: Extract dependency resources before test

Using the maven-dependency-plugin code in the original question and in the answer, I was able to copy the FTL files from the dependency into the Freemarker folder of the child project (in the compiled target folders of course), allowing them to be imported by Freemarker without any other changes made to the child project (the FTL files had to be moved to the resources directory in the parent project). Here are the relevant sections of the child project pom file:

I included the parent project in the dependencies:

<dependency>
    <groupId>ourGroupId</groupId>
    <artifactId>parentArtifactId</artifactId>
    <version>1.0.0</version>
</dependency>

And then added the maven-dependency-plugin in the plugins section of the build, using the same artifact id I used in the dependency section:

<plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>3.3.0</version>
    <executions>
        <execution>
            <id>resource-dependencies</id>
            <phase>process-resources</phase>
            <goals>
                <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
                <includeArtifactIds>parentArtifactId</includeArtifactIds>
                <includes>freemarker/*/*.ftl</includes>
                <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

I chose the phase and goals that seemed to make sense, I'm not sure if they're "optimal" but they seem to work. The FTL files are inside a sub-folder, under the "freemarker" folder, in the resources directory of the parent file. The "includes" parameter is a bit more restrictive that I thought, it seems I need to have the correct folder depth specified in order to import the files correctly, but that's fine.

Just for clarity, I made sure the resulting location of the copied Freemarker files matched the Freemarker that folder had already been specified in the applicationContext.xml file:

<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    <property name="templateLoaderPath" value="/WEB-INF/freemarker/" />
</bean>
SolS
  • 11
  • 4