Reputation: 4560
What I am trying to do is to load .class file (compiled class file) from jar as a resource stream. This try is made from inside JUnit test case.
Let me present some code for better understanding.
package org.jboss.shrinkwrap.impl.nio.file;
import org.jboss.shrinkwrap.api.asset.Asset;
public class FileStoreTestCase {
// (...)
@Test
public void usedSpace(){
final Class<?> classToAdd = Asset.class;
final String pathToClass = new StringBuilder(classToAdd.getName().replace('.', File.separatorChar)).append(
".class").toString();
final InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(pathToClass);
}
Problem is that in above code "in" variable is always null. Do you know why? And how I can get it to work?
Thanks for any input.
Upvotes: 0
Views: 229
Reputation: 583
Try with replace('.', '/') i.e. use '/' instead of File.separatorChar
Upvotes: 1