I have built the war archieve for a struts application and deployed but sometimes it refuses to start. when i througly checked it, i found that tomcat refuses to start the application if there is no internet connection even though its just a hello world application with no web service being used. On closer examination I found that the error is thrown while parsing struts.xml file when there is no internet connection. Seems as though the DTD is being checked to parse it and in absence of internet connection its not possible to fetch DTD and auto extracting and starting of the war archieve file fails.
How can this problem be avoided so as to work with no internet connection. I use netbeans and am a novice.
Try downloading the DTD, putting it on your local host and pointing to the local DTD in your doctype declaration.
Related
I have to realise a web application, on a Ubuntu server, using the Guacamole application, that has been developped by the Apache foundation. In order to understand how to manipulate it, I followed their official documentation, and tried to code my own application, but I can't manage to reach the said application.
The issue doesn't seem to come from Tomcat itself, for it sucessfully manages to host their original guacamole client, given in the said documentation. However, when I try to put my own code in the tomcat9/webapp/ directory, Tomcat just isn't able to launch the application. The manager is able to recognise it, and the app is actually displayed in the app list, but if I try to hit the "start button", I get an error that says :
FAIL - The application for the given context path [/guacamole-tutorial-1.4.0] can't be started
(The message may not be exact here, for it is displayed in my language, and I had to translate it)
I tried to search on internet some help, but I haven't been able to find any solution so far. I've seen a lot of people saying that one should check the logs whenever such issue occurs, but mine doesn't have any error entry. The file just ends up with the two following lines :
2022 06:47:10,753 INFOS [http-nio-8080-exec-29] org.apache.catalina.core.ApplicationContext.log HTMLManager : start: Starting web application '/guacamole-tutorial-1.4.0'
2022 06:47:10,753 INFOS [http-nio-8080-exec-35] org.apache.catalina.core.ApplicationContext.log HTMLManager : list Listing contexts for virtual host 'localhost'
My application is deployed as a .war file, in the same location as the guacamole clients, that actually works. I use Maven to compile the project, as told in Guacamole's documentation, and Nginx as a reverse proxy for Tomcat.
Thanks in advance.
After a few days of research, I managed to find the origin of the error, that happened because of my web.xml file. First, unlike what the tutorial said, it shouldn't begin with the tag, but with :
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
Then, I also found out that the way the Guacamole documentation tells how to declare the servlet is wrong. After fixing it, my application worked out.
I hope that this will help any other person that struggles with that part of Guacamole. I'll also add two pages that helped me understanding how to write the web.xml file :
http://www-igm.univ-mlv.fr/~dr/XPOSE2003/tomcat/tomcat.php?rub=16
https://mkyong.com/maven/how-to-create-a-web-application-project-with-maven/
One of the most important non-functional requirements of any project is the build process in my opinion and that's where I kinda get stuck in my java project, which has just one external dependency, a jdbc compatible database. All the tutorials about spring and deployment out there; I've read them all, but they either say:
run it with gradle bootRun applications.properties (yes works but on a webserver I'm not going to have any properties-files, but JNDI resource for example) or
build a deployable war file with JNDI resources (yes it works on the webserver, but not in my embedded webserver or I'm doing it wrong, but I cannot find any doc about how an embedded tomcat loads a context.xml from outside the jar file).
Now I tried to use the same setup as my server and installed tomcat7 and the #Asyc #Scheduled services run, but no servlets, like a simple /status page should return "OK" just for checking. catalina.out does not show any errors. My /manager from tomcat7-admin says deployment ok, and when I click start: "FAIL - Application at context path /xyz-0.1.0 could not be started
FAIL - Encountered exception org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/xyz-0.1.0]]"
And now I want to make a cut here and throw every "bootstrap" stuff away and start from zero.
So my question is, am I wrong when I say, that the big deal of my deployment is a jdbc JNDI resource provided from the web container, which is called 'jdbc/xyz' and everyone who wants to deploy my war needs that JNDI. That means so matter if you're using wildfly, jboss, tomcat, glassfish or any embedded server: your server impl has to provide that web container and jndi resource to make it run. And I don't want to configure any tomcat, glassfish or whatever implementation in my war.
Is that wrong?
It would be great, if you could help me. I'm playing around with that many weeks now :( and if A works B does not and vice versa. Would it be easier to use JEE?
Thank you.
First of all, I am aware that there are other questions regarding Tomcat, Eclipse, and the infamous 404 error. However, none of them manages to resolve the issue. I have spent well over 24 hours on this issue.
To save time, when I configured everything (including Tomcat, and creating a server in Eclipse), I:
• Changed the server location from "workspace metadata" to its correct location by using the "Switch Location" button located in the server's Properties window.
• I chose the "Use Tomcat Installation" option in Server Locations, and saved the choice I made.
In both cases, I restarted the server. If you're curious as to what app I'm currently working on, it's a simple Hello World app, found at: http://theopentutorials.com/examples/java-ee/servlet/how-to-create-a-servlet-with-eclipse-and-tomcat/
• I have included the Java file in the "welcome file" list inside web.xml.
Lastly, out of curiosity, why does the Eclipse browser only go to the project directory, and not the servlet itself? (If I add on the servlet name, then "Hello World" appears).
• Yes, if I enter "http://localhost:8080", the default Tomcat page appears, so no issues there.
Can anyone clue me in, as to why I am still getting 404s after all this, and following advice that has been marked as "Accepted" here at SO, such as the following:
HTTP Status 404 - The requested resource (/) is not available
Thanks in advance for any help, it is greatly appreciated.
The error 404 may occur because of large amount of different reasons. In order to resolve that, you should check your tomcat log file out first. It contains by the path:
%PATH_TO_WORKSPACE%\.metadata\.plugins\org.eclipse.wst.server.core\tmp%SERVER_NUMBER%\
logs
Usually it contains some stacktraces which discribes the problem. If not, then you should check your deployed application out there:
%PATH_TO_WORKSPACE%\.metadata\.plugins\org.eclipse.wst.server.core\
tmp%SERVER_NUMBER%\___YOUR_APP____
It might happen that your application was not deployed correctly by eclipse plugin (happens very often) and you should try this:
Project --> clean
'Right click on your server' --> clean
Or just remove your webapp from the directory I mentioned erlier and redeploy it from scratch.
There is something basic you need to understand regarding using tomcat(or application server for that matter). There is a slight difference between using from Eclipse and using from outside
Using From within Eclipse
What happens here is that Eclipse (by default) uses a copy of your tomcat installation and places it in its metadata workplace. This secondary tomcat is used by Eclipse for all deployments, re-deployments and all. Keep in mind that this is not your original copy of tomcat installation.
The difference in this tomcat installation is that is actually a minimal server, meaning that although it has all the deployment capabilities, it does not have some of the extra features that come with the tomcat installation and one main feature is the tomcat's homepage (the only reason why people out there get the infamous 404 resource not found when they try to run-on-server their application).
Workaround
Although not an issue (nor a bug from the Apache's end), you can still view your application by changing the URL to your application's url, homepage or no homepage ! All you have to do is change the url from http://localhost:8080 to http://localhost:8080/yourApplicationName and voila , the default page of your application will be shown that you mentioned in the welcome-page-list. Keep note that if you didn't specify a default page in your web.xml, you will again wind up with, yet again, the dreaded 404 resource not found page. The reason is that Tomcat has found your application, but it doesn't know what to do at the root context of your application. You can either map your servlet to the root of the application (that way it will always run at http://localhost:8080/yourApplicationName) or you can change the URL to the url-pattern that you mapped with the servlet in the web.xml, it must be something like http://localhost:8080/myApplicationName/myServletMappingPattern
I'm deploying my first Java web service app and just finished solving "Glassfish: Exception while preparing the app : Invalid resource : __pm". I created the glassfish-resources.xml file and placed it in my web-inf folder per http://www.oracle.com/technetwork/articles/java/pongegf-1517943.html. (It took me awhile to realize that Netbeans put the file in the wrong place to start with).
Now I'm wondering about distribution in the real world where the login credentials are buried in the WAR file via the glassfish-resources.xml file. Presumably if I ever need to change the credentials, I would have to rebuild for every server configuration I deploy to since my login credentials will be different between environments. Since we typically go through 2-3 stages of testing environments before going to production, this seems prone to introducing new errors or changes. Is there a way to maintain the login credentials in a config file that isn't part of the compiled WAR file or am I missing something more fundamental?
Thank you.
Normally you would setup a JDBC connection pool and use a JDBC resource to reference it. In the application you configure the JDBC resource used via the persistence.xml.
Something like this, when using the default Glassfish derby database (JDBC resource and connection are already setup for this, only the DB must be started):
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="my_persistence">
<jta-data-source>jdbc/__default</jta-data-source>
</persistence-unit>
So on all your environments you must ensure the JDBC resource has the same name (if you do not want to change the war file) but the actual config can be different, because it is stored in the Glassfish instance and not in your war file.
According to comments, as you asked #Trebor for determining DB type at runtime there is way to go through,visit thisJDBC connection
also
http://docs.oracle.com/javase/6/docs/api/java/sql/DatabaseMetaData.html
getClientInfo()
Entity Manager IN java
http://tomee.apache.org/examples-trunk/injection-of-entitymanager/README.html
this will definitely going to solve your issue .all the best .!
I am trying to point a Tomcat webapp from one Oracle database to another. To do so, I navigated to the webapps/[my web app]/WEB-INF/classes folder, and I edited the jdbc.properties file so as to change the connection URL, user, and password.
As soon as I did this, the webapp failed to work (it was working before). I end up getting Apache Tomcat error 404 - "The requested resource [my web app] is not available".
I know that the connection URL along with the user/password combo work perfectly fine, as I have tested it in SQL clients. Does anyone know why my webapp failed to work after my modifications? Are there any other modifications that I have to make?