简体   繁体   中英

Eclipse: Not succeeding importing classes from another project

I wanted to use classes from another project, so I went on project -> properties -> Java Bulid path -> projects and add ed the project the classes are on. Eclipse recognized it, since it started to show the import option from those classes at the "warning" icon. But I'm still getting the erros NoClassDefFoundError and ClassNotFoundException from one of those classes, at the following message:

java.lang.NoClassDefFoundError: com/caelum/jdbc/modelo/Contato
    br.com.caelum.servlet.AdicionaContatoServlet.service(AdicionaContatoServlet.java:50)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

java.lang.ClassNotFoundException: com.caelum.jdbc.modelo.Contato
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305)
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1157)
    br.com.caelum.servlet.AdicionaContatoServlet.service(AdicionaContatoServlet.java:50)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

It's not complaining about other class that I use from the other mentioned project, the problem seems to be only at the class Contato that I instantiate at the line 50 of AdicionaContatoServlet .

It means the class AdicionaContatoServlet requires the class com.caelum.jdbc.modelo.Contato.

You have to search for the class com.caelum.jdbc.modelo.Contato, you can Google it, and then add it to your workspace.

I am not sure if this one will work for yours or not, you can try it https://github.com/dronan/fj21-jdbc/blob/master/src/br/com/caelum/jdbc/modelo/Contato.java .

If only Contato.java does not work, you may need to download all the source code from the project above and add it to your workspace as another project.

At last, you may need to change the package name for the above project by removing "br." and you will get exact the same missing package name and class. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM