I made a .war file that prints strings to the console when I run in cmd
java -jar print.war
However, when I deploy this .war file to tomcat 8 by copying the file into the webapps folder:
C:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps
I get this error whenever I go to http://localhost:8080/print
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Dec 19 14:36:59 CST 2016
There was an unexpected error (type=Not Found, status=404).
No message available
Does that mean my deployment failed? Or is there something wrong with my .war file?
Thanks.
In order to process http request you need to specify a class that extends javax.servlet.http.HttpServlet and provide a deployment descriptor to let your servlet container know where should it delegate specific request.
If those terms are new to you, visit: https://www.tutorialspoint.com/servlets/ for more informations.
Related
When launching the application from STS, the application works fine and I can access everything.
But once I create a jar file using mvn clean install, and then deploying this on an aws ec2 I get the following error :
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this
as a fallback.
Thu Sep 14 08:46:01 UTC 2017
There was an unexpected error (type=Internal Server Error, status=500).
Exception parsing document
Any reason why it would show this ?
Thank you
I have a Java servlet web app (.war) which I deployed to Tomcat Ubuntu server.
Can I change the content the Java classes at: myProject/WEB-INF/classes/
without re-export-and-deploy the entire app ?
Thanks in advance.
I could thought of below to re deploy your app without restarting tomcat:
Modify your java file
Generate .class file
Replace it with your existing file in Tomcat
Trigger your app restart by touching WEB-INF/web.xml
Disclaimer: I don't recommend doing this because it can give unexpected results. I am aware that sometimes you need to do "quick-and-dirty" fix, but consider yourself warned :)
I assume you have a Web application, let's call it 'MyApp'. Go to <TOMCAT-DIR>/webapps and locate your MyApp.war file. Put new .class file into the MyApp.war (open it with some archiver) and then delete the folder <TOMCAT-DIR>/webapps/MyApp. Deleting the folder means undeployment for Tomcat. After some time, Tomcat will figure out that it has a .war file in his <TOMCAT-DIR>/webapps folder that needs to deploy and it will automatically do it. You will see in Tomcat's log something like:
Aug 25, 2015 9:24:55 AM org.apache.catalina.startup.HostConfig undeploy
INFO: Undeploying context [/MyApp]
Aug 25, 2015 9:24:55 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /home/tomcat/apache-tomcat-7.0.55/webapps/MyApp.war
Aug 25, 2015 9:25:17 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive /home/tomcat/apache-tomcat-7.0.55/webapps/MyApp.war has finished in 21,937 ms
And there you go, you just refreshed your application without redeployment and without restarting server.
How to configure system environment variables inside one Jetty application?
e.g. For database connection details, putting it in file and checking it into cvs is bad idea. For that reason using system environment is one way to go. While the system environment variables are defined in /etc/environments file or .bashrc/.zshrc file , in Jetty application, doing System.getenv("variable_name") won't give anything. It will result in null.
I have read this question: Configuring a Jetty application with env variables which concludes that which tells that Jetty doesn't support System.getenv() and not even in start.ini file.
And jetty and etc environment on ubuntu 12.10 which says In the jetty.sh script you can source the /etc/environment file and they will be present. which I tried and didn't get the values as expected meaning it gave me only null.
If I can't use the default System.getenv() or in any .ini file then how to specify credentials such as Database connection etc ?
Not supporting System.getenv() is not a Jetty thing, but a Java thing.
There are ton of restrictions around System.getenv() and your environment, making it nearly useless in all but the most naive and basic test case. (eg: multiline values are not supported. multiline entries can break parsing. keys without values are not supported. keys without values can often merge with next key during parsing. entries with non US-ASCII characters are not supported. entries with control characters are not supported.)
The common technique when using System Environment variables with Java programs is to use the shell specific techniques to obtain the values and inject them either on the command line, or into a ini file format for Jetty to then use.
Depending on your technique, these values would either show up as Jetty properties, or as Java System Properties.
Just created a project to demonstrate 4 ways to accomplish this at
https://github.com/jetty-project/jetty-external-config
External Configuration Properties with Jetty
Demonstration of how to configure simple properties that can be accessed
by Servlets within Jetty.
This demonstration shows 4 different ways to configure a property
at runtime, that can then be read by the Servlet running within
Jetty.
The props.war
This is a simple war file with a single HttpServlet and a WEB-INF/web.xml
[jetty-external-config]$ jar -tvf target/props.war
0 Mon Feb 23 09:02:14 MST 2015 META-INF/
131 Mon Feb 23 09:02:14 MST 2015 META-INF/MANIFEST.MF
0 Mon Feb 23 09:02:14 MST 2015 WEB-INF/
0 Mon Feb 23 09:02:14 MST 2015 WEB-INF/classes/
0 Mon Feb 23 09:02:14 MST 2015 WEB-INF/classes/org/
0 Mon Feb 23 09:02:14 MST 2015 WEB-INF/classes/org/eclipse/
0 Mon Feb 23 09:02:14 MST 2015 WEB-INF/classes/org/eclipse/demo/
2188 Mon Feb 23 09:02:12 MST 2015 WEB-INF/classes/org/eclipse/demo/PropsServlet.class
572 Mon Feb 23 08:45:22 MST 2015 WEB-INF/web.xml
See PropsServlet.java for details of behavior.
Just compile the top level and the war file will be built and placed in all of the demo jetty.base locations for this project.
Example #1: Basic Command Line
The /base-command-line project contains a simple start.ini which starts jetty on port 9090, and deploys the webapp. no extra configuration is done by the on-disk configuration.
If you start it up like so ...
[base-command-line]$ java -jar /path/to/jetty-distribution-9.2.7.v20150116/start.jar
2015-02-23 09:15:46.088:INFO::main: Logging initialized #290ms
2015-02-23 09:15:46.222:INFO:oejs.Server:main: jetty-9.2.7.v20150116
2015-02-23 09:15:46.235:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:/home/joakim/code/stackoverflow/jetty-external-config/base-command-line/webapps/] at interval 1
2015-02-23 09:15:46.325:INFO:oejw.StandardDescriptorProcessor:main: NO JSP Support for /props, did not find org.eclipse.jetty.jsp.JettyJspServlet
2015-02-23 09:15:46.343:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext#6e7f61a3{/props,file:/tmp/jetty-0.0.0.0-9090-props.war-_props-any-27537844855769703.dir/webapp/,AVAILABLE}{/props.war}
2015-02-23 09:15:46.353:INFO:oejs.ServerConnector:main: Started ServerConnector#67cd35c5{HTTP/1.1}{0.0.0.0:9090}
2015-02-23 09:15:46.353:INFO:oejs.Server:main: Started #555ms
you'll see that it has started up and deployed to the /props context path.
From here you can test for properties in the servlet via tooling like wget or curl.
Example:
$ curl http://localhost:9090/props/props
[java.runtime.name] = Java(TM) SE Runtime Environment
[sun.boot.library.path] = /home/joakim/java/jvm/jdk-7u75-x64/jre/lib/amd64
[java.vm.version] = 24.75-b04
[java.vm.vendor] = Oracle Corporation
[java.vendor.url] = http://java.oracle.com/
...
[file.separator] = /
[java.vendor.url.bug] = http://bugreport.sun.com/bugreport/
[sun.io.unicode.encoding] = UnicodeLittle
[sun.cpu.endian] = little
[sun.desktop] = gnome
[sun.cpu.isalist] =
You can even request a specific property ..
$ curl http://localhost:9090/props/props/user.timezone
[user.timezone] = America/Phoenix
Lets stop the server and run it with a system property of our choice.
Notice the -Dfoo=bar ?
[base-command-line]$ java -Dfoo=bar -jar /path/to/jetty-distribution-9.2.7.v20150116/start.jar
2015-02-23 09:15:46.088:INFO::main: Logging initialized #290ms
2015-02-23 09:15:46.222:INFO:oejs.Server:main: jetty-9.2.7.v20150116
2015-02-23 09:15:46.235:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:/home/joakim/code/stackoverflow/jetty-external-config/base-command-line/webapps/] at interval 1
2015-02-23 09:15:46.325:INFO:oejw.StandardDescriptorProcessor:main: NO JSP Support for /props, did not find org.eclipse.jetty.jsp.JettyJspServlet
2015-02-23 09:15:46.343:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext#6e7f61a3{/props,file:/tmp/jetty-0.0.0.0-9090-props.war-_props-any-27537844855769703.dir/webapp/,AVAILABLE}{/props.war}
2015-02-23 09:15:46.353:INFO:oejs.ServerConnector:main: Started ServerConnector#67cd35c5{HTTP/1.1}{0.0.0.0:9090}
2015-02-23 09:15:46.353:INFO:oejs.Server:main: Started #555ms
and look for it via curl ...
$ curl http://localhost:9090/props/props/foo
[foo] = bar
That demonstrates access of a property that was specified via the command line, now lets look at the other choices.
Example #2: Using start.ini
The /base-startini project contains a simple start.ini which starts jetty on port 9090, and deploys the webapp.
This start.ini also contains a foo.ish property.
Lets start up Jetty and try our props servlet access again ...
[base-startini]$ java -jar /path/to/jetty-distribution-9.2.7.v20150116/start.jar
2015-02-23 09:16:46.088:INFO::main: Logging initialized #290ms
2015-02-23 09:16:46.222:INFO:oejs.Server:main: jetty-9.2.7.v20150116
and request it via curl ...
$ curl http://localhost:9090/props/props/foo.ish
[foo.ish] = bar
Example #3: Using start.d optional ini
The /base-startd project contains a simple start.ini which starts jetty on port 9090, and deploys the webapp.
This start.ini also contains no extra properties that we are interested in.
The start.d/myconf.ini contains a property called foo.d that we are interested in.
Lets start up Jetty and try our props servlet access again ...
[base-startd]$ java -jar /path/to/jetty-distribution-9.2.7.v20150116/start.jar
2015-02-23 09:19:46.088:INFO::main: Logging initialized #290ms
2015-02-23 09:19:46.222:INFO:oejs.Server:main: jetty-9.2.7.v20150116
and request it via curl ...
$ curl http://localhost:9090/props/props/foo.d
[foo.d] = over here
Example #4: Using --include-jetty-dir optional config
The /base-jettyinclude project contains a new start.ini which starts jetty on port 9090, and deploys the webapp.
This start.ini also contains no extra properties that we are interested in.
However, the start.ini uses the --include-jetty-dir=../jettydir optional configuration that points to an entirely new interrim jetty.base configuration source.
The ../jettydir/start.ini contains a property called foo.jetty.dir that we are interested in.
Lets start up Jetty and try our props servlet access again ...
[base-jettyinclude]$ java -jar /path/to/jetty-distribution-9.2.7.v20150116/start.jar
2015-02-23 09:24:46.088:INFO::main: Logging initialized #290ms
2015-02-23 09:24:46.222:INFO:oejs.Server:main: jetty-9.2.7.v20150116
and request it via curl ...
$ curl http://localhost:9090/props/props/foo.jetty.dir
[foo.jetty.dir] = more of the same
I have deployed a web app including an EJB (RESTFul web service) from Netbwans 8 into Glassfish 4. This includes a cross origin resource sharing filter. I am getting the "HTTP Status 500 - Internal Server Error" error in the browser when i try to view the output of the web service (directly from the web service path, not from a client per se). I saw in a forum that i might try un-checking a Jersey option in my project properties in Netbeans but i see no such option. The only thing I've found in the logs is:
Info: WELD-000900 2.0.0 (SP1)
Warning: Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled
Warning: Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled
Info: Registering the Jersey servlet application, named com.mycompany.enterprisesample.service.ApplicationConfig, at the servlet mapping /webresources/*, with the Application class of the same name.
Aug 21, 2014 11:31:10 AM com.sun.enterprise.glassfish.bootstrap.osgi.BundleProvisioner$DefaultCustomizer getLocations
WARNING: Skipping entry because it is not an absolute URI.
Aug 21, 2014 11:31:10 AM com.sun.enterprise.glassfish.bootstrap.osgi.BundleProvisioner$DefaultCustomizer getLocations
WARNING: Skipping entry because it is not an absolute URI.
Registered com.sun.enterprise.glassfish.bootstrap.osgi.EmbeddedOSGiGlassFishRuntime#5c8edb94 in service registry.
Add
<jvm-options>-Djavax.xml.accessExternalSchema=all</jvm-options>
line of code in the domain.xml file at glassfish4\glassfish\domains\domain1\config\domain.xml folder
inside <java-config> </java-config> tag as :-
<java-config>
.
.
<jvm-options>-Djavax.xml.accessExternalSchema=all</jvm-options>
</java-config>
Note:- add the above line of code at the last of the –D..... code of the domain.xml file. Adding it at random position may not gurantee that this will work.
I am trying to deploy an application using spring in tomcat7 running on ubuntu12. When I drop the war file in the webapps directory, the directory is created for the application inside webapps - yet the application does not load up. Latest issue is copied below. Any thoughts on troubleshooting this will be appreciated.
Java versions are the same on the computers where the war file was generated vs the one where I am deploying the application. I do not see a file permission issue - there is a logging.properties file in tomcat7.
Jan 31, 2014 10:43:05 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Jan 31, 2014 10:43:05 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/test-webapp] startup failed due to previous errors
Jan 31, 2014 10:43:05 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/test-webapp] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.
Update:
I missed an error message. I will update this ticket shortly.
Update:
I was missing a file in tomcat meant for the application deployment - pilot error. Thanks to everyone for sharing their thoughts- much appreciated!
It looks like a known issue of MySQL over tomcat, have you tried yet any of the suggested solutions in
http://bugs.mysql.com/bug.php?id=69526
http://bugs.mysql.com/bug.php?id=68556
?