java servlet项目和eclipse中的android库项目 - NoClassDefFoundError [英] java servlet project and android library project in eclipse - NoClassDefFoundError

查看:205
本文介绍了java servlet项目和eclipse中的android库项目 - NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作区有一些项目:

  AndroidMonitoring#一个android应用程序
MonitoringModel#一个android库项目
DataServlet#servlet project

AndroidMonitoring(依赖于MonitoringModel,





编译并运行正常,但我需要在DataServlet项目中也可以使用MonitoringModel类。我在DataServlet项目的Java Build路径中添加了Model作为依赖,但是我得到:

  java.lang.NoClassDefFoundError: gr / uoa / di / monitoring / model /电池
gr.uoa.di.monitoring.server.servlets.DataCollectionServlet.doGet(DataCollectionServlet.java:20)
javax.servlet.http.HttpServlet.service (HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

我需要模型是一个Android库项目,因为它包含android类 - 而且还包含解析servlet中的文件的方法 - 是可能吗?如何设置?



编辑:MonitoringModel是 here

解决方案

已解决


  1. 从DataServlet的java构建路径中删除依赖关系

  2. 转到 MonitoringModel 项目和删除库属性,将其作为Android应用程序运行,将其重新映像到库中(从此处清理MonitoringModel项目

  3. 从bin /中获取monitormodel.jar,并将其放入 DataServlet / WEB-INF / lib

  4. 刷新并在服务器上运行

  5. 完成

将尝试改进这个黑客(链接到外部jar似乎没有工作btw) - 任何更好的想法将被接受作为答案 - 但现在关闭这个。



编辑:显然步骤3.可以通过从 DataServlet / WEB-INF / lib / monitoringmodel.jar 创建一个硬连接替代为monitormodel.jar - 仍然将其作为一些操作序列进行测试打破链接。符号链接似乎不起作用 - 报告为错误



EDIT2 :以下步骤似乎也可以工作,但是我留下手动过程,因为它绝对有效


  1. 从DataServlet的java构建路径中删除依赖关系

  2. 将monitormodel.jar从bin /连接到code> DataServlet / WEB-INF / lib中。我使用shell链接扩展名,但是这样:

      mklink / H c:\path\to\WebContent\WEB- INF \lib\monitoringmodel.jar c:\path\to\bin\monitoringmodel.jar 

    也应该工作


  3. 现在每当您更改监控模型时,jar都会更新。您只需要刷新 servlet项目(默认情况下将自动重新部署在服务器上)



$ b $澄清:当然,servlet项目不是要使用 android。* 类 - 这不是我的问题 - 我的问题是让模型代码在一个地方,这个地方必须是一个Android库


I have some projects in my workspace :

AndroidMonitoring # an android application
MonitoringModel # an android library project
DataServlet # servlet project

AndroidMonitoring (which depends on MonitoringModel,

)

compiles and runs just fine but I need the MonitoringModel classes to be available also in the DataServlet project. I added the Model as a dependency in the Java Build path of the DataServlet project but I get :

java.lang.NoClassDefFoundError: gr/uoa/di/monitoring/model/Battery
    gr.uoa.di.monitoring.server.servlets.DataCollectionServlet.doGet(DataCollectionServlet.java:20)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

I need the Model to be an Android library project as it contains android classes - but also contains the methods to parse the files in the servlet - is it possible ? How should I set this up ?

EDIT : MonitoringModel is here

解决方案

Solved !

  1. remove the dependency from DataServlet's java build path
  2. go to the MonitoringModel project and remove the library attribute, run it as an Android app remake it into a library (from here) Clean the MonitoringModel project
  3. grab the monitoringmodel.jar from bin/ and drop it into the DataServlet/WEB-INF/lib
  4. refresh and run on server
  5. done !

Will try and improve on this hack (linking to an external jar did not seem to work btw) - any better ideas will be accepted as an answer - however closing this for now.

EDIT : apparently step 3. can be substituted by creating a hard link from DataServlet/WEB-INF/lib/monitoringmodel.jar to monitoringmodel.jar - still testing this as some action sequences break the link methinks. Symbolic links do not seem to work though - reported this as a bug

EDIT2 : the steps below seem to work too - but I leave the manual procedure as it definitely works

  1. remove the dependency from DataServlet's java build path
  2. Hard link the monitoringmodel.jar from bin/ and to the DataServlet/WEB-INF/lib. I used shell link extension but this :

    mklink /H c:\path\to\WebContent\WEB-INF\lib\monitoringmodel.jar c:\path\to\bin\monitoringmodel.jar
    

    should also work

  3. Now everytime you make a change in monitoring model the jar is updated. You only have to refresh the servlet project (will be redeployed on server on its own by default)

Clarification : of course the servlet project is not meant to use android.* classes - this was not my issue - my issue was to have the model code in one place and this place had to be an android library

这篇关于java servlet项目和eclipse中的android库项目 - NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆