External project dependency in Vaadin

廉价感情. 提交于 2019-12-21 22:42:25

问题


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.


回答1:


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).




回答2:


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.

Check the content of the WEB-INF/lib directory under:
eclipse-workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\your_ project\WEB-INF\lib


回答3:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!