Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
506 views
in Technique[技术] by (71.8m points)

java servlet project and android library project in eclipse - NoClassDefFoundError

I have some projects in my workspace :

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

AndroidMonitoring (which depends on MonitoringModel,

in the Android section of the project properties)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:pathoWebContentWEB-INFlibmonitoringmodel.jar c:pathoinmonitoringmodel.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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...