Example usage for org.springframework.core.io ClassPathResource ClassPathResource

List of usage examples for org.springframework.core.io ClassPathResource ClassPathResource

Introduction

In this page you can find the example usage for org.springframework.core.io ClassPathResource ClassPathResource.

Prototype

public ClassPathResource(String path) 

Source Link

Document

Create a new ClassPathResource for ClassLoader usage.

Usage

From source file:org.haedus.datatypes.phonetic.SegmenterTest.java

@BeforeClass
public static void init() throws IOException {
    Resource resource = new ClassPathResource("featuremodel");
    model = new FeatureModel(resource.getFile());
}

From source file:se.inera.intyg.intygstjanst.web.integration.util.SendMessageToCareUtil.java

public static SendMessageToCareType getSendMessageToCareTypeFromFile(String fileName) throws Exception {
    JAXBContext jaxbContext = JAXBContext.newInstance(SendMessageToCareType.class);
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    return unmarshaller.unmarshal(new StreamSource(new ClassPathResource(fileName).getInputStream()),
            SendMessageToCareType.class).getValue();
}

From source file:biz.c24.io.spring.integration.test.TestUtils.java

public static byte[] loadXmlBytes() throws Exception {

    ClassPathResource resource = new ClassPathResource("valid-XML-1.xml");
    byte[] valid1 = FileCopyUtils.copyToByteArray(resource.getInputStream());

    return valid1;
}

From source file:ru.mystamps.web.config.TestContext.java

@Bean
public static PropertySourcesPlaceholderConfigurer getPropertySourcesPlaceholderConfigurer() {
    PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
    configurer.setLocations(new ClassPathResource("test/spring/test-data.properties"),
            new ClassPathResource("ru/mystamps/i18n/MailTemplates.properties"));
    return configurer;
}

From source file:com.eventattend.portal.Factory.LoginFactory.java

public static LoginController isUserExist() throws Exception {
    ClassPathResource resource = new ClassPathResource("BusinessObjectFactory.xml");
    BeanFactory factory = new XmlBeanFactory(resource);
    return (LoginController) factory.getBean("checkUser");
}

From source file:com.loy.MicroServiceConsole.java

@SuppressWarnings("rawtypes")
static void init() {

    ClassPathResource classPathResource = new ClassPathResource("application.yml");
    Yaml yaml = new Yaml();
    Map result = null;/*from w  w  w .j  a va2  s  . c  o m*/
    try {
        result = (Map) yaml.load(classPathResource.getInputStream());
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    String platformStr = result.get("platform").toString();
    String version = result.get("version").toString();
    String jvmOption = result.get("jvmOption").toString();
    @SuppressWarnings("unchecked")
    List<String> projects = (List<String>) result.get("projects");
    platform = Platform.valueOf(platformStr);

    final Runtime runtime = Runtime.getRuntime();
    File pidsForder = new File("./pids");
    if (!pidsForder.exists()) {
        pidsForder.mkdir();
    } else {
        File[] files = pidsForder.listFiles();
        if (files != null) {
            for (File f : files) {
                f.deleteOnExit();
                String pidStr = f.getName();
                try {
                    Long pid = new Long(pidStr);
                    if (Processes.isProcessRunning(platform, pid)) {
                        if (Platform.Windows == platform) {
                            Processes.tryKillProcess(null, platform, new NullProcessor(), pid);
                        } else {
                            Processes.killProcess(null, platform, new NullProcessor(), pid);
                        }

                    }
                } catch (Exception ex) {
                }
            }
        }
    }

    File currentForder = new File("");
    String root = currentForder.getAbsolutePath();
    root = root.replace(File.separator + "build" + File.separator + "libs", "");
    root = root.replace(File.separator + "e-example-ms-start", "");
    final String rootPath = root;
    new Thread(new Runnable() {
        @Override
        public void run() {
            int size = projects.size();
            int index = 1;
            for (String value : projects) {
                String path = value;
                String[] values = value.split("/");
                value = values[values.length - 1];
                value = rootPath + "/" + path + "/build/libs/" + value + "-" + version + ".jar";
                final String command = value;
                try {
                    Process process = runtime
                            .exec("java " + jvmOption + " -Dfile.encoding=UTF-8 -jar " + command);
                    Long pid = Processes.processId(process);
                    pids.add(pid);
                    File pidsFile = new File("./pids", pid.toString());
                    pidsFile.createNewFile();
                    new WriteLogThread(process.getInputStream()).start();

                } catch (IOException e) {
                    e.printStackTrace();
                }
                synchronized (lock) {
                    try {
                        if (index < size) {
                            lock.wait();
                        } else {
                            index++;
                        }

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }).start();
}

From source file:org.ligoj.app.plugin.prov.aws.in.CsvForBeanEc2Test.java

@Test
public void readNotCompute() throws IOException {
    final BufferedReader reader = new BufferedReader(new InputStreamReader(
            new ClassPathResource("mock-server/aws/index-small-not-compute.csv").getInputStream()));
    Assertions.assertNull(new CsvForBeanEc2(reader).read());
}

From source file:com.eventattend.portal.Factory.UserFactory.java

public static UserController updateUserAccountSettings() throws Exception {
    ClassPathResource resource = new ClassPathResource("BusinessObjectFactory.xml");
    BeanFactory factory = new XmlBeanFactory(resource);
    return (UserController) factory.getBean("User");
}

From source file:eu.freme.common.starter.FREMEStarter.java

/**
 * Start FREME package from XML configuration file.
 * //from  w ww .  j  a  va 2 s.  com
 * @param packagePath Path to the xml configuration file.
 * @param args Command line arguments passed to the spring application context.
 * @return
 */
public static ConfigurableApplicationContext startPackageFromClasspath(String packagePath, String[] args) {
    ClassPathResource config = new ClassPathResource(packagePath);
    return SpringApplication.run(config, args);
}

From source file:com.aspose.showcase.qrcodegen.web.config.AppConfigProperties.java

@Bean
public PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
    PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer();
    propertyPlaceholderConfigurer.setLocation(new ClassPathResource("config.properties"));
    // Allow for other PropertyPlaceholderConfigurer instances.
    propertyPlaceholderConfigurer.setIgnoreUnresolvablePlaceholders(true);
    return propertyPlaceholderConfigurer;
}