Tomcat web apps location question - java

I am q java web apps developer.
I am using Eclipse+Tomcat.
Currently I am working on about 10 web apps.
Here is my problem:
My web apps are not all placed under a single folder, they are located in different places.
To test my changes I have to export my web apps into war files or to move the updated files manually every time so the Tomcat will recognize them.
This seems like a waste of time for me.
Is there a way to tell tomcat where my web apps located instead of copying files every time?

Are you using Eclipse Webtools?
If you're not, consider doing so. You will be able to configure Eclipse to launch Tomcat with your web applications, have them auto-reloaded, etc...
Short of that, you could still configure your Tomcat server to pick up your web applications from wherever you want by specifying appropriate document base in either server.xml or your webapp's context.xml
Here's a link to Server Tools documentation

Here comes a tutorial telling you how tomcat and eclipse are supposed to work together to forge a development environment.
http://www.ibm.com/developerworks/opensource/library/os-eclipse-tomcat/index.html
Follow it and you will not be exporting the .war all the time.

You can do this easily with Tomcat. For each app you want run from somewhere else, you need to place a context fragment in $CATALINA_HOME/conf/Catalina/[host] directory. For example,
app1.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="/anywhere/app1" swallowOutput="true">
</Context>
The xml file name will be your context name.

You don't actually have to use Tomcat to test your apps... You can use the Jetty web server from within Eclipse, which is very comfortable.

You can try using Ant or Maven. It will solve this problems

I think you should load your application from context files rather than the server.xml. There is no need to load a application every time in the container. You can run your application from the place where it is.
Please use this link

Related

How does Jetty deployment on Azure App Service work?

I have a Java web app that I run on an Azure App Service instance. To deploy it, I use a Bitbucket repo with a .war file inside it. When I commit a new .war file to this repo, it is supposed to be deployed automagically by the service. However, more often than not, I have to either restart, re-deploy, or even upload the .war file via FTP for the deployment to be completed successfully.
I have a single Jetty instance residing in this service, hence my .war file is named ROOT.war. AFAIK, when uploaded to the service (whether via Bitbucket or FTP), this .war file should be unarchived into the same directory, which is /site/wwwroot/webapps. In my case, this doesn't happen. The web app works with the ROOT.war file sitting alone inside /site/wwwroot/webapps. And every once in a while, I get a ROOT folder under /site/wwwroot/webapps, with two default files index.jsp and background.png. I don't have the slightest idea what causes the ROOT folder to appear with these default files. The only clue I have is that it happened a couple of times after I changed an environment variable.
Also after the ROOT folder appears with the empty server files, the only way I can re-deploy the app is to manually delete this ROOT folder via FTP or the console provided in the portal, and only then my re-deploy request succeeds with my web app.
So, if it isn't clear enough, my question is what is going on here? I can't make anything out of the behaviors I'm facing. I feel like I'm using this Azure service blindly, and can't get to fix anything when something goes wrong. Are there any resources that may explain what happens in the background when a web app is deployed?
So, Azure API Apps are a PAAS, not IAAS service. You can access the PaaS platform by coming to yoursite.scm.azurewebsites.net, where you can browse the file system in CMD or Powershell, and you can see the running processes. This may feel like you are on a single VM, but you are not. The data you see here is replicated down into your API App instances. You can control how many instances you have through scaling your API App.
I have commonly seen your issue with deploying, then ROOT being empty(working internally to see this fixed...).
The best method that works every time for me, is to stop your API App, manually UNZIP your ROOT.war. Move the files into /ROOT/, then to start your API App.
You can simply place ROOT.war, and let the system unpack it when you turn it back on, but this can sometimes lead to that empty ROOT directory, then requiring another restart.
All of this has me moving to Spring-Boot instead. No unpacking required. Simply configure your web.config and drop the jar file.
https://learn.microsoft.com/en-us/azure/app-service-web/web-sites-java-custom-upload#springboot
I had the same problem. The solution is to call the endpoint after de deploy.
Stop the Azure App Service.
Deploy the ROOT.war artifact in the /webapps folder.
Start the Azure App Service.
Call the URL of the App Service once.
The four-step is very important and start the process that you mentioned before (the automagically deploy).
I lost a lot of time figuring out what was the problem.

How to deploy/upload a JSP file on Server

I have created a jsp file which will give an output in JSON format using java class and servlet, i am new to java and i don't have idea about the deployment of jsp file. Can anyone suggest me how to do it? I used to develop an asp.net web application in which there was a specific option available which called " publish project", but i cant find in eclipse.
I already have a php server in which i have uploaded few php files, can i use the same server to upload this file?
Currently, my application is running fine on localhost.
Please help me with this matter and thank you for your time.
To publish your project in Eclipse:
Right click your project
Export
Under Web > Choose WAR
Then just follow the instructions and your good to go.
It is done as a component of a WAR (Web Application Archive) file.
Upon deployment, JSP files are processed by the Servlet container. The processing effectively turns them into Servlets, such that the plain text of the JSP becomes println statements in the response of the Servlet, and the embedded Java code in the JSP becomes regular Java code in the Servlet.
The packaging details are covered in detail in the JEE7 tutorial, although earlier tutorials don't differ much in the details.
i assume you are using tomcat in your php? you can use tomcat or glassfish server to deploy your application. you just need the .war file of your application and upload it to the admin page of tomcat or glassfish server.
It should be in .war file format
Here are few links which can help you in building it from eclipse, link1, link2.
For deployment, there should be a server -- tomcat / glassfish / jboss which can provide platform to execute .war files.
IDEs and .war files are great productivity tools, but I'm of a mind that you need to understand how these things work from the command line. I'm using Apache Tomcat running on a Raspberry Pi as a development server. I developed my .jsp and then just copied to where it needed to be. In this example login.jsp needs to be in the root folder of an app called SEM. So, just copy it there and access it via its URL.
sudo cp login.jsp $CATALINA_BASE/webapps/SEM
http://localhost:8080/SEM/login.jsp
Didn't even have to restart Tomcat. :)

Are Tomcat webapps server independent?

I have made an app using Tomcat as my server. It uses JSP pages and java servlets.
If I copy my webapp (the folder) to some other server, will it run? What are the requirements for it to work/not work?
EDIT: Thanks for the answers. One more thing, what if some of my code uses filepath, that originates from the bin folder of Tomcat. For eg: "../webapps/MyApp/WEB-INF/sample.txt"
Is the directory structure the same in all servers?
Java servlets and JSP are intended to be portable technologies. There is a servlet standard and a JSP standard. Any servlet container (such as Tomcat) that implements the version of the standard that your code uses should be able to run your code.
You should move your web application around by copying its web application archive (WAR) file, rather thsn the directory (the extracted content of the WAR).
Ofcourse it will run , there are many servers out there that support jsp/servlet . Most of them are free for development and some are paid for deployment. See this link for more info
For most of the containers (i am not sure for all but most of them) like Tomcat, Jetty, Resin etc, you don't need to modify the project. You can place your project war file in the webapps directory and the project will get deployed on starting the server.

how to access files on local file system from deployed web app?

I have a web app deployed on Tomcat on Windows 7. I have various files on the PC, local file system, that I want to access from my web app. How can I do this or is this possible?
Ok, looks like I found the solution.
Can just use the File() object with absolute paths and that does the trick.
I thought there would be some special requirements for web apps but it looks like there isn't

Deploy Java EE Project in Weblogic

I have WebLogic installed in my computer. I already added it as a server in my Eclipse IDE. How do I configure my Web application to run or for it to be deployed on the WebLogic server. I found a sample project and found a weblogic.xml in it. Where do I start? Do I need to add something, etc.
If your web application is already a "Dynamic Web Application", then you should be able to deploy it just by right clicking on it, then Run As > Run on Server and choose the WebLogic Server runtime.
If this doesn't work, maybe you need to add the right facet to your project. Right click on your project and go to Properties > Project Facets and check that Dynamic Web Module is checked.
If this still doesn't work, maybe recreate a "Dynamic Web Application" from scratch and move (or copy) your sources to this newly created project.
Many tutorials are actually available at the WTP Community Resources page. See for example Using the Eclipse Web Tools Platform with Apache Tomcat. It is not specific to WebLogic but if you already have it setup in Eclipse, it should be easy to adapt the specific parts.
PS: It's hard to say anything about your sample project and the weblogic.xml as you didn't provide any detail about them. Maybe try to follow the advices above and, if you still have problems, update your question with more information.
There are a number of resources on using Eclipse with WebLogic, including Oracl'es Enterprise Pack for Eclipse. It's hard to tell without more information, but you need a WebLogic Domain configured with at least an Admin Server to deploy the web application to. When doing local development, it's acceptable to deploy applications to the Admin Server, but beyond this you typically want an Admin Server and a managed server where the application will get deployed to.
Here's some info on Eclipse and WebLogic - http://www.oracle.com/technetwork/developer-tools/eclipse/learnmore/index.html
Question is missing much details. You can find some detailed help here
http://download-llnw.oracle.com/docs/cd/E13222_01/wls/docs90/deployment/index.html

Categories