Server Tomcat v8.0 Server at localhost failed to start.

最近准备再来复习一下j2ee的开发,毕竟好多年没碰过了,所以决定先写个jsp和servlet来看看, 开发环境是Eclipse Java EE和tomcat, 在web.xml里没加<servlet>时,tomcat是可以启动的, 也能找开tomcat的欢迎页面, 然而加了之后,tomcat就启不来了, 一直出现下面的错误,从这个exception根本看不出来是啥原因, 经过无限的尝试后来发现是<url-pattern>配的不对,原来是少了个/,

<url-pattern>/webapp.do</url-pattern>, 之前写成了

<url-pattern>webapp.do</url-pattern>

这个错误是不是很低级, 但我还是坚信错的不是我, 少了个/,  不至于tomcat启动不起来啊,最多也应该是url解析不对啊

SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/test]]
at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:868)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/test]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
… 7 more
Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern> webapp.do in servlet mapping
at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3102)
at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3077)
at org.apache.catalina.startup.ContextConfig.configureContext(ContextConfig.java:1368)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1172)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:767)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:302)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5083)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
… 7 more

Jul 25, 2014 3:59:39 PM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:439)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:752)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.startup.Catalina.start(Catalina.java:625)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:924)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:868)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
… 7 more

Jul 25, 2014 3:59:39 PM org.apache.catalina.startup.Catalina start
SEVERE: The required Server component failed to start so Tomcat is unable to start.
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.startup.Catalina.start(Catalina.java:625)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:752)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
… 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:439)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
… 9 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:924)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
… 11 more

Jul 25, 2014 3:59:39 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-nio-8080"]
Jul 25, 2014 3:59:39 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-nio-8009"]
Jul 25, 2014 3:59:39 PM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
Jul 25, 2014 3:59:39 PM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-nio-8080"]
Jul 25, 2014 3:59:39 PM org.apache.coyote.AbstractProtocol destroy
SEVERE: Failed to destroy end point associated with ProtocolHandler ["http-nio-8080"]
java.lang.NullPointerException
at org.apache.tomcat.util.net.NioEndpoint.releaseCaches(NioEndpoint.java:307)
at org.apache.tomcat.util.net.NioEndpoint.unbind(NioEndpoint.java:482)
at org.apache.tomcat.util.net.AbstractEndpoint.destroy(AbstractEndpoint.java:792)
at org.apache.coyote.AbstractProtocol.destroy(AbstractProtocol.java:531)
at org.apache.catalina.connector.Connector.destroyInternal(Connector.java:1023)
at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)
at org.apache.catalina.core.StandardService.destroyInternal(StandardService.java:588)
at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)
at org.apache.catalina.core.StandardServer.destroyInternal(StandardServer.java:842)
at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)
at org.apache.catalina.startup.Catalina.start(Catalina.java:629)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)

Jul 25, 2014 3:59:39 PM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["ajp-nio-8009"]
Jul 25, 2014 3:59:39 PM org.apache.coyote.AbstractProtocol destroy
SEVERE: Failed to destroy end point associated with ProtocolHandler ["ajp-nio-8009"]
java.lang.NullPointerException
at org.apache.tomcat.util.net.NioEndpoint.releaseCaches(NioEndpoint.java:307)
at org.apache.tomcat.util.net.NioEndpoint.unbind(NioEndpoint.java:482)
at org.apache.tomcat.util.net.AbstractEndpoint.destroy(AbstractEndpoint.java:792)
at org.apache.coyote.AbstractProtocol.destroy(AbstractProtocol.java:531)
at org.apache.catalina.connector.Connector.destroyInternal(Connector.java:1023)
at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)
at org.apache.catalina.core.StandardService.destroyInternal(StandardService.java:588)
at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)
at org.apache.catalina.core.StandardServer.destroyInternal(StandardServer.java:842)
at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)
at org.apache.catalina.startup.Catalina.start(Catalina.java:629)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)

 

perl how to rename file name

perl rename file name,
perl replace specific characters in file name

scripts:

#!/usr/bin/perl -w

foreach my $file(glob “*%2B*.txt”) {
my $newfile = $file;
$newfile =~ s/%2B/\+/;
if (-e $newfile) {
warn “already exist $newfile \n”;
}elsif(rename $file, $newfile) {
print ‘renamed ‘, $file,’ => ‘, $newfile, “\n”;
}
}

Could not find gdb.setup under ./libs/armeabi

运行ndk-gdb出现了下面的错误,

Could not find gdb.setup under ./libs/armeabi
This usually means you modified your AndroidManifest.xml to set
the android:debuggable flag to ‘true’ but did not rebuild the
native binaries. Please call ‘ndk-build’ to do so,
*then* re-install to the device!

原来是因为我在jni目录下运行的ndk-build命令, 而不是在项目的根目录下, 可能在jni下运行的话可能根本没有办法检测到根目录下的AndroidManifest.xml里的android:debuggable=”true” (只是猜测)

连不上mysql, can’t connect to mysql

明明已经grant all on *.* to xx@’%’ identified by ‘xxx’;了, 而且还运行了flush privileges;
可用Mysql Workbench就是连不上mysql,

折腾了半天,发现原来新装的centos的防火墙是打开的, 对mysql端口3306没有开放, 只要把这个端口打开就连上了

Capture

AsyncTask并不是多线程异步执行多任务

关于AsyncTask, 我想大家可能会有些误解, 这其中也包括我自己, 一度被这个问题调试了好久, 开始以为是DefaultHttpClient不能同时发多个request, 这主要是因为还有个AsyncHttpClient, 这个一直让我觉得DefaultHttpClient不是异步的

从字面上来看AsyncTask它是一个多线程异步执行的任务, 但实际上不完全是这样的

例如 我如果像下面这样连续创建5个AsyncTask,  它实际上是一个接着一个连续执行的, 并不会异步多线程同时执行

for (int i = 1; i <= 5; i++) {

Log.d(DEBUG_TAG, “for : ” + i);

String url = “http://baidu.com?i=” + i;

new DownloadWebpageTask(url).execute();

}

为什么呢, 我们可以从官方文档里找到原因: Order of execution

When first introduced, AsyncTasks were executed serially on a single background thread. Starting with DONUT, this was changed to a pool of threads allowing multiple tasks to operate in parallel. Starting with HONEYCOMB, tasks are executed on a single thread to avoid common application errors caused by parallel execution.

也就是说现在所有的AsyncTask都只在一个线程里执行, 一个执行完了再执行另外一个

如果要多个AsyncTask在多个线程里异步执行, 我们可以这样做:

private static ExecutorService LIMITED_TASK_EXECUTOR = (ExecutorService) Executors.newFixedThreadPool(THREAD_NUMBER);

new DownloadWebpageTask(url).executeOnExecutor(LIMITED_TASK_EXECUTOR);