Basics of packaging Jruby on Rails for Tomcat - ruby-on-rails-3

I have a sample rails app that works just fine when run normally. However, I cannot seem to get it packaged as a war that will deploy into Tomcat 7. Warbler seems to be not generating the web.xml file. What is the best way to package a simple war file that will run in Tomcat?

The book deploying Rails with Jruby has a good run down of this.
The basics are:
warble config
(generates the warble.rb file)
Adjust that file to suit your needs then:
warble executable war or just plain warble might work.
warble -T lists all the tasks that warble can do.
Inside the warble.rb file you can add options that show up on your web.xml file when the war is created.
For example this line:
config.webxml.jruby.max.runtimes = 4
puts the config option in the webxml.

Related

Location of config files when deploying Symfony

I'm trying to deploy a Symfony 3 application on Kimsufi of OVH.
Everything works on my local machine, but when I deploy I get the error (debug mode is on) :
The file "/home/remiblaiyb/app/app/config/routing.yml" does not exist.
Symfony seems to search on app/app for config, I have no idea why.
Do you have any suggestion? Thank you very much.
EDIT: I finally found the answer. It's due to the new way of getting the project directory in Symfony: Symfony looks after the composer.json file, which I didn't upload in prod!
So do not forget to include your composer.json into your project.
Thanks!

Tomcat customization while starting server

I am manually copying a war file to the web-apps folder of Tomcat and starting Tomcat using cmd ./catalina.sh start. I want to customize it in such a way that I can use a war name to start e.g ./catalina.sh start quickenweb (where 'quickenweb' is a war file name).
Please suggest how to achieve this.
If you have access to Windows and WinZip or the 7-Zip File Manager, you can open the war file with Zip Program. Or, if you have LINUX, PeaZip/File Roller would work too.
In the zip program, you can navigate to the folder - like log4j.properties for example and edit it. When closing TextPad/LeafPad for example, the Zip program should prompt you to update the war file. It is advisable to edit/update the war file outside of the tomcat folder structure and then delete the war under tomcat and then update.. Actually, probe is a great tool for managing/updating/compiling war files.
Hope this helps?

Pass runtime arguments to grails project on tomcat server

I'm trying to pass in a variable at runtime to my application to configure where my external config files are stored.
I need external config files so that the config can be changed without having to deploy a new release every time the config changes, and want to be able to define the location of these at run time so the applications is more portable and the team deploying the application can follow their existing rules on where to store config.
I have read answers like this:
How to add custom "-Djava" arguments to Grails app? - but I'm not sure how this relates to me from the point of having the war file on my local machine, to deploying this with the param being passed in. I have been using the Tomcat Web Application Manager to simply select the war file to upload, and clicking delpoy - the file is uploaded and automatically exploded out and launched.
https://grails.github.io/grails-doc/latest/ref/Command%20Line/war.html - This suggests that the arguments have to passed in at the point of creating the war file which is not what I'm after.
In my code I have:
grails.config.locations = ["${System.properties['configFolder']}/application-config.properties"]
and I am looking for a way to include arguments when deploying from the Application Manager, or a command something like
deploy myApp.war -DconfigFolder="/usr/share/tomcat5/.grails/myApp/conf/application-config.properties"
EDIT
Turns out you're meant to pass in the runtime parameters when you start the tomcat server (or just after), not when you deploy the application.
The command needed is:
export CATALINA_OPTS="-DconfigLocation=/usr/share/tomcat5/.grails/TAPaS/"
or whatever params/values you want.
This can either be entered manually once the server has been started, or you can create a setenv.sh file containing that command within the CATALINA_HOME directory. This can be found out using the echo $CATALINA_HOME. Another way to find it is to use the start command below, and view the response, e.g.
bash catalina.sh start
Using CATALINA_BASE: /opt/apache-tomcat-7.0.61
Using CATALINA_HOME: /opt/apache-tomcat-7.0.61
Using CATALINA_TMPDIR: /opt/apache-tomcat-7.0.61/temp
Using JRE_HOME: /usr
Using CLASSPATH: /opt/apache-tomcat-7.0.61/bin/bootstrap.jar:/opt/apache-tomcat-7.0.61/bin/tomcat-juli.jar
If you have added the command to the setenv.sh file, use the command bash catalina.sh start to start the server. bash catalina.sh stop is used to stop it. You will need to use the path to .sh file if you're not in the directory of them.
As far as I can work out, this is not possible.
Whenever a .war file is dropped into the appBase
if autoDeploy attribute is "true" then the application will automatically be deployed while the Tomcat server is running
else, the application will be deployed when there Tomcat server is started
bash /opt/apache-tomcat-7.0.61/bin/shutdown.sh
bash /opt/apache-tomcat-7.0.61/bin/startup.sh
will shutdown and the start up the server again and any .war files that are in the appBase will be deployed.
The only instance I can see where an actual command is needed to deploy is when using the Client Deployer Package. More information on Tomcat Deployment found at: https://tomcat.apache.org/tomcat-8.0-doc/deployer-howto.html

How to change the path that jar files use in java Web Applications

I have written a java Servlet web application, using NetBeans 7.2.1. The program have some jar file libraries that I have attached to the project. The application runs fine using NetBeans and Apache Tomcat 7.0.27.
My problem is that some of the jar file libraries that I am using in the project, need to access to some folders and files. I put these folder and files on the same directory as the whole NetBeans project is. but I got this exception:
Exception: java.lang.RuntimeException: java.io.FileNotFoundException
So I used these codes to find out where should I put them:
out.println("current directory: " + new File(".").getAbsolutePath());
out.println("current directory: " + System.getProperty("user.dir"));
out.println("current directory: " + getServletContext().getRealPath(("/")));
So I figured out that the current working directory is:
C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.27\bin
My question is that how can I set different directory address for each web application? I have many web applications and some of them use the same resource file names. I can't just put all of them in one directory.
Please note that I don't have access to the source code of jar files to change the. I just need a way to set the absolute path that the jar files use.
I have the same problem when I put the WAR file on the unix server. The extracted WAR file is in this location on the server:
/data02/tools/Apache/Tomcat/apache-tomcat-6.0.37/webapps/BANNEROnline
But I figure I should put the resource folders and files in this path (moosavi3 is my username!):
/home/moosavi3
How can I change the path?
The working directory is the directory from which java.[exe,bin] is started. I assume the bin directory is where the tomcat start-up script is? If the jars are all using this working directory I don't believe there is a way to make different web-apps have different working directory, they're all loaded on the same jvm (java.exe) from the same working directory.
A working directory is the directory from which a binary is started, it is not some arbitrary value that you can change.
I suspect these jar files where meant to be run as standalone applications and expected the filesystem resources they are trying to access to be in the same location as themselves.
Any filesystem resources would have to be moved to the location of your java.exe so that the correct file path resolution can result from your jars.
Standard Servlet project requires external libraries to be placed in the 'WEB-INF/lib' directory under project root. You can search google for 'servlet directory structure' and do your own research for more information. Shared libraries between web applications can be placed in the 'lib' directory under tomcat root, they should be picked up by tomcat jvm. My recommendation would be to keep the dependencies project specific, because you may need different versions in different projects in the future.
Update:
Read this page on the tomcat documentation, it will explain exactly how the project should be structured, and how to add a library that will be shared across all web applications:
http://tomcat.apache.org/tomcat-7.0-doc/appdev/deployment.html
Update 2:
The following Stackoverflow link explains several options how to add a static file to your web application, that will available at runtime.
https://stackoverflow.com/a/2161583/940754
Update 3:
Add a path to the classpath using the project's manifest:
http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html

I want to know how to deploy the war file in apache tomcat and make it to run

I create a war file using apache ant and
i wanted to
deploy that .war file in tomcat and make it run
can u people help me with the steps..
i m not clear abt it
stop tomcat
move your war into [tomcat install dir]/webapps
start tomcat
tomcat will deploy the war on startup
for database connectivity copy the connector in the lib folder of project which is in WEB_INF folder
like point\war\WEB-INF\lib
create war File ...in war folder of the project
like c:/user/workspace/point/war/ there (point is project name)
...by command jar cvf point.war *
now type http://localhost/portnumber/ like mine is http://localhost/9090
press on tomcat manager and give user and password
go on the option deploy war file to upload ...browse and choice the war file create in war folder of project
upload the file
click on the /point which created by manager and their your file is uploaded