classloader

this.getClass().getResource(“”).getPath() returns an incorrect path

白昼怎懂夜的黑 提交于 2019-12-04 09:34:27
问题 I am currently making a small simple Java program for my Computer Science Final, which needs to get the path of the current running class. The class files are in the C:\2013\game\ folder. To get this path, I call this code segment in my main class constructor: public game(){ String testPath = this.getClass().getResource("").getPath(); //Rest of game } However, this command instead returns this String: "/" despite the correct output being "C:/2013/game" Additionally, I attempted to rectify

Java ClassLoader and Dependency Resolution

时光总嘲笑我的痴心妄想 提交于 2019-12-04 08:50:54
Can someone clarify that the role of a ClassLoader is not only to load an individual class, but also its dependencies? And if so, what exactly does the entire process entail? I'm looking for implementation detail if at all possible. For example, at some point, bytes are going to have to be read in from somewhere (a network or filesystem location), and file system locations are going to have to be calculated on the basis of a classes canonical name and a foreknowledge of class paths available to the JVM- how does an individual ClassLoader try to locate a file over potentially multiple class

Load jar dynamically at runtime?

爷,独闯天下 提交于 2019-12-04 07:36:48
My current java project is using methods and variables from another project (same package). Right now the other project's jar has to be in the classpath to work correctly. My problem here is that the name of the jar can and will change because of increasing versions, and because you cannot use wildcards in the manifest classpath, it's impossible to add it to the classpath. So currently the only option of starting my application is using the -cp argument from the command line, manually adding the other jar my project depends on. To improve this, I wanted to load the jar dynamically and read

Get intent Class loader . I want to set text a textView in secondActivity to name of firstActivity (Actually I need class loader name)

好久不见. 提交于 2019-12-04 06:23:44
问题 In going from an activity to another one by an intent, How can I get class loader name ? I need name of class loader. If my intention wasn't clear, Please look at this codes. I created a test app for this Question. It has three activity. ActivityA , ActivityB and ActivityC. I have a button in ActivityA and ActivityB that start activityC. ActivityA: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_a); Button

Why does Class.getPackage return the same Package for classes from different packages?

蓝咒 提交于 2019-12-04 06:08:53
I make a new ClassLoader and make it define a new Class , which means that new class should be in a new namespace, which it is, AFAIK. The strange thing is, when I call Class.getPackage on the new class, it returns the exact same object as returned by calling getPackage on any other class in my main namespace. According to the JVM spec : The runtime package of a class or interface is determined by the package name and defining class loader of the class or interface. So in other words, if you have two classes in the same package, but are loaded by different classloaders, they are considered to

Using JavaCompiler in an OSGi Bundle

Deadly 提交于 2019-12-04 05:51:47
I'm in the process of refactoring a Java application to use OSGi. One feature of the application is on-the-fly Java compilation using javax.tools.JavaCompiler . In the original application this process worked by feeding the compiler the existing classpath, like so. JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); String[] options = {"-classpath", System.getProperty("java.class.path")}; DiagnosticListener<JavaFileObject> listener = new DiagnosticListener<JavaFileObject>() {...}; StandardJavaFileManager fileManager = compiler.getStandardFileManager(listener, null, null); Iterable<?

custom classLoader issue

流过昼夜 提交于 2019-12-04 05:21:39
问题 the problem is next: i took the base classLoader code from here. but my classLoader is specific from a point, that it must be able to load classes from a filesystem(let's take WinOS), so in classLoader must be some setAdditionalPath() method, which sets a path(a directory on a filesystem), from which we'll load class(only *.class, no jars). here is code, which modifies the loader from a link(you can see, that only loadClass is modified), but it doesn't work properly: public void

Make JVM use My Own Class Loader

拈花ヽ惹草 提交于 2019-12-04 04:49:57
I wrote my own class loader. I need all my classes to be loaded using my class loader. I have passed the VM the following: -Djava.system.class.loader=MyClassLoader Only the first referenced class in my package is being loaded using my class loader. Other classes in my package are being loaded using AppClassLoader . Here is what MyClassLoader looks like: import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Enumeration; public class MyClassLoader extends ClassLoader { public MyClassLoader() { super(MyClassLoader.class.getClassLoader()); } public

Autowiring classes from external jar with Spring

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 04:28:20
I'm trying to build a standalone application (not running inside an application server) with Spring and I'm facing the following problem : My standalone application (spring enabled) is depending on another project (bundled as a jar) which contains a lot of services in com.application.service (Annotated with @Service ). There is no spring related configuration in the external project and the standalone application context is very simple, it only contains : <context:component-scan base-package="com.application" /> Here is an example of Class that depends on a service which can't be acquired :

How to use ClassLoader.getResources() in jar file

无人久伴 提交于 2019-12-04 04:28:10
问题 Problem statement: I have a jar file with a set of configuration files in a package mycompany/configuration/file/ . I don't know the file names. My intention is to load the file names at runtime from the jar file in which they are packaged and then use it in my application. As far as I understood: When I use the ClassLoader.getResources("mycompany/configuration/file/") I should be getting all the configuration files as URLs. However, this is what is happening: I get one URL object with URL