I have a Vaadin project and an external Java project. I would like call code in the external project from Vaadin. I have both project imported in Eclipse and the Vaadin project references the external one in Eclipse Java Build Path
. Eclipse reports no error but when I deploy the Vaadin application to Tomcat (using Project > Run As > Run on Server
), I get the following error:
HTTP Status 500 - java.lang.NoClassDefFoundError: com/example/MyClass
Note that the Vaadin project is based on Ivy, not Maven.
I've tried searching around for Vaadin external project dependencies with no success. I'll be thankful for any suggestions on how to use the external project's code from Vaadin.
The solution was to add the external projects to the classpath of the Tomcat instance in Eclipse. Select
Run > Run Configurations > Apache Tomcat > (your Tomcat instance) > Classpath
Click Add Projects...
and add the required project.
This will work for development. For deployment, the external project must be packaged as a library to a .jar file and copied manually (or using a build script) to WEB-INF/lib
directory of the Vaadin project (see this answer on the Vaadin forum).
Another solution which will deploy your dependencies directly in the WEB-INF/lib
is to :
- Add your external project to the Project / Java Build Path / Projects
- Add your external project libraries (assumed to be Maven here) to the Project / Java Build Path / Libraries
Click on Add Variable / M2_REPO
and click on Extend
to select the right library.
This part can be painful if you depend on many libraries.
- Add your external project and java build path entries in the Project / Deployment Assembly
panel.
- Restart your Tomcat instance.
WEB-INF/lib
directory under:eclipse-workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\your_ project\WEB-INF\lib
Take your external project and export it as a jar. Then copy your new jar and any dependencies into the WEB-INF/lib directory of your vaadin project. This will work in a deployment as well as development environment.
来源:https://stackoverflow.com/questions/16569069/external-project-dependency-in-vaadin