简体   繁体   English

Velocity中的“ NoClassDefFoundError”

[英]“NoClassDefFoundError” in Velocity


I use Velocity in Java project to generate source code. 我在Java项目中使用Velocity生成源代码。 I export the project as jar file to use it in an other project. 我将项目导出为jar文件,以便在其他项目中使用它。
This is my velocity properties file content: 这是我的速度属性文件的内容:
runtime.log.logsystem.class = org.apache.velocity.runtime.log.SystemLogChute runtime.log.logsystem.class = org.apache.velocity.runtime.log.SystemLogChute
resource.loader = resources/ resource.loader =资源/
classpath.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader classpath.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader

I get this error: 我收到此错误:
Internal compiler error: java.lang.NoClassDefFoundError: org/apache/velocity/exception/ResourceNotFoundException at java.lang.Class.getDeclaredConstructors0(Native Method) 内部编译器错误:java.lang.NoClassDefFoundError:java.lang.Class.getDeclaredConstructors0(本地方法)处的org / apache / velocity / exception / ResourceNotFoundException

That Class was present during build time but it depends upon environment, if you are working in J2EE environment than you can get NoClassDefFoundError even if class is present because it may not be visible to corresponding class loader. 该类在构建期间就存在,但是它取决于环境,如果您在J2EE环境中工作,则即使存在类也可以获取NoClassDefFoundError,因为相应的类加载器可能看不到该类。

Put all dependencies to WEB-INF/lib and add them to CLASSPATH . 将所有依赖项放入WEB-INF/lib并将它们添加到CLASSPATH

Where to Put the Velocity Jar 哪里放速度罐

First of all you have to decide whether you will use the dependency-free version 
 of velocity.jar or the version including all dependend jars. If you are not worried 
about collisions with Avalon Logkit, Commons Collections or Jakarta Oro, using the jar 
containing all dependencies is very convenient.

Putting the velocity jar in WEB-INF/lib your web application 
will result in it's classes being available in the classpath for that web application.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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