How do I install and use Apache Velocity? - apache2

I have installed Apache server 2.4, and Ant 1.8.3, I have downloaded Velocity 1.7, and Velocity tools 2.0. I have read the installation documentation for Apache Velocity about ten times, and Googled it for two days, I still have no idea what to do with these files. Can anyone provide a detailed description on how to install Velocity please?
I was hoping to develop using Eclipse, so I have also installed this.
I would appreciate any assistance as I am stuck.
Thank you.
Update:
I have configured Eclipse to use Tomcat and have worked my way through a tutorial and managed to get this all working, but I do not know how exactly to start a velocity project in Eclipse, if anyone has used Eclipse to build a Velocity project, I would appreciate some advice on how to set that up.
Thanks.

You will also need a Java EE container (aka servlet container) like Apache Tomcat. The Apache HTTP server doesn't know anything about Java. Please note that Tomcat can itself be used directly as an HTTP server - you would typically choose to keep Apache HTTP server in front of Tomcat on production servers to speed up static files requests among other reasons (Apache HTTP can forward requests to Tomcat with the mod_proxy_ajp module). But for the beginning, it's easier to directly use the HTTP service provided by Tomcat.
Then, you need to get familiar with the concept of a Web Application. It's nothing more than a specific hierarchy of files (that can be compressed into a jar file with the .war extension). For a web application using Velocity, that would typically be:
./ ← root of your web application
./index.vhtml ← your welcome page template
./foo/bar.vhtml ← any other file or subdirectory containing your web resources
./WEB-INF/ ← the WEB-INF directory contains all web application configuration
./WEB-INF/web.xml ← maps HTTP requests towards filters and servlets
./WEB-INF/tools.xml ← optional configuration file for your Velocity custom tools
./WEB-INF/velocity.properties ← optional file to tune Velocity configuration
./WEB-INF/lib/ ← contains all the libraries needed by your web application
./WEB-INF/src/ ← contains your custom Java classes source code
./WEB-INF/classes/ ← contains your custom Java classes
Your web.xml file has to map adequate requests towards the VelocityViewServlet. It will look like this:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>view</servlet-name>
<servlet-class>org.apache.velocity.tools.view.VelocityViewServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>view</servlet-name>
<url-pattern>*.vhtml</url-pattern>
</servlet-mapping>
</web-app>
I cannot help you much with Eclipse as I don't use it, but there seems to be several tutorials online if you search for tomcat + eclipse. Here's one that looks interesting: http://www.coreservlets.com/Apache-Tomcat-Tutorial/tomcat-7-with-eclipse.html

Related

Apache CXF installation options into Tomcat

I want to be able to use Apache CXF with Tomcat. I have copied CXF's jar files into WEB-INF/lib and then I am able deploy my WAR file into Tomcat. That WAR file works fine in Tomcat, but that WAR file is then not usable in IBM WebSphere Liberty JEE server. I want to build my WAR files, such that they are write ones run any were.
The CXF app server configuration guide has no mention about Tomcat; the Metro project suggest that it's own jar file be copied into Tomcat's endorsed folder. Can the same be done for CXF? What is the best practice?
Best practice for a Tomcat deployment is to package the CXF jar files in the WAR file. It should also work as part of Tomcat's lib folder but I don't know many deployments using that.
Maybe you should take a look at Apache Tomee to have a combination with Tomcat and CXF?

Migration from tomcat to wildfly

I am migrating my web application from tomcat to wildfly. I was able to deploy the app using a temporary workaround of placing the configurations inside the WEB-INF/web.xml (). But I wanted it outside my war file. Is there any equivalent for catalina/conf/localhost/myapplicationconfig.xml in wildfly. Any suggestions please. I tried naming subsytem configuration and also placing it in modules but it didn't work for me

How is my GAE app able to run without app.yaml?

Although I started development for Google App Engine using Endpoints a while ago, I hadn't noticed this - Google's ref. page for Project structure says this:
Your development file hierarchy should look like this:
MyDir/
[pom.xml]
[build.gradle]
[index.yaml]
[cron.yaml]
[dispatch.yaml]
src/main/
appengine/
app.yaml
docker/
[Dockerfile]
java/
com.example.mycode/
MyCode.java
webapp/
[index.html]
[jsp.jsp]
WEB-INF/
[web.xml]
You'll need to define an app.yaml file that looks like this:
...
Note that the app.yaml is deemed compulsory as per the docs. In my case, I spawned a backend module(through the Wizard) in Android Studio that builds on Gradle. I have been able to build and deploy this module on GAE successfully but now I needed to switch from automatic scaling to basic/manual scaling, I found this to be done through app.yaml file.
Here is the thing: I don't have an app.yaml in place and it works fine. Where is then the config info. that GAE requires to deploy the App.
Specifically,
app.yaml specifies the environment - Java. But, I found the java plugin in build.gradle for that. Aren't 2 config places for the same thing confusing?
Is it possible to ditch app.yaml entirely for equivalent config. in build.gradle?
Why is Google claiming app.yaml to be compulsory when I am able to do without it?
The App Engine Java runtime uses its own configuration schema in XML, while others are YAML.
To set the scaling elements, follow the official reference.

Mapping project-name and application-id in GAE

I am trying to deploy my project on the appengine. I use maven to build it. Name of my project (say, project-name)and the application-id on the appengine are different. Is there a way to map the application-id with my project? Every time I say,
mvn appengine:update
I get an error message like
This application does not exist (app_id='project-name').
Since I have not said which application-id to map it with, it attempts to find an application-id same as y project name. How should I fix this?
The appengine-application.xml and appengine-web.xml files contain general information used by App Engine tools when your app is deployed. Put your application ID (the ID you registered when you created your application in the Google Developers Console) into <application> element.
appengine-application.xml
<appengine-application xmlns="http://appengine.google.com/ns/1.0">
<application>your-application-id</application>
</appengine-application>
appengine-web.xml
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>your-application-id</application>
<module>default</module>
<version>v1</version>
...
</appengine-web-app>
All the App Engine Configuration information is store in the appengine-web.xml You must need to update them as per your google app engine project information.
For example my
project id : prabhatabc-2012
& i want to run my application on the version : v2
so i need to update my appengine-web.xml file project id(prabhatabc-2012) in <application></application> and version in <version>v2</version>
<application>prabhatabc-2012</application>
<version>v2</version>

Google App Engine Eclipse plugin without using GWT

I want to host a Java/AngularJS app on Google App Engine, and leverage the Eclipse plugin. I figure the most straightforward way to do this is:
From within Eclipse, start a new Google Web Project.
Go to project properties and uncheck GWT and DataNucleus.
Delete the generated java classes and GWT related stuff so you have an appengine.web.xml, web.xml, WEB-INF/lib, log4j properties, and a few other files left.
Put index.html under the war folder, sister to favicon.ico.
Change web.xml welcome file to index.html
Deploy and test that index.html is visible.
Deployment via Eclipse works fine, but myapp.appspot.com/ and myapp.appspot.com/index.html both return 404.
Simply put my use case is "how do I deploy an index.html to GAE (using Eclipse plugin) without the 800 pound guerilla that is GWT?"
I was unable to find good documentation on this.
Unchecking 'Use Google Web Toolkit' should be all you need to do to create a basic App Engine application without GWT, however, it will not create a sample index.html file. For that, you need to keep 'Generate project sample code' checked. This will create some extra Java files for you that you'll need to delete, but it's the closest you can get to what you described in your question.

Resources