簡體   English   中英

Arquillian不在JBOSS中部署war文件夾

[英]Arquillian not deploy war folder in JBOSS

我正在使用JBoss EAP 6.1開發Java EE應用程序。

使用Arquillian運行測試我在使用測試中注入的方法時總是有一個空指針異常,我發現ShrinkWrap不能用我的類創建war文件夾。

這是我的Arquillian收縮包裝,不會創建war文件夾。

@Deployment(name = "Test")
@OverProtocol("Servlet 3.0")
public static Archive<?> createDeployment() {

    WebArchive archive = ShrinkWrap
            .create(WebArchive.class, "test_archive.war")
            .addClass(ArquillianTest.class)
            .addPackages(true, "it.payroll.model")
            .addPackages(true, "it.payroll.dao")
            .addPackages(true, "it.payroll.controller")
            .addAsResource("META-INF/persistence.xml")
            .addAsWebInfResource(EmptyAsset.INSTANCE,
                    ArchivePaths.create("beans.xml"));

    archive.as(ZipExporter.class).exportTo(
            new File("target/test_archive.war"), true);

    return archive;
}

謝謝你的幫助。

一個工作文件

@ArquillianSuiteDeployment
public class ArquillianDeploymentHelper {

public static final String DEPLOYMENT_NAME = "test";

private static final Logger LOGGER = LoggerFactory.getLogger(ArquillianDeploymentHelper.class);

private static final String WEBAPP_SRC = "src/main/webapp";
private static final String TEST_RESOURCES_SRC = "src/test/resources";
private static final String POM_FILE = "pom.xml";
private static final String ARCHIVE_NAME = "arquillian-test.war";

@Deployment(name = DEPLOYMENT_NAME)
public static Archive<?> generateDefaultDeployment() {

    // Generate the default WAR used by all *IT tests using @OperateOnDeployment("test") annotation
    LOGGER.info("Generating " + ARCHIVE_NAME + " archive ...");

    PomEquippedResolveStage pom = Maven.resolver().loadPomFromFile(POM_FILE);
    ScopeType[] scopes = {ScopeType.COMPILE, ScopeType.IMPORT, ScopeType.TEST}; // no SYSTEM and no PROVIDED
    File[] libs = pom.importDependencies(scopes).resolve().using(TransitiveStrategy.INSTANCE).asFile();

    WebArchive archive =  ShrinkWrap.create(WebArchive.class, ARCHIVE_NAME)
            .addAsLibraries(libs)
            //.addAsResource(new File(TEST_RESOURCES_SRC, "test-configuration.properties"), "configuration.properties")
            .addPackages(true, "com.test")
            //.addAsWebInfResource(new File(WEBAPP_SRC, "WEB-INF/web.xml"))
            .addAsWebInfResource(new File(WEBAPP_SRC, "WEB-INF/beans.xml"))
            .addAsWebInfResource(new File(WEBAPP_SRC, "WEB-INF/jboss-web.xml"))
            .addAsWebInfResource(new File(TEST_RESOURCES_SRC, "persistence.xml"), "classes/META-INF/persistence.xml");
            //.addAsManifestResource(new File(WEBAPP_SRC, "META-INF/jboss-deployment-structure.xml"));

    // No need to log the content anymore, the archive is kept in target directory 
    // "deploymentExportPath" variable in arquillian.xml
    // LOGGER.info(archive.toString(true));

    LOGGER.info(archive.toString(true));

    return archive;
}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM