@Test public void testJavaArchiveFromClass() throws Throwable { JavaArchive archive = ShrinkWrapUtils.getJavaArchiveFromClass(Test.class); assertNotNull(archive.get("/org/junit/Test.class")); assertNotNull(archive.get("/org/junit/Ignore.class")); }
public static JavaArchive getJavaArchiveFromClass(Class<?> clazz) { URL url = clazz.getResource(clazz.getSimpleName() + ".class"); try { String file = url.getFile(); if (file.startsWith("file:")) { file = file.substring(file.indexOf(":") + 1); } file = file.substring(0, file.indexOf('!')); JavaArchive jar = ShrinkWrap.create(ZipImporter.class, file + "!").importFrom(new File(file)).as(JavaArchive.class); return jar; } catch (Exception e) { throw new IllegalStateException("Cannot get JAR from class " + clazz.getName() + " from URL " + url, e); } }
ShrinkWrapUtils { public static JavaArchive getJavaArchiveFromClass(Class<?> clazz) { URL url = clazz.getResource(clazz.getSimpleName() + ".class"); try { String file = url.getFile(); if (file.startsWith("file:")) { file = file.substring(file.indexOf(":") + 1); } file = file.substring(0, file.indexOf('!')); JavaArchive jar = ShrinkWrap.create(ZipImporter.class, file + "!").importFrom(new File(file)).as(JavaArchive.class); return jar; } catch (Exception e) { throw new IllegalStateException("Cannot get JAR from class " + clazz.getName() + " from URL " + url, e); } } }
ShrinkWrapUtils { public static JavaArchive getJavaArchiveFromClass(Class<?> clazz) { URL url = clazz.getResource(clazz.getSimpleName() + ".class"); try { String file = url.getFile(); if (file.startsWith("file:")) { file = file.substring(file.indexOf(":") + 1); } file = file.substring(0, file.indexOf('!')); JavaArchive jar = ShrinkWrap.create(ZipImporter.class, file + "!").importFrom(new File(file)).as(JavaArchive.class); return jar; } catch (Exception e) { throw new IllegalStateException("Cannot get JAR from class " + clazz.getName() + " from URL " + url, e); } }  }
ShrinkWrapUtils { public static JavaArchive getJavaArchiveFromClass(Class<?> clazz) { URL url = clazz.getResource(clazz.getSimpleName() + ".class"); try { String file = url.getFile(); if (file.startsWith("file:")) { file = file.substring(file.indexOf(":") + 1); } file = file.substring(0, file.indexOf('!')); JavaArchive jar = ShrinkWrap.create(ZipImporter.class, file + "!").importFrom(new File(file)).as(JavaArchive.class); return jar; } catch (Exception e) { throw new IllegalStateException("Cannot get JAR from class " + clazz.getName() + " from URL " + url, e); } }  static JavaArchive getJavaArchiveFromClass(Class<?> clazz); }
ShrinkWrapUtils { public static JavaArchive getJavaArchiveFromClass(Class<?> clazz) { URL url = clazz.getResource(clazz.getSimpleName() + ".class"); try { String file = url.getFile(); if (file.startsWith("file:")) { file = file.substring(file.indexOf(":") + 1); } file = file.substring(0, file.indexOf('!')); JavaArchive jar = ShrinkWrap.create(ZipImporter.class, file + "!").importFrom(new File(file)).as(JavaArchive.class); return jar; } catch (Exception e) { throw new IllegalStateException("Cannot get JAR from class " + clazz.getName() + " from URL " + url, e); } }  static JavaArchive getJavaArchiveFromClass(Class<?> clazz);  }