My Dynamic Web Project welcome-file doesn't get affected by changes - java

This is a pretty strage and hassle problem i have here.
I created a Dynamic Web Project in Eclipse and created an HTML file named "inicio.html".
I put this into my web.xml <welcome-file> and all seemed to work okay.
I could Run on server without any problem.
Until i dragged a folder into my webapp.
folder in my project
Now when i run on server my file doesnt change at all, and even when i change the welcome-file from web.xml it doesn't change.
It looks like there's another file somewhere like a copy from the original "inicio.html" that's executing on my server.
this is an example of what's happening
I tried to change my TomCat's web.xml file and it doesn't works.

It's unlikely that the new IMG folder is relevant. Deployment Descriptors aren't really hot swappable.
Make sure automatic building is enabled on the Project menu, and then try right-clicking on the server in the Servers View and choosing "Clean Tomcat Work Directory". Otherwise, you'll need to restart the server for changes to take effect.

Related

Why Tomcat works fine when I put a .jsp but with a .html doesn't works?

I'm working with eclipse and I created a project, I put a test.html and test.jsp file in the root folder. In the URL of the Google Chrome I put this:
http://localhost:8080/project/test.html Error 404
http://localhost:8080/project/test.jsp Works (hello world!)
What is happening?
Double check if your test.html exists under this path:
"Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\project"
If exists, then it should be accessed normally, if not then you have to clean/build your application correctly or even try to restart eclipse.
Based on your follow-up comments about the custom Tomcat install and the project error message, it sounds like you either don't have Eclipse properly configured to use your Tomcat server, or you don't have your project associated with the Tomcat server you've set up, and so perhaps your changes arent being deployed properly. See if that issue has a quick fix suggestion (right click it) or go through your project settings and verify your selected server runtime. Sorry on phone can't give specific instructions.

Editing Folder content in tomcat manually?

I have a WAR file called ROOT.war where I uploaded into Tomcat few days back. There I have few "public" HTML pages like index.html, about.html etc. These pages has no connection with the programatic part of the application, instead containing a link for login.jsp.
Now, I need to change the content of the index.html and about.html. What I was used to do is rebuild the entire WAR file and re-uplaod it, but now can't do it for small and iterative changes like this because the application is in use.
So, can I simply access the webapps -> ROOT folder in Tomcat and replace the index.html? Will it affect the process of the application?
It works but avoid such practices which lead to discrepancies.
Follow standard deployment process - rebuild the entire WAR file and re-upload it during deployment window.
You can, and It will work. You can even change the JSP code. The only issue you may have is that when you redeploy a new version of the war, changes made in the server will ve overriden by the new version, so you better change it in the original tool also.

jquery.js doesn't get loaded in Tomcat

OK, so I found out so far, that despite me having the jquery.js file in the same folder as the jsp file I have, the Ecipse-Tomcat configuration is executing the files in a different location and it takes all the files except for jquery.js How is this possible and how I can make it automatically load the file in it execution folder?
In my case jquery refuses to work unless I specifically put it in the folder where tomcat is executing the files... Any ideas? Thanks.
Alright, after a few hours of struggling, I finally found a solution to this problem. Seems Eclipse Tomcat probably isn't refreshing and checking the files in the path well if you're using any other perspective than Java EE. In my case I was using and working all the time in the normal Java perspective and this way it never reloaded even when I would click refresh. Now however I switched to Java EE view and clicked refresh. The file finally appeared and jquery finally started working!
All JS/CSS/HTML files are static resources and would be served from Tomcat through DefaultServlet. You would need to configure the default servlet in your web.xml with appropriate location to the folder where these are present. This has nothing to do with the location of JSP, though the JSPs can also go under the same folder.

Tomcat and Eclipse Zero Turnaround Deployment

I want to be able to deploy code changes to Tomcat (near instantly), while I'm developing in Eclipse.
So far, I have my output from Eclipse placing the built classes in the WEB-INF/classes folder of my web application.
I also have a reloadable context, with the web.xml as a watched resource. Any edit / save to this file does reload my web app, taking just over one second - much quicker than building a new war file and deploying it in full.
However, what I'd like to do is trigger the redeploy when I edit any source file. As the .class files are being modified in Tomcat, it seems I just need to monitor any changes in the WEB-INF/classes folder and it's children.
I've read that I can add additional watched resources in Tomcat's context.xml but this doesn't seem to be quite what I need - unless it's possible to specify a directory that will be watched (including recursively monitoring sub folders and files)?
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>WEB-INF/someother.file</WatchedResource>
<Manager pathname=""/>
</Context>
So essentially, my question is can I watch the entire classes folder (without including each WatchedResource explicitly) to trigger a redeploy in Tomcat?
If not, can I configure Eclipse to touch the web.xml file, whenever I save a source file in that project? I'm developing on a Windows system. :(
PS I'm not interested in the JRebel product. Any answer should be a free solution.
Update
According to the Tomcat documentation, the classes folder should be monitored by setting the context to reloadable:
Set to true if you want Catalina to
monitor classes in /WEB-INF/classes/
and /WEB-INF/lib for changes, and
automatically reload the web
application if a change is detected.
Only changes to the web.xml seem to trigger a reload. Is this a bug or is my setup incorrect?
Also, I've read about setting the docBase attribute for a given context:
docBase="webapps/someExample"
This appears to be close to what I need, as I could then republish in Eclipse quickly. My only problem is that I require several web apps / servlets to be running in Tomcat concurrently, on the same port etc.
For these cases I set the eclipse build output to WEB-INF/classes as you have done and create a context file with the docBase set to the webapp folder (parent of WEB-INF) in the project. This is manually placed in conf/Catalina/localhost (assuming default configs for some elements of server.xml). End result is tomcat ends up serving from the development directory. So, change a servlet or other class and it is updated to the classes folder. Save a jsp and it is immediately available.
If project structured like:
src
|-main
|-webapp
|-images
|-js
|-WEB-INF
|-jsp
|-classes
Then context would be like:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/path" reloadable="true"
docBase="<pathtoproject>/src/main/webapp" />
Maybe the Web Tools Project of Eclipse with auto-redeploy enabled will help you? Add a server, open properties and under Publishing you will see a radiobutton saying "Automatically publish when resources changes". This will result in a redeploy if classes changes otherwise just overwrites resources. You can install WTP via a built in update site (Eclipse only), so check out your software updates. It is free for most servers but it does not support certain Websphere features?
Try the Spring Loaded JVM agent I've described in the following answer:
https://stackoverflow.com/a/37064672/1034436
While that has worked for my Spring web application, this should work with vanilla Eclipse + WTP + Tomcat + Dynamic Web Applications since Spring Loaded works on the JVM/classloading level.
You will still need to use the "Automatically publish when resources changes" as mentioned by #toomasr in his answer. However, you must also disable "Module auto reload by default" option as well. If you already added/published modules from Eclipse to Tomcat, then disable "Auto Reload" for each web module (via the Tomcat config page's Modules tab). That should prevent Tomcat from reloading the application when a single class file is updated, which I suspect is what all that reload/wait time is.

Deploying a WAR file gives me a 404 Status Code on Tomcat?

I am fairly new to Tomcat. I just managed to build a project and exported it as a WAR file. I tried manually copying a WAR file to the Tomcat folder then restarting. It created the folder structure and everything but I get a 404 Status code when I try to reach the application. I tried deploying it through the Tomcat Admin panel but I'm seeing the same behavior. Am I doing anything fundamentally wrong?
Assuming that you have full privileges with the Tomcat installation, try going to http://localhost:8080/manager/html/, if you don't know the password to get into that area, look for the tomcat-users.xml file in your ${tomcat-installation}/conf directory, and that should have it. If it has no entries in it then you will want to add an entry like the following to it:
<user username="username" password="password" roles="admin,manager" />
See whether your application shows up in that screen, and if it does, click on the link and see if that gets you anywhere. If it doesn't, then I suggest following ifishers's advice, and looking at the log files to see if it lists any errors.
But long story short, most likely something is screwed up with your project's web.xml
In more recent times, this condition might occur if JAVA_HOME points to an earlier version of Java than the code in the WAR. Tomcat might use JAVA_HOME to determine JRE_HOME it shows after running startup.bat in Tomcat's BIN directory. While Tomcat may be happy itself with the Java version it gets, for the application this might not be sufficient. In my case, Tomcat 8.0.49 was running alright with JDK1.7, while the application was not initializing at all (yes, it was a Spring Boot application, WAR was being unpacked, but that's all) - without giving any errors. After setting JAVA_HOME to the location of JDK1.8, the problem was solved.
I have the same problem.
My problem is my application name and war file name are different.
I have change war file name to my application name.
Here, when your application is deployed tomcat automatically extract your war file with same name. In my case my service name is my-web-service(i.e.https://localhost:8080/my-web-service/) and my war file name is MY-java-connector-0.0.1-SNAPSHOT.war(this is my project folder name). Now tomcat is looking for my-web=service folder and it finds epicor-java-connector-0.0.1-SNAPSHOT folder. so rename the folder to my-web=service.war and it is working.
I had the same issue, my problem was that I was copying the file via sftp straight into the webapps dir of tomcat which may have caused a polling issue causing it to not deploy correctly.
Tomcat monitors the webapps dir and when it sees the .xml it will crack on and do its thing, problem is that maybe everything hasn't been copied across yet. :(
Best to create a staging folder, move or copy the war to that folder and then use linux mv command to move it into the webapps - mv is atomic so tomcat won't do anything until the operation is complete.
Magic.
Credit goes to a very very random post that I found on javarance which in turn lead to : http://pub.admc.com/howtos/tomcat/ch02.html#stagedir-section
Hope this helps someone else :)
If your'e using Spring-Boot like me to create your WAR file make sure to add the following to your main Application file.
#SpringBootApplication
public class serverTestApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(serverTestApplication.class, args);
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(serverTestApplication.class);
}
}
I was stuck on this for awhile, looked through dozens of guides. This is the video that finally showed me I never configured my application properly:
https://www.youtube.com/watch?v=05EKZ9Xmfws
My best guess is that you have not configured the welcome files in your web.xml. If you go to /app/ you need to have some default file available. Typically, people either created an index.html or they have welcome file settings to point the user to the correct jsp.
I ran into this problem, too.
My simple roundabout solution is to change docBase path.
problem occurs when
docBase=".../tomcat/webapps/app_name.war";
problem solved with
docBase=".../tomcat/webapps/app_foldername/web"
I had the same problem with tomcat and just fixed it by forcing my IDE to create a web.xml file. Mine was missing. It would deploy the project but I would still get the 404 error. I read through several of these tutorials but to no avail. I read somewhere that the web.xml file needed to be configured correctly. Went to find the web.xml in the WEB-INF folder, and there was no folder and no web.xml file. I did a quick google on how to create on using my IDE and then compiled my program with the web.xml output, and it fixed the problem for me. Hope that helps. Cheers!
FWIW I had this problem and fixed it by discovering I was accessing the wrong host, like "http://wronghost:8080/why_is_this_war_not_there" so if it says "XX.war successfully deployed" in catalina.out/localhost.*.out that may be a hint for followers.
I had the same issue. In my case there were no errors in the log files, I had a welcome page defined, it was listed in the Tomcat manager webapp, and it deployed and worked fine on my dev machine. However, visiting the app at http://example.com/myApp just returned a 404 error.
It turns out the problem was in the Apache config. Apache didn't have a mount point, so it didn't know to proxy those requests to Tomcat.
Adding in the appropriate directive fixed the problem:
ProxyPass /myApp ajp://127.0.0.1:8009/myApp
If you have not created any welcome page like index.html JSP or whatever then create one. project must have an index page. I just created one say index.html and the problem is solved..🙏🙏🙏
Did you try
localhost:8080/app
assuming your war file is app.war?
edit for comment -- then your web.xml is screwed up.

Categories