예제 #1
0
  private void deployAll() throws GlassFishException {
    // deploy explicit wars first.
    int deploymentCount = 0;
    Deployer deployer = gf.getDeployer();
    if (deployments != null) {
      for (File war : deployments) {
        if (war.exists() && war.isFile() && war.canRead()) {
          deployer.deploy(war, "--availabilityenabled=true");
          deploymentCount++;
        } else {
          logger.log(Level.WARNING, "{0} is not a valid deployment", war.getAbsolutePath());
        }
      }
    }

    // deploy from deployment director
    if (deploymentRoot != null) {
      for (File war : deploymentRoot.listFiles()) {
        String warPath = war.getAbsolutePath();
        if (war.isFile()
            && war.canRead()
            && (warPath.endsWith(".war")
                || warPath.endsWith(".ear")
                || warPath.endsWith(".jar")
                || warPath.endsWith(".rar"))) {
          deployer.deploy(war, "--availabilityenabled=true");
          deploymentCount++;
        }
      }
    }
    logger.log(Level.INFO, "Deployed {0} wars", deploymentCount);
  }
예제 #2
0
  @Test
  public void test() throws Exception {

    GlassFishProperties props = new GlassFishProperties();
    props.setPort("http-listener", 8080);
    GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(props);
    glassfish.start();

    // Test Scattered Web Archive
    ScatteredArchive sa =
        new ScatteredArchive("cdi_ejb_jpa", ScatteredArchive.Type.WAR, new File("src/main/webapp"));
    sa.addClassPath(new File("target/classes"));
    sa.addClassPath(new File("src/main/resources"));
    URI warURI = sa.toURI();
    printContents(warURI);

    // Deploy archive
    Deployer deployer = glassfish.getDeployer();
    String appname = deployer.deploy(warURI);
    System.out.println("Deployed [" + appname + "]");
    Assert.assertEquals(appname, "cdi_ejb_jpa");

    // Now create a http listener and access the app.
    WebContainer webcontainer = glassfish.getService(WebContainer.class);
    HttpListener listener = new HttpListener();
    listener.setId("my-listener");
    listener.setPort(9090);
    webcontainer.addWebListener(listener);

    get(
        "http://localhost:8080/cdi_ejb_jpa/BasicCDITestServlet",
        "All CDI beans have been injected.");

    deployer.undeploy(appname);

    glassfish.dispose();
  }
예제 #3
0
  public static void main(String[] args) /* throws GlassFishException */ {
    logger.info(String.format("Launching %s...", APPLICATION_NAME));

    // Determine installation path
    File installationPath =
        new File(Launcher.class.getProtectionDomain().getCodeSource().getLocation().getPath());
    String installationDirectoryPath =
        (installationPath.isDirectory() ? installationPath : installationPath.getParentFile())
            .getAbsolutePath();

    logger.info(String.format("Installation directory path: %s", installationDirectoryPath));

    logger.info("Starting Java DB (Apache Derby)...");
    NetworkServerControl serverControl;
    try {
      serverControl = new NetworkServerControl(InetAddress.getByName("localhost"), 1527);
      serverControl.start(null);
    } catch (Exception e) {
      throw new RuntimeException("Cannot start Java DB (Apache Derby)!", e);
    }

    logger.info(String.format("Creating database %s...", DATABASE_NAME));
    String driver = "org.apache.derby.jdbc.ClientDriver";
    String connectionURL =
        "jdbc:derby:" + /* installationDirectoryPath + "\\" + */ DATABASE_NAME + ";create=true";
    Connection connection = null;
    try {
      Class.forName(driver);
    } catch (java.lang.ClassNotFoundException e) {
      throw new RuntimeException(e);
    }
    try {
      connection = DriverManager.getConnection(connectionURL);
    } catch (Throwable e) {
      throw new RuntimeException(e);
    } finally {
      try {
        connection.close();
      } catch (SQLException e) {
        // Ignore exception
      }
    }

    logger.info("Starting Oracle Glassfish Embedded and deploying application...");
    GlassFishProperties glassfishProperties = new GlassFishProperties();
    String configFilePath = installationDirectoryPath + "\\" + GLASSFISH_CONFIG_FILE_NAME;
    String configFileURI = new File(configFilePath).toURI().toString();
    logger.info(String.format("Configuration file URI: %s", configFileURI));
    glassfishProperties.setConfigFileURI(configFileURI);
    glassfishProperties.setConfigFileReadOnly(true);

    try {
      GlassFishRuntime glassfishRuntime = GlassFishRuntime.bootstrap();
      GlassFish glassfish = glassfishRuntime.newGlassFish(glassfishProperties);
      glassfish.start();

      // Deploy plenus Server package to GlassFish
      File applicationPackage =
          new File(installationDirectoryPath + "\\" + APPLICATION_PACKAGE_FILE_NAME);
      Deployer deployer = glassfish.getDeployer();
      deployer.deploy(
          applicationPackage); // Can be invoked instead the variant above because other parameters
                               // are optional.

      System.out.println(String.format("Press <<Enter>> to stop the %s...", APPLICATION_NAME));
      // Wait for <<Enter>>
      try {
        new BufferedReader(new java.io.InputStreamReader(System.in)).readLine();
      } catch (IOException e) {
        // Ignore exception
      }

      // Teardown GlassFish
      glassfish.dispose();
      glassfishRuntime.shutdown();
    } catch (GlassFishException e) {
      throw new RuntimeException("Glassfish error!", e);
    }

    logger.info("Stopping Java DB (Apache Derby)...");
    try {
      serverControl.shutdown();
    } catch (Exception e) {
      throw new RuntimeException("Cannot stop Java DB (Apache Derby)!", e);
    }
  }