Example usage for java.io File pathSeparatorChar

List of usage examples for java.io File pathSeparatorChar

Introduction

In this page you can find the example usage for java.io File pathSeparatorChar.

Prototype

char pathSeparatorChar

To view the source code for java.io File pathSeparatorChar.

Click Source Link

Document

The system-dependent path-separator character.

Usage

From source file:ca.simplegames.micro.Micro.java

public Micro(String path, ServletContext servletContext, String userClassPaths) throws Exception {
    final File applicationPath = new File(path);
    final File webInfPath = new File(applicationPath, "WEB-INF");

    showBanner();/* w ww.jav  a  2 s.co  m*/

    site = new SiteContext(new MapContext<String>().with(Globals.SERVLET_CONTEXT, servletContext)
            .with(Globals.SERVLET_PATH_NAME, path).with(Globals.SERVLET_PATH, applicationPath)
            .with(Globals.WEB_INF_PATH, webInfPath));

    welcomeFile = site.getWelcomeFile();

    //initialize the classpath
    StringBuilder cp = new StringBuilder();
    if (new File(webInfPath, "/lib").exists()) {
        cp.append(webInfPath.toString()).append("/lib,");
    }

    if (new File(webInfPath, "/classes").exists()) {
        cp.append(webInfPath.toString()).append("/classes,");
    }

    if (StringUtils.isNotBlank(userClassPaths)) {
        cp.append(",").append(userClassPaths);
    }

    String resources = ClassUtils.configureClasspath(webInfPath.toString(),
            StringUtils.split(cp.toString(), "," + File.pathSeparatorChar));
    if (log.isDebugEnabled()) {
        log.info("classpath: " + resources);
    }
    configureBSF();

    site.loadApplication(webInfPath.getAbsolutePath() + "/config");
    // done with the init phase
    //log.info("\n");

    // Registers a new virtual-machine shutdown hook.
    // For more details, see:  http://goo.gl/L9k1YT
    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            shutdown();
        }
    });
}

From source file:ClassPath.java

/**
 * Checks for class path components in the following properties:
 * "java.class.path", "sun.boot.class.path", "java.ext.dirs"
 * /*from  w  ww. ja  va2  s .co m*/
 * @return class path as used by default by BCEL
 */
public static final String getClassPath() {
    String class_path = System.getProperty("java.class.path");
    String boot_path = System.getProperty("sun.boot.class.path");
    String ext_path = System.getProperty("java.ext.dirs");
    List list = new ArrayList();
    getPathComponents(class_path, list);
    getPathComponents(boot_path, list);
    List dirs = new ArrayList();
    getPathComponents(ext_path, dirs);
    for (Iterator e = dirs.iterator(); e.hasNext();) {
        File ext_dir = new File((String) e.next());
        String[] extensions = ext_dir.list(new FilenameFilter() {

            public boolean accept(File dir, String name) {
                name = name.toLowerCase(Locale.ENGLISH);
                return name.endsWith(".zip") || name.endsWith(".jar");
            }
        });
        if (extensions != null) {
            for (int i = 0; i < extensions.length; i++) {
                list.add(ext_dir.getPath() + File.separatorChar + extensions[i]);
            }
        }
    }
    StringBuffer buf = new StringBuffer();
    for (Iterator e = list.iterator(); e.hasNext();) {
        buf.append((String) e.next());
        if (e.hasNext()) {
            buf.append(File.pathSeparatorChar);
        }
    }
    return buf.toString().intern();
}

From source file:com.igormaznitsa.sciareto.preferences.FileHistoryManager.java

@Nonnull
private static String packToString(@Nonnull @MustNotContainNull final File[] files) {
    final StringBuilder result = new StringBuilder();
    for (final File f : files) {
        if (result.length() > 0) {
            result.append(File.pathSeparatorChar);
        }//from   w ww  .  j a v  a  2s.  c  om
        result.append(FilenameUtils.normalize(f.getAbsolutePath()));
    }
    return result.toString();
}

From source file:com.sleepcamel.ifdtoutils.MvnPluginMojo.java

private String fileToClass(File baseDirectory, File file) {
    String classFilePath = FilenameUtils.removeExtension(file.getPath()).replace(baseDirectory.getPath(), "")
            .substring(1);// ww w. ja v  a 2 s .c o  m
    String className = classFilePath.replace(File.separatorChar, '.');
    while (classFilePath.length() != className.length()) {
        classFilePath = className;
        className = classFilePath.replace(File.pathSeparatorChar, '.');
    }
    return className;
}

From source file:org.red5.server.war.MainServlet.java

/**
 * Main entry point for the Red5 Server as a war
 *//*  ww  w. java 2  s.  c  o m*/
// Notification that the web application is ready to process requests
public void contextInitialized(ServletContextEvent sce) {
    System.setProperty("red5.deployment.type", "war");

    if (null != servletContext) {
        return;
    }
    servletContext = sce.getServletContext();
    String prefix = servletContext.getRealPath("/");

    long time = System.currentTimeMillis();

    logger.info("RED5 Server (http://www.osflash.org/red5)");
    logger.info("Loading red5 global context from: " + red5Config);
    logger.info("Path: " + prefix);

    try {
        // Detect root of Red5 configuration and set as system property
        String root;
        String classpath = System.getProperty("java.class.path");
        File fp = new File(prefix + red5Config);
        fp = fp.getCanonicalFile();
        if (!fp.isFile()) {
            // Given file does not exist, search it on the classpath
            String[] paths = classpath.split(System.getProperty("path.separator"));
            for (String element : paths) {
                fp = new File(element + "/" + red5Config);
                fp = fp.getCanonicalFile();
                if (fp.isFile()) {
                    break;
                }
            }
        }
        if (!fp.isFile()) {
            throw new Exception(
                    "could not find configuration file " + red5Config + " on your classpath " + classpath);
        }

        root = fp.getAbsolutePath();
        root = root.replace('\\', '/');
        int idx = root.lastIndexOf('/');
        root = root.substring(0, idx);
        // update classpath
        System.setProperty("java.class.path",
                classpath + File.pathSeparatorChar + root + File.pathSeparatorChar + root + "/classes");
        logger.debug("New classpath: " + System.getProperty("java.class.path"));
        // set configuration root
        System.setProperty("red5.config_root", root);
        logger.info("Setting configuation root to " + root);

        // Setup system properties so they can be evaluated
        Properties props = new Properties();
        props.load(new FileInputStream(root + "/red5.properties"));
        for (Object o : props.keySet()) {
            String key = (String) o;
            if (StringUtils.isNotBlank(key)) {
                System.setProperty(key, props.getProperty(key));
            }
        }

        // Store root directory of Red5
        idx = root.lastIndexOf('/');
        root = root.substring(0, idx);
        if (System.getProperty("file.separator").equals("/")) {
            // Workaround for linux systems
            root = "/" + root;
        }
        System.setProperty("red5.root", root);
        logger.info("Setting Red5 root to " + root);

        Class contextClass = org.springframework.web.context.support.XmlWebApplicationContext.class;
        ConfigurableWebApplicationContext applicationContext = (ConfigurableWebApplicationContext) BeanUtils
                .instantiateClass(contextClass);

        String[] strArray = servletContext.getInitParameter(ContextLoader.CONFIG_LOCATION_PARAM)
                .split("[,\\s]");
        logger.info("Config location files: " + strArray.length);
        applicationContext.setConfigLocations(strArray);
        applicationContext.setServletContext(servletContext);
        applicationContext.refresh();

        // set web application context as an attribute of the servlet
        // context so that it may be located via Springs
        // WebApplicationContextUtils
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
                applicationContext);

        ConfigurableBeanFactory factory = applicationContext.getBeanFactory();
        // register default
        // add the context to the parent
        factory.registerSingleton("default.context", applicationContext);

    } catch (Throwable e) {
        logger.error("", e);
    }

    long startupIn = System.currentTimeMillis() - time;
    logger.info("Startup done in: " + startupIn + " ms");

}

From source file:ch.ivyteam.ivy.maven.AbstractProjectCompileMojo.java

private String getDependencyClasspath() {
    return StringUtils.join(
            getDependencies("jar").stream().map(jar -> jar.getAbsolutePath()).collect(Collectors.toList()),
            File.pathSeparatorChar);
}

From source file:ml.shifu.guagua.yarn.util.YarnUtils.java

/**
 * Populate the environment string map to be added to the environment vars in a remote execution container.
 * /*  w w  w .j  av  a 2s. co  m*/
 * @param env
 *            the map of env var values.
 * @param conf
 *            the Configuration to pull values from.
 */
public static void addLocalClasspathToEnv(final Map<String, String> env, final Configuration conf) {
    StringBuilder classPathEnv = new StringBuilder(Environment.CLASSPATH.$());

    // add current folder
    classPathEnv.append(File.pathSeparatorChar).append("./*");

    // add yarn app classpath
    for (String cpEntry : conf.getStrings(YarnConfiguration.YARN_APPLICATION_CLASSPATH,
            YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH)) {
        classPathEnv.append(File.pathSeparatorChar).append(cpEntry.trim());
    }

    for (String jar : conf.getStrings(MRJobConfig.MAPREDUCE_APPLICATION_CLASSPATH,
            org.apache.hadoop.util.StringUtils
                    .getStrings(MRJobConfig.DEFAULT_MAPREDUCE_APPLICATION_CLASSPATH))) {
        classPathEnv.append(File.pathSeparatorChar).append(jar.trim());
    }

    // add the runtime classpath needed for tests to work
    if (conf.getBoolean(YarnConfiguration.IS_MINI_YARN_CLUSTER, false)) {
        classPathEnv.append(File.pathSeparatorChar).append(Environment.CLASSPATH.$());
    }

    // add guagua app jar file
    String path = getFileName(conf.get(GuaguaYarnConstants.GUAGUA_YARN_APP_JAR));
    classPathEnv.append(GuaguaYarnConstants.CURRENT_DIR).append(path).append(File.pathSeparatorChar);

    // Any libraries we may have copied over?
    String libs = conf.get(GuaguaYarnConstants.GUAGUA_YARN_APP_LIB_JAR);
    if (StringUtils.isNotEmpty(libs)) {
        for (String jar : Splitter.on(GuaguaYarnConstants.GUAGUA_APP_LIBS_SEPERATOR).split(libs)) {
            classPathEnv.append(GuaguaYarnConstants.CURRENT_DIR).append(getFileName(jar.trim()))
                    .append(File.pathSeparatorChar);
        }
    }

    // add log4j
    classPathEnv.append(GuaguaYarnConstants.CURRENT_DIR).append(GuaguaYarnConstants.GUAGUA_LOG4J_PROPERTIES)
            .append(File.pathSeparatorChar);

    // add guagua-conf.xml
    classPathEnv.append(GuaguaYarnConstants.CURRENT_DIR).append(GuaguaYarnConstants.GUAGUA_CONF_FILE);

    env.put(Environment.CLASSPATH.toString(), classPathEnv.toString());
}

From source file:org.ebayopensource.turmeric.eclipse.typelibrary.codegen.model.TypeLibModelTransformer.java

private static String getXJCClassPath() throws CoreException, IOException {
    StringBuffer xjcClassPath = new StringBuffer("");
    for (IProject typeLibProject : WorkspaceUtil
            .getProjectsByNature(TypeLibraryProjectNature.getTypeLibraryNatureId())) {
        xjcClassPath.append(typeLibProject.getLocation().toFile().getCanonicalPath());
        xjcClassPath.append(File.pathSeparatorChar);
    }// w w  w  .  j a  v a  2s. c om
    return StringUtils.substringBeforeLast(xjcClassPath.toString(), File.pathSeparator);

}

From source file:hudson.remoting.Launcher.java

@Option(name = "-cp", aliases = "-classpath", metaVar = "PATH", usage = "add the given classpath elements to the system classloader.")
public void addClasspath(String pathList) throws Exception {
    Method $addURL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
    $addURL.setAccessible(true);/*www  .j  av a2  s.c om*/

    for (String token : pathList.split(File.pathSeparator))
        $addURL.invoke(ClassLoader.getSystemClassLoader(), new File(token).toURI().toURL());

    // fix up the system.class.path to pretend that those jar files
    // are given through CLASSPATH or something.
    // some tools like JAX-WS RI and Hadoop relies on this.
    System.setProperty("java.class.path",
            System.getProperty("java.class.path") + File.pathSeparatorChar + pathList);
}