Java Code Examples for org.apache.commons.lang3.SystemUtils#JAVA_HOME

The following examples show how to use org.apache.commons.lang3.SystemUtils#JAVA_HOME . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JarUtilsTest.java    From confucius-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testResolveJarAbsolutePath() throws Exception {
    URL resourceURL = ClassLoaderUtils.getClassResource(classLoader, String.class);
    String jarAbsolutePath = JarUtils.resolveJarAbsolutePath(resourceURL);
    File rtJarFile = new File(SystemUtils.JAVA_HOME, "/lib/rt.jar");
    Assert.assertNotNull(jarAbsolutePath);
    Assert.assertEquals(rtJarFile.getAbsolutePath(), jarAbsolutePath);
}
 
Example 2
Source File: JarUtilsTest.java    From confucius-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testToJarFile() throws Exception {
    URL resourceURL = ClassLoaderUtils.getClassResource(classLoader, String.class);
    JarFile jarFile = JarUtils.toJarFile(resourceURL);
    JarFile rtJarFile = new JarFile(new File(SystemUtils.JAVA_HOME, "/lib/rt.jar"));
    Assert.assertNotNull(jarFile);
    Assert.assertEquals(rtJarFile.getName(), jarFile.getName());
}
 
Example 3
Source File: URLUtilsTest.java    From confucius-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testResolveRelativePath() throws MalformedURLException {
    ClassLoader classLoader = ClassLoader.getSystemClassLoader();
    URL resourceURL = ClassLoaderUtils.getClassResource(classLoader, String.class);
    String expectedPath = "java/lang/String.class";
    String relativePath = URLUtils.resolveRelativePath(resourceURL);
    Assert.assertEquals(expectedPath, relativePath);

    File rtJarFile = new File(SystemUtils.JAVA_HOME, "lib/rt.jar");
    resourceURL = rtJarFile.toURI().toURL();
    relativePath = URLUtils.resolveRelativePath(resourceURL);
    Assert.assertNull(relativePath);

}
 
Example 4
Source File: SimpleFileScannerTest.java    From confucius-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testScan() {
    File jarHome = new File(SystemUtils.JAVA_HOME);
    Set<File> directories = simpleFileScanner.scan(jarHome, true, DirectoryFileFilter.INSTANCE);
    Assert.assertFalse(directories.isEmpty());

    directories = simpleFileScanner.scan(jarHome, false, new NameFileFilter("bin"));
    Assert.assertEquals(1, directories.size());
}