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, @Nullable Class<?> clazz) 

Source Link

Document

Create a new ClassPathResource for Class usage.

Usage

From source file:org.arc4eclipse.panelExerciser.BindingListAndPanel.java

/**
 * Auto-generated main method to display this org.eclipse.swt.widgets.Composite inside a new Shell.
 * //from   ww  w  .  j a v  a 2 s  .  c om
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    URL resource = new ClassPathResource("log4j.xml", BindingListAndPanel.class).getURL();
    DOMConfigurator.configure(resource);
    IArc4EclipseRepository repository = IArc4EclipseRepository.Utils.repository();
    try {
        showGUI(repository);
    } finally {
        repository.shutdown();
    }
}

From source file:com.trigonic.utils.spring.cmdline.Grep.java

public static void main(String[] args) {
    ClassPathResource contextXml = new ClassPathResource("Grep-context.xml", Grep.class);
    new CommandLineAppContext(contextXml).run(Grep.class, args);
}

From source file:org.zalando.stups.clients.kio.spring.ResourceUtil.java

static Resource resource(final String resourcename) {
    return new ClassPathResource(resourcename + ".json", ResourceUtil.class);
}

From source file:test.util.TestResourceUtils.java

/**
 * Loads a {@link org.springframework.core.io.ClassPathResource} qualified by the simple name of clazz,
 * and relative to the package for clazz.
 * //from   w  ww  .j a  v  a2s  .co  m
 * <p>Example: given a clazz 'com.foo.BarTests' and a resourceSuffix of 'context.xml',
 * this method will return a ClassPathResource representing com/foo/BarTests-context.xml
 * 
 * <p>Intended for use loading context configuration XML files within JUnit tests.
 * 
 * @param clazz
 * @param resourceSuffix
 */
public static ClassPathResource qualifiedResource(Class<?> clazz, String resourceSuffix) {
    return new ClassPathResource(format("%s-%s", clazz.getSimpleName(), resourceSuffix), clazz);
}

From source file:com.lewisd.maven.lint.rules.opensource.OpensourceRulesIT.java

@BeforeClass
public static void beforeAllTest() {
    applicationContext = new GenericApplicationContext();
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    ClassPathResource classPathResource = new ClassPathResource(CONFIG_LOCATION, classLoader);
    XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(applicationContext);
    xmlBeanDefinitionReader.loadBeanDefinitions(classPathResource);

    applicationContext.getBeanFactory().registerSingleton("LOG", LOG);
    applicationContext.getBeanFactory().registerResolvableDependency(PluginParameterExpressionEvaluator.class,
            mock(PluginParameterExpressionEvaluator.class));
    applicationContext.refresh();//from  w  w  w  .j a  v  a2  s  .com
}

From source file:com.mymita.vaadlets.VaadletsBuilderTest.java

private static InputStreamReader reader(final String xmlFile) throws IOException {
    return new InputStreamReader(new ClassPathResource(xmlFile, VaadletsBuilderTest.class).getInputStream());
}

From source file:net.javacrumbs.springws.test.helper.DefaultStrategiesHelperFactory.java

public static DefaultStrategiesHelper getDefaultStrategiesHelper() {
    //should be MessageDispatcherServlet.class but it would require servlet-api in the classpath. So we use HttpTransportException instead.
    return new DefaultStrategiesHelper(
            new ClassPathResource(DEFAULT_STRATEGIES_PATH, HttpTransportException.class));
}

From source file:org.obiba.onyx.engine.StageManagerTest.java

@Test
public void testGetStages() throws Exception {
    StageManagerImpl stageManager = new StageManagerImpl();
    stageManager.setStageDescriptor(new ClassPathResource("testStages.xml", StageManagerTest.class));
    stageManager.afterPropertiesSet();/*w w w  . j a  v  a  2  s  .  c o  m*/

    List<Stage> stages = stageManager.getStages();
    Assert.assertNotNull(stages);
    Assert.assertEquals(6, stages.size());
    for (Stage stage : stages) {
        Assert.assertNotNull(stage.getName());
    }
}

From source file:com.opengamma.elsql.ElSqlBundle.java

/**
 * Loads external SQL based for the specified type.
 * <p>/*from  w ww  .  jav a 2  s . c  om*/
 * This will load a file from the same package, with the ".elsql" extension
 * followed by one with the suffix "-$ConfigName.elsql".
 * 
 * @param config  the config, not null
 * @param type  the type, not null
 * @return the bundle, not null
 * @throws IllegalArgumentException if the input cannot be parsed
 */
public static ElSqlBundle of(ElSqlConfig config, Class<?> type) {
    ArgumentChecker.notNull(config, "config");
    ArgumentChecker.notNull(type, "type");
    ClassPathResource baseResource = new ClassPathResource(type.getSimpleName() + ".elsql", type);
    ClassPathResource configResource = new ClassPathResource(
            type.getSimpleName() + "-" + config.getName() + ".elsql", type);
    return parse(config, baseResource, configResource);
}

From source file:org.projecthdata.social.api.RootTest.java

@Before
public void setUp() throws Exception {
    serializer = new Persister();
    source = new ClassPathResource("../resources/root.xml", getClass()).getFile();
    assertTrue(source.exists());/*  w  w w .j a v  a 2 s . c  o m*/
    root = serializer.read(Root.class, source);
    assertNotNull(root);
}