• I-Jetty部署war包到安卓手机


    罗嗦一下:最近在做一个把iJetty集成到安卓软件中的项目,今天经过4小时的折腾,到快绝望了才让我把这个问题给解决掉了,哎,记下,以免别人走我的老路,还有提醒大家,以后多关心下Log。。。

    1、制作安卓手机能识别的war包

    声明:直接用Eclipse导出的war包,安卓手机是无法解析的,原因是安卓用的java虚拟机是谷歌自己写的,做安卓开发的人都知道为什么,就不说明了。

    (1) 把web工程的lib下的jar文件转换成安卓认识的dex文件

    以下指令说明:把lib和classes的中与java有关的文件编译成dex并打包到D盘根目录下(dx.bat在android sdk的build-tools中有)


    dx.bat --dex --output=D:classes.zip D:WorkSpaceTestWebRootWEB-INFclasses D:WorkSpaceTestWebRootWEB-INFlib

    (2) 把classess.zip文件复制到web工程的lib文件夹下,并删除lib文件夹下所有的jar包,但是classes中的class文件要保留。
    (3) 把Web工程打包成war(打开cmd后,先cd到web工程的WebRoot下,如cd D:TestWebRoot),注意指令后面的英文句号,有用的!!!


    jar cvf Test.war .
    (4) 在WebRoot文件夹下会生成Test.war,把它复制放到到安卓的ijetty/webapps下,重启ijetty服务器后,有些手机就可以看到效果了。


    2、解决HTTP ERROR: 503 SERVICE_UNAVAILABLE

    这个问题百度、谷歌后,基本没人回答的出来,当然问的人也少,我也是最后看到了log之后才知道原因的,以下原因分析:

    先看log:

    Failed startup of context o.e.j.w.WebAppContext{/Test,[file:/data/data/org.mortbay.ijetty/cache/jetty-0.0.0.0-8080-Test.war-_Test-any-/webinf/, jar:file:/storage/emulated/0/jetty/webapps/Test.war!/]},file:/storage/emulated/0/jetty/webapps/Test.war
    java.io.IOException: Couldn't open jar:file:/storage/emulated/0/jetty/webapps/Test.war!/WEB-INF/web.xml
    at org.apache.harmony.xml.ExpatParser.openUrl(ExpatParser.java:755)
    at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:292)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:390)
    at org.eclipse.jetty.xml.XmlParser.parse(XmlParser.java:199)
    at org.eclipse.jetty.xml.XmlParser.parse(XmlParser.java:215)
    at org.eclipse.jetty.webapp.Descriptor.parse(Descriptor.java:60)
    at org.eclipse.jetty.webapp.WebDescriptor.parse(WebDescriptor.java:143)
    at org.eclipse.jetty.webapp.MetaData.setWebXml(MetaData.java:165)
    at org.eclipse.jetty.webapp.WebXmlConfiguration.preConfigure(WebXmlConfiguration.java:55)
    at org.eclipse.jetty.webapp.WebAppContext.preConfigure(WebAppContext.java:417)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:453)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
    at org.mortbay.ijetty.deployer.AndroidWebAppDeployer.scan(AndroidWebAppDeployer.java:203)
    at org.mortbay.ijetty.deployer.AndroidWebAppDeployer.doStart(AndroidWebAppDeployer.java:63)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
    at org.eclipse.jetty.util.component.AggregateLifeCycle.doStart(AggregateLifeCycle.java:63)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:53)
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:91)
    at org.eclipse.jetty.server.Server.doStart(Server.java:263)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
    at org.mortbay.ijetty.IJettyService.startJetty(IJettyService.java:704)
    at org.mortbay.ijetty.IJettyService$JettyStarterThread.run(IJettyService.java:159)
    Caused by: java.util.zip.ZipException: Local File Header signature not found; was F0C75E71
    at java.util.zip.ZipFile.throwZipException(ZipFile.java:427)
    at java.util.zip.ZipFile.getInputStream(ZipFile.java:283)
    at java.util.jar.JarFile.getInputStream(JarFile.java:389)
    at libcore.net.url.JarURLConnectionImpl.getInputStream(JarURLConnectionImpl.java:222)
    at org.apache.harmony.xml.ExpatParser.openUrl(ExpatParser.java:753)
    ... 21 more

    上面说IO流出错,Test.war的WEB-INF目录下的web.xml文件无法打开,其实原因很简单,这里是因为程序没有读SD卡权限造成的,谷歌在安卓4.1后加入了读SD卡权限,刚好我使用的模拟器是4.4版本,而且刚好iJetty也没有加入读SD卡权限,所以会报错,所以加上读SD卡权限后,问题解决,完成!!!
    ————————————————
    版权声明:本文为CSDN博主「GitLqr」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/csdn_lqr/article/details/50917336

  • 相关阅读:
    Codeforces467C George and Job
    Codeforces205E Little Elephant and Furik and RubikLittle Elephant and Furik and Rubik
    Codeforce205C Little Elephant and Interval
    51nod1829 函数
    51nod1574 排列转换
    nowcoder35B 小AA的数列
    Codeforce893E Counting Arrays
    gym101612 Consonant Fencity
    CodeForces559C Gerald and Giant Chess
    CodeForces456D A Lot of Games
  • 原文地址:https://www.cnblogs.com/dogdogwang/p/12503294.html
Copyright © 2020-2023  润新知