我需要你帮忙。我在一个需要velocity库的EJB中工作,但是当我部署和运行EJB时,抛出了一个异常:java.lang.noClassDefoundError:org/apache/commons/collections/extendedProperties
我不明白为什么。当我直接在会话Bean中使用该类时,没有任何问题。但是当这个类从Velocity实例化时,我会收到异常
我尝试将库声明为直接依赖项。在Glassfish console configurating Libraries字段中部署EJB,得到相同的结果
服务器:GlassFish Server Open Source Edition 3.1.2.2(build 5)
SO:Windows 7
package test.mavenproject1;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Schedule;
import javax.ejb.Singleton;
import org.apache.commons.collections.ExtendedProperties;
import org.apache.velocity.app.VelocityEngine;
@Singleton
public class NewSessionBean {
@Schedule(hour = "*", minute = "*")
public void businessMethod() {
ExtendedProperties p = new ExtendedProperties();
p.addProperty("test", "A");
VelocityEngine ve = new VelocityEngine();
Logger.getLogger(NewSessionBean.class.getName()).log(Level.INFO, p.getString("test"));
}
}
和POM文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>mavenproject1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>ejb</packaging>
<name>mavenproject1</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
输出:
WARNING: javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5215)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5113)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4901)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2045)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1994)
at com.sun.ejb.containers.BaseContainer.callEJBTimeout(BaseContainer.java:4088)
at com.sun.ejb.containers.EJBTimerService.deliverTimeout(EJBTimerService.java:1832)
at com.sun.ejb.containers.EJBTimerService.access$100(EJBTimerService.java:108)
at com.sun.ejb.containers.EJBTimerService$TaskExpiredWork.run(EJBTimerService.java:2646)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/collections/ExtendedProperties
at org.apache.velocity.runtime.RuntimeInstance.<init>(RuntimeInstance.java:183)
at org.apache.velocity.app.VelocityEngine.<init>(VelocityEngine.java:60)
at test.mavenproject1.NewSessionBean.businessMethod(NewSessionBean.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5388)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundTimeout(SystemInterceptorProxy.java:149)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5360)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5348)
at com.sun.ejb.containers.BaseContainer.callEJBTimeout(BaseContainer.java:4058)
... 9 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.ExtendedProperties
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at com.sun.enterprise.v3.server.AppLibClassLoaderServiceImpl$URLClassFinder.findClass(AppLibClassLoaderServiceImpl.java:158)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 42 more
我发现问题可能是GlassFish的bug。我的项目是用Maven做的,如果我使用一个需要其他库的库,最后一个库中的类就找不到了。
解决方法是将jar库放入域库目录中,重新启动服务器,问题就不存在了。
对于我的示例,我下载了commons-collections和commons-lang,并将它们放在{domain-directory}/lib中
在此之后,我的ejb运行正常。
我在Docker有个Jenkins集装箱。 当我成功构建某个东西时,我希望将其部署到一个glassfish docker容器中。 https://docs.oracle.com/cd/e19798-01/821-1757/ghgmi/index.html https://github.com/jenkinsci/postbuildscript-plugin
我使用的是NetBeans 8.0.2、JDK1.8和Glassfish 4。我还使用了另一个配置,使用了NB 7.3.1、jdk 1.7和GF 3.1.2和相同的结果。 我正在创建一个新的Java EE项目,只有一个EJB模块。当我尝试部署EJB模块时,我得到以下错误: 这是服务器日志: 我已经证实了这个.罐子是存在的。我找遍了所有地方,也没有找到类似的东西。我能做什么?Netbeans、Jav
Netbeans和EJB是如何从部署到Glassfish的? Netbeans能够做到这一点,但如何在IDE之外实现这一点呢? 另见: 如果EJB模块依赖于其他一些jar文件,那么部署独立的EJB模块是不起作用的-这些jar文件被忽略并且没有部署到服务器上,这将导致EJB模块的ClassNotFound异常。类似的情况也在AppClient中。 这从来没有起过作用,这个问题从4.x NB早期版本就
错误: 类ModeloApp: 接口EventOfacade.java(第一行,它真的很大): 感谢任何帮助
所以这是我的问题。我正在努力将一个简单的maven应用程序部署到Glassfish服务器中,只是为了检查我的配置是否正确,以便进一步开发。我使用的是NetBeans IDE,但由于它提供的控制台日志很小,几乎无法读取,所以我尝试使用系统终端(我使用的是Fedora)。 我试图部署的应用程序由一个无状态EJB bean(名为DziekanatBean,当前不执行任何操作)和一个Maven POM项目
我对Java EE7/Spring还是新手,并试图解决以下问题。我使用GlassFish4.1和JDK1.8。 我在Eclipse中创建了一个测试项目(New Project->Spring Project->Simple Java),使用项目方面“Dynamic Web Module”、“Java”、“JavaScript”、“JavaServer Faces”,如下所示: UserServic