如何将另一个类添加到Arquillian部署档案中? [英] How to add classes from another to the Arquillian deployment archive?

查看:204
本文介绍了如何将另一个类添加到Arquillian部署档案中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用Arquillian并按照教程进行操作。它介绍了如何将EJB注入测试用例。由于Arquillian的目标是Java Web和EE项目,因此我很惊讶实体类和EJB接口的分离在本教程中没有涉及,因为至少EE项目中所有内容都被丢弃在一个项目中很少。

I'm getting started with Arquillian and followed the tutorial. It covers how to inject EJBs into a test case. Since Arquillian is targeting Java Web and EE projects, I'm very suprised that the separation of entity classes and EJB interfaces wasn't covered in the tutorial since at least EE projects where everything is dumped in one project are rare.

由于教程中没有任何内容,任何EE容器都没有可理解的错误消息,我设法通过反复试验提取了一个测试用例,其中显示了

Since there's no coverage in the tutorial and no understandable error message by any of the EE containers, I managed to extract a test case by trial and error which shows that classes used in

@Deployment
public static JavaArchive createDeployment() {
    return ShrinkWrap.create(JavaArchive.class)
        .addClasses(MyXBean.class, DefaultMyXBean.class, TermsOfUse.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}

这些是在类路径上,但不在同一个Maven项目中的测试包含在中,由于 NoClassDefFoundError 而失败。将类移动到项目中而不触及任何其他内容会使部署工作。

which are on the classpath, but not in the same Maven project the test in contained in, fail due to NoClassDefFoundError. Moving the class into the project without touching anything else makes the deployment work.

有没有办法在实际Java EE中使用Arquillian,其中实体和接口是不包含在测试的 .war 中,但是作为 .ear 存档中的兄弟c $ c> .war

Is there any way to use Arquillian in a "real" Java EE in which entities and interfaces are not contained into the .war of the test, but as a sibling inside the parent .ear archive of the .war?

我可以考虑使用硬编码的pathes从Maven缓存中添加JAR,但这不可能是,可以吗?

I could think of adding JARs from the Maven cache with hardcoded pathes, but that can't be it, can it?

如何使用Arquillian maven多项目进行Java ee测试可能存在同样的问题。

How test in Java ee using Arquillian maven multiple project might be about the same issue.

推荐答案

可以像这样构建具有库的EAR部署:

An EAR deployment with libraries can be built like this:

@Deployment
public static Archive<?> createDeploymentPackage() throws IOException {
    MavenDependencyResolver resolver = DependencyResolvers  
         .use(MavenDependencyResolver.class)  
         .loadMetadataFromPom("test1-pom.xml");  

    final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "my-ejbs.jar").addClass(SomeEjb.class);

    final WebArchive webApp = ShrinkWrap.create(WebArchive.class, "my-webap.war").addClass(MyServlet.class);
    final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class)
            .setApplicationXML("application.xml")
            .addAsLibraries(resolver.artifact("log4j:log4j:1.2.17").resolveAsFiles()) 
            .addAsModule(ejbJar)
            .addAsModule(webApp);
    return ear;
}

这篇关于如何将另一个类添加到Arquillian部署档案中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆