template xxx.ftl not found in maven - eclipse

I am using Eclipse LUNA and create a java project to send SMS to the mobile with some text. It is working fine, now I convert the java project into Maven based project by using configure to maven project it is converted and POM.XML is also added. But when I am trying to run the project it gives error.
Error is:
SMS Sending Failed
Template "xxx.ftl" not found `
can you please help to me i tried a lot but it can't solve it.

Maven references to templates like '.ftl' separately as resources. So you need to add the path to resources in POM.xml
You can point the path to root of your java if you have your templates distributed in many packages and don't change the paths given in your project.
<project>
...
<build>
...
<resources>
<resource>
<directory>src/main/java</directory>
</resource>
</resources>
...
</build>
...
</project>
Or you can point it to the templates folder you have, as mentioned by,
<project>
...
<build>
...
<resources>
<resource>
<directory>[your folder here]</directory>
</resource>
</resources>
...
</build>
...
</project>
Note: You will have to refer to the templates w.r.t. to the path you mention in the resource directory.
Eg. If your templates directory is com/foo/bar/templates and you set the resource directory to be src/main/java/com/foo, you will have to refer to your ftl as /bar/templates/example.ftl

Related

Running Scala code in Eclipse with Maven enabled

I am trying to run some trivial Scala code in Eclipse but I am not able to get it working when Maven is enabled.
I start by creating a Scala project in Eclipse and then I add an object with the following code:
object HelloSpark extends App
{
println("Hello, world!")
}
I then use "Run As>>Scala Application" to successfully execute the above code:
Hello, world!
I then enable Maven by clicking on "Configure>>Convert to Maven Project". While the ensuing build is successful, the "Run As>>Scala Application" option no longer comes up. Using the previously created launch configuration results in the following error:
Error: Could not find or load main class HelloSpark
Trying the answer for Eclipse, Scala & Maven - Class files are not generating did not help in my case.
Could someone please tell me what I am doing wrong? I don't understand why enabling Maven changes the way Scala code is run.
Thanks.
Edit: Here is the pom.xml that was automatically generated when I converted the above to a Maven project:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>HelloSpark</groupId>
<artifactId>HelloSpark</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
Usually when you have a maven project, the project is build with maven. Therefore you need a pom.xml file where you define how to build the project and so on. Are you aware of this, did you configure a pom.xml? Without the correct pom file you cannot build and run the app.
So without a correct maven build, you will not have a class file. Therefore you are getting this error: Error: Could not find or load main class HelloSpark
So it turns out simply converting the Eclipse project to a Maven project is not enough. Maven has to know it's a Scala project and build it accordingly.
I followed the instructions at http://docs.scala-lang.org/tutorials/scala-with-maven.html and now I have a working project with running code. It's important to generate a Maven archetype first and then convert it to an Eclipse project before importing it into Eclipse.

Eclipse deploying unfiltered .WAR-Archive on Tomcat

i have the following problem: I want to use maven profiles and the maven-war-plugin for filtering my webapplication, so that it's just one click to deploy it either on the live- or on the development server.
When i build the .WAR-archive via Eclipse (Maven-Plugin) and then manually deploy it on the tomcat-server via the tomcat-manager-interface, my application works as expected. (all variables are replaced correctly inside the generated .WAR-archive)
But when i want to run the application using Eclipse's "Run on Server", an exception occurs:
[..] nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.security.web.authentication.logout.LogoutFilter]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: ${security.casEntryPoint.logoutSuccessUrl} isn't a valid redirect URL
This is the configuration of the maven profiles in my pom.xml:
<profiles>
<profile>
<id>prod</id>
<build>
<filters>
<filter>src/main/filters/dfnaaiAgreement-prod.properties</filter>
</filters>
</build>
</profile>
<profile>
<id>devLocal</id>
<build>
<filters>
<filter>src/main/filters/dfnaaiAgreement-devLocal.properties</filter>
</filters>
</build>
</profile>
This is an example entry for the *.properties file:
security.casEntryPoint.logoutSuccessUrl = https://example_entry/please_logmeout
This is one entry in the settings.xml that should be replaced by the value in the *.properties file:
<security:logout logout-url="/logout" logout-success-url="${security.casEntryPoint.logoutSuccessUrl}" />
and this is the configuration for the maven plugin (in the pom.xml), that is used for filtering the configuration files:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<warName>dfnaaiAgreement</warName>
<webResources>
<resource>
<directory>${basedir}/src/main/webapp</directory>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
</webResources>
</configuration>
This is my maven build configuration:
Maven-Build configuration (Sorry, not enough reputation to post images directly)
It seems like eclipse's "run on server" deploys the unfiltered application on the tomcat-server.
What am i doing wrong?
Update:
I followed this Link Run Maven webapp on server from Eclipse with properties injection from profile, but i'am still receiving the same Exception.
Here's the adjustment of my project's configuration: Active Maven Profiles
Update: Eclipse (Luna) deploys the webapplication to workspace/.metadata/.plugins/.org.eclipse.wst.server.core/tmp0/wtpwebapps/applicationName. The settings.xml that's deployed there still contains the unfiltered variables, whereas the generated .WAR-Archive (that is located at workspace/applicationName/target) has the correctly filtered settings.xml. How is this possible?
Thanks for your help!
Although it's not an optimal solution i found a workaround to fix my problem. Therefor i adjusted the project's deployment assembly settings in the way that the WEB-INF-Folder of the target-Folder will be taken for deployment.
You can do this by rightclicking your project and choose "Properties". Here's a screenshot of how i adjusted the settings:
Web_Deployment_Assembly.PNG

Maven Dependencies Location

I'm using Eclipse Luna and having trouble with a imported third party Maven project. In Maven Dependencies the project has several jars, but the project is insisting they are to be found in C:\Users\username.m2\repository when they're not.
How do I tell it they are not there but in E:\java\jars?
I tried changing Native Library Locations but that didn't work, and there is nothing in the pom file that says which folder location to use. All attempts to get the classpath to work have failed (probably due to my newness to this environment).
You can include your resource in your pom.xml as follows:
<project>
<build>
<resources>
<resource>
<directory>[your folder here]</directory>
</resource>
</resources>
</build>
</project>
Alternatively, you can add your 3rd Party JARs as a repository, like so:
<repositories>
<repository>
<id>lib_id</id>
<url>file://your_path_to_lib/lib</url>
</repository>
</repositories>
Resources:
Specifying resource directories.
Guides to installing 3rd Party JARs.
Introduction to Repository.
Related SO Question.

Is it necessary that properties file should be in resources folder in maven project?

In maven project is it necessary that all the properties file,xml files needs to be in resources folder.Means if I want my properties file is in src/main/java/com/search/search.properties
then I need to put it in resources/com/search/search.properties.Is it necessary?
Because right now they are in java folder ,when I run maven project in hosted mode it runs properly. But when I create war it does not include that properties file in war/web-inf/classes/com/search/search.properties.
When I put it in resources/com/search/search.properties then and then only it include it in war folder.
According to the Maven standard directory layout you have to put Application/Library related resources into src/main/resources, if you do not do this, when maven want to package your application (War, Jar or ...) only copy resource in src/main/resources into your package.
It really depends on how you manage things. By default maven takes care if you use src/main/resources.
Also just verify that you have correct include/exclude tags in your resource tag under build.
<build>
<outputDirectory>${project.build.directory}/${project.artifactId}/WEB-INF/classes</outputDirectory>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources/</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<build>

Deploying a War File to Tomcat Root With Maven pom.xml

Assuming the following pom.xml maven would build a client.war file which when deployed to Tomcat will have the URL www.server.com:8080/client/
What would one have to change so the application can be reached at the server root www.server.com:8080/?
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>...</groupId>
<artifactId>client</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>...</name>
<url>http://maven.apache.org</url>
<build>
<resources>
<resource>
<directory>target/generated-resources</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
...
</plugins>
<finalName>client</finalName>
</build>
...
</project>
I believe you can leave the war named client.war if you'd like. Then configure the tomcat6 plugin, setting the path like this:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.0-beta-1</version>
<!-- put the configuration in an execution if you want to... -->
<configuration>
<path>/</path>
<warFile>${project.build.directory}/client.war</warFile>
<!-- other config options here -->
</configuration>
</plugin>
I haven't used tomcat7 version of the plugin, but I'm guessing it's similar.
Since you're using the combination of eclipse, tomcat, and maven, I'm going to make the guess that the m2e-wtp plugin is in use here. There's a FAQ that addresses this. This also shows though how to change your context root in a maven specific way (using the war plugin for specifying a finalName for the war) which results in a correctly named war file (such as ROOT.war as mentioned in other answers.
Maven war plugin (which is defined on super-pom by default) will only generate a war file. It's up to you to set up your app on Tomcat. If you want to add the "deploy to a container" to your maven build, go with Tomcat Maven Plugin or Cargo Maven Plugin.
What you want has nothing to do with Maven, actually. Setting your war name to ROOT.war should do it (<finalName>ROOT</finalName> on your build section), but if you want to add your context.xml to the war file, you could do something like (assuming src/main/webapp is your webapp folder defined by maven):
`<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<webResource>
<directory>${basedir}/src/main/webapp/META-INF</directory>
<includes>
<include>context.xml</include>
</includes>
<targetPath>META-INF</targetPath>
<filtering>true</filtering>
</webResource>
</webResources>
</configuration>
</plugin>
`