0

我有 Wildfly swarm 应用程序,它有 App 类、容器和部署以及外观,一切正常,但是当我将 UserFacades 更改为另一个包并与运行应用程序的 App 主类分离时,部署失败!

导入 org.wildfly.swarm.Swarm;

public class App {

    public static void main(String[] args) throws Exception {

        MyContainer.newContainer()
                .start()
                .deploy(MyDeployment.createDeployment());

    }


public class MyContainer {

    private static final String MYSQL_OPTIONS = "autoReconnect=true&useSSL=false&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";

    public static Container newContainer() throws Exception {
        Container container = new Container();

        container.fraction(new DatasourcesFraction()
                .jdbcDriver("mysql", (d) -> {
                    d.driverClassName("com.mysql.jdbc.Driver");
                    d.xaDatasourceClass("com.mysql.jdbc.jdbc2.optional.MysqlXADataSource");
                    d.driverModuleName("com.mysql");
                })
                .dataSource("MyDS", (ds) -> {
                    ds.driverName("mysql");
                    ds.connectionUrl("jdbc:mysql://localhost:3306/tfm?" + MYSQL_OPTIONS);
                    ds.userName("root");
                    ds.password("root");
                })
        );

        container.fraction(new MySQLJPAFraction()
                .inhibitDefaultDatasource()
                .defaultDatasource("jboss/datasources/MyDS")
        );

        return container;
    }

public class MyDeployment {

  public static JAXRSArchive createDeployment() throws Exception {
    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);

    deployment.addPackage(App.class.getPackage());
    deployment.addAsWebInfResource(
        new ClassLoaderAsset("META-INF/persistence.xml", App.class.getClassLoader()), "classes/META-INF/persistence.xml");
    deployment.addAsWebInfResource(
        new ClassLoaderAsset("META-INF/load.sql", App.class.getClassLoader()), "classes/META-INF/load.sql");

      return deployment;
  }
}


2016-10-19 01:12:17,308 ERROR [stderr] (main)     Caused by: java.lang.NoClassDefFoundError: Lcom/project/backend/facades/UserFacade;
2016-10-19 01:12:17,309 ERROR [stderr] (main)     Caused by: java.lang.ClassNotFoundException: com.project.backend.facades.UserFacade from [Module \"deployment.082daa7c-bb37-4a26-9740-29e7de1da93b.war:main\" from Service Module Loader]"}}

2016-10-19 01:12:17,309 ERROR [stderr] (main)   at org.wildfly.swarm.container.runtime.RuntimeDeployer.deploy(RuntimeDeployer.java:159)

2016-10-19 01:12:17,310 ERROR [stderr] (main)   at org.wildfly.swarm.container.Container.deploy(Container.java:432)

2016-10-19 01:12:17,310 ERROR [stderr] (main)   at org.wildfly.swarm.Swarm.deploy(Swarm.java:122)

2016-10-19 01:12:17,310 ERROR [stderr] (main)   at com.project.backend.App.main(App.java:15)

有什么问题?如何设置主 App 类以扫描所有包?

4

1 回答 1

0

哦,我错过了将新包添加到部署类:(deployment.addPackage("com.myproject.facades");

于 2016-10-18T21:36:36.813 回答