classloader

Adding MarvinFramework to a WebApp on Tomcat7

南笙酒味 提交于 2019-12-01 11:14:17
I have a Jersey WebApp running on Tomcat and want to integrate the MarvinFramework for ImageProcessing. Basically I want to reduce noise, grayscale and scale an Image for further processing. The Marvin Framework relies on custom Plugins for their specific prupose, and those Plugins I want to use. But since the Framwork has its own ClassLoader , that loads the plugins JAR dynamically at runtime from an absolute location inside the project, I am confused where to put the files or how to configure the WebApp, that the ClassLoader is able load the JARs. I recreated the directory-structure for

Spring ApplicationContext with multiple XML Files from Jar

馋奶兔 提交于 2019-12-01 11:14:04
I need to create a ApplicationContext with the "main" applicationContext-a.xml from the current Maven build. The other one wires classes from another maven build and is preset in the jar included by a Maven Dependency. Here the idea: ApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "classpath*:applicationContext-*.xml"}); This should load applicationContext-a.xml from the Classpath because it's in the same Project. This works. Then applicationContext-b.xml should be loaded from the dependency-jar. This doesn't work. Note that "classpath*:applicationContext-*.xml"

this.getClass().getClassLoader().getResourceAsStream always returning null

一个人想着一个人 提交于 2019-12-01 11:05:56
While reading a file in a web application with this.getClass().getClassLoader().getResourceAsStream(../abc.txt) is always returning null. Can anyone please provide details where should I put abc.txt in order to read. And any article on getResourceAsStream will be helpful. I have searched a lot but did not get any relevant information. Please provide your valuable suggestions. Thanks. If your abc.txt is in classpath and in different package like com/test/oops/testpaper/abc.txt . Then read it like below. InputStream io=this.getClass().getClassLoader().getResourceAsStream("com/test/oops/testpaper

Create class with javassist and make it available

浪尽此生 提交于 2019-12-01 11:02:35
问题 I want to do the following: try { Class.forName("MyClass"); } catch(ClassNotFoundException e) { ClassPool pool = ClassPool.getDefault(); CtClass cc = pool.makeClass("MyClass"); Class.forName("MyClass"); } I have tried it, but it doesn't seem to work always... It works in one context, but in the other the same code is crashing on the second "Class.forName("MyClass")"... Calling cc.toClass() always brings the correct class, and have tried cc.writeFile() but it makes no difference. Somehow, in

I use load time weaving in spring. How can i set class loader in jetty?

痴心易碎 提交于 2019-12-01 10:53:01
I use load time weaving in spring. All works fine with websphere, because it has own class loader, but i have troubles in dev mode, where i use embedded jetty. How can i set class loader in jetty? When i run it i see following error [INFO] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.weaving.AspectJWeavingEnabler#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadTimeWeaver': Instantiation of bean failed; nested exception is org

How can I locate a non-Java resource in a WAR at runtime?

拟墨画扇 提交于 2019-12-01 09:25:14
I need to run a shell script at runtime from a WAR that I run on Tomcat. Thus, I've placed my script theScript.sh in my src/main/resources directory (because, yes, I use Maven). This directory is in the classpath, I've checked it. In the code, I want to copy my script in a temp directory. So I've tried to get it via my ClassLoader: URL myURL = ClassLoader.getSystemResource("theScript.sh"); if (myURL == null) { LOG.error("Couldn't find the resource"); } And guess what? Yes, the "Couldn't find the resource" keeps appearing all over the place in my logs. Any idea what I'm doing wrong here? My

Can a loaded JAR be deleted by the Java-Process?

荒凉一梦 提交于 2019-12-01 09:24:24
Hello I have following Problem: Within an uninstall-process I load a JAR (jdbc-driver). URL pDriverJar = jarToDelete.toURI().toURL(); URL[] lURLList = new URL[]{pDriverJar}; URLClassLoader lLoader = new URLClassLoader(lURLList, Thread.currentThread().getContextClassLoader()); Thread.currentThread().setContextClassLoader(lLoader); Class<?> aClass = Class.forName("jdbc.Driver"); // was Oracle: oracle.jdbc.OracleDriver but should not be important if(jarToDelete.delete()){ System.out.println("deleted"); }else { jarToDelete.deleteOnExit(); } After terminiation of the JVM, the jar is still existant.

PMD rule “Use Proper Class Loader” explaination?

五迷三道 提交于 2019-12-01 09:16:57
There is the following PMD rule: Use Proper Class Loader (Critical) In J2EE getClassLoader() might not work as expected. Use Thread.currentThread().getContextClassLoader() instead. Can somewhat explain more what they are thinking of? What exactly means "J2EE" environment here? J2EE environment refers to the Java Enterprise Edition. Here, you do not run your program as a standalone application on the JVM, but instead, you let the JEE Application Server (e.g. Glassfish or Tomcat) to run it for you. Application Servers provide a lot of different ways to run your program, for example they offer

JIMFS not recognized by ZipFileSystemProvider

▼魔方 西西 提交于 2019-12-01 09:14:04
I have a zip file created in jimfs (google in memory file system) from a byte array. When trying to open that file with ZipMemoryFileSystem , I get an error that the provider is not recognized. My code is as following: public static void test(byte[] document) { try { try (FileSystem memoryFileSystem = Jimfs.newFileSystem(Configuration.unix())) { Files.write(memoryFileSystem.getPath("/file.zip"), document); URI uri = URI.create("jar:" + memoryFileSystem.getPath("/file.zip").toUri()); Map<String, String> env = Collections.singletonMap("create", "false"); try (FileSystem zipfs = FileSystems

I use load time weaving in spring. How can i set class loader in jetty?

99封情书 提交于 2019-12-01 08:50:34
问题 I use load time weaving in spring. All works fine with websphere, because it has own class loader, but i have troubles in dev mode, where i use embedded jetty. How can i set class loader in jetty? When i run it i see following error [INFO] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.weaving.AspectJWeavingEnabler#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: