Dynamic loading java classes in terminal - java

The application is modular plug-in architecture. That is, while the work is done dynamically load classes. For this purpose a custom class loader extends ClassLoader.
The essence of the problem is that in Eclipse application runs, while in terminal (ubuntu) using the following line of code (where the Catalog "m /" indicates the location of the modules * .class):
java -jar ModularApp.jar m/
I get the following message:
10:07:24,085 DEBUG main CModuleLoader:findClass:39 - Run of the System Classloader.
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606) at
org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.NoClassDefFoundError: ru/intetech/module/CModule
at java.lang.ClassLoader.defineClass1(Native Method) at
java.lang.ClassLoader.defineClass(ClassLoader.java:800) at
java.lang.ClassLoader.defineClass(ClassLoader.java:643) at
ru.intetech.moduleloader.CModuleLoader.findClass(CModuleLoader.java:35)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at
java.lang.ClassLoader.loadClass(ClassLoader.java:358) at
ru.intetech.modularApp.Main.main(Main.java:42) ... 5 more Caused by:
java.lang.ClassNotFoundException: ru.intetech.module.CModule at
java.lang.ClassLoader.findClass(ClassLoader.java:531) at
ru.intetech.moduleloader.CModuleLoader.findClass(CModuleLoader.java:40)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at
java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 12 more
Here's a snippet of code, the user class loader (extending ClassLoader), where there is an error:
protected Class<?> findClass(String className) throws ClassNotFoundException
{
try
{
byte b[]=getClassAsBytes(m_pathToBin+className+".class");
return (defineClass(className, b, 0, b.length));
}
catch(FileNotFoundException ex)
{
m_log.debug("Run of the System Classloader.");
return (super.findClass(className));
}
catch(IOException ex)
{
m_log.debug("Run of the Bootstrap.");
return (super.findClass(className));
}
}
What could be the problem?
P.S. Loader implemented on the basis of this article:
http://sysmagazine.com/posts/104229/

Look: The stack trace shows the message "Run of the System Classloader", which proves that the first catch was executed. This was caused by a FileNotFoundException, which clearly occurred in the getClassAsBytes method: This is what you must investigate: Find out what file you are trying to read (put a trace showing the the absolute path), and why that file does not exist.
(Eventually, that catch block tries to load the required class by the system classloader, which has no acces to that class, and so, it throws the ClassNotFoundException).

Related

JSON Path 2.3.0 conflicts with hadoop 2.7 Environment JSON-smart1.2.0.jar

Have a Input of JSON inside HDFS location
It is required to parse the JSON and to aggregate results
To do am using the PIG UDF which are using JSON-path libraries
On the hadoop2.7 environment jar: json-smart1.2, json-path1.2 are hardbinded
Whenever I execute the PIG Mapreduce which throws me below Exception
java.lang.NoSuchFieldError: defaultReader
at com.jayway.jsonpath.spi.json.JsonSmartJsonProvider.<init>(JsonSmartJsonProvider.java:39)
at com.jayway.jsonpath.internal.DefaultsImpl.jsonProvider(DefaultsImpl.java:21)
at com.jayway.jsonpath.Configuration.defaultConfiguration(Configuration.java:174)
at com.jayway.jsonpath.internal.JsonContext.<init>(JsonContext.java:52)
at com.jayway.jsonpath.JsonPath.parse(JsonPath.java:596)
In-order to solve the problem tried below options
Option 1:
Tried setting Registering the json-smart2.3.jar & json-path2.3.0.jar
But no promising results (As the Jar it was referencing is json-path1.2.jar)
Option 2:
Downgrading my module dependencies to json-path1.2.jar
No results
Option 3:
Using Custom classLoaders tried to load the jar of JSON-path2.3.0 jar it
loaded the class went into issues of Org.slf4j binding
There were multiple binding paths identified, But went problems with sun.misc classloader
Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NullPointerException
at sun.net.util.URLUtil.urlNoFragString(URLUtil.java:50)
at sun.misc.URLClassPath.getLoader(URLClassPath.java:485)
at sun.misc.URLClassPath.getNextLoader(URLClassPath.java:457)
at sun.misc.URLClassPath.access$100(URLClassPath.java:64)
at sun.misc.URLClassPath$1.next(URLClassPath.java:239)
at sun.misc.URLClassPath$1.hasMoreElements(URLClassPath.java:250)
at java.net.URLClassLoader$3$1.run(URLClassLoader.java:601)
at java.net.URLClassLoader$3$1.run(URLClassLoader.java:599)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader$3.next(URLClassLoader.java:598)
at java.net.URLClassLoader$3.hasMoreElements(URLClassLoader.java:623)
at sun.misc.CompoundEnumeration.next(CompoundEnumeration.java:45)
at sun.misc.CompoundEnumeration.hasMoreElements(CompoundEnumeration.java:54)
at org.slf4j.LoggerFactory.findPossibleStaticLoggerBinderPathSet(LoggerFactory.java:238)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:138)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:120)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:331)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:283)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:304)
at com.jayway.jsonpath.internal.JsonContext.<clinit>(JsonContext.java:41)
at com.jayway.jsonpath.internal.ParseContextImpl.parse(ParseContextImpl.java:38)
at com.jayway.jsonpath.JsonPath.parse(JsonPath.java:599)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.optum.pdm.ReferenceDataUpdate.addURL(ReferenceDataUpdate.java:112)
at com.optum.pdm.ReferenceDataUpdate.main(ReferenceDataUpdate.java:124)
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.optum.pdm.ReferenceDataUpdate.addURL(ReferenceDataUpdate.java:112)
at com.optum.pdm.ReferenceDataUpdate.main(ReferenceDataUpdate.java:124)
Caused by: java.lang.ExceptionInInitializerError
at com.jayway.jsonpath.internal.ParseContextImpl.parse(ParseContextImpl.java:38)
at com.jayway.jsonpath.JsonPath.parse(JsonPath.java:599)
... 6 more
Caused by: java.lang.IllegalStateException: Unexpected initialization failure
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:167)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:120)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:331)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:283)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:304)
at com.jayway.jsonpath.internal.JsonContext.<clinit>(JsonContext.java:41)
... 8 more
Caused by: java.lang.NullPointerException
at sun.net.util.URLUtil.urlNoFragString(URLUtil.java:50)
at sun.misc.URLClassPath.getLoader(URLClassPath.java:485)
at sun.misc.URLClassPath.getNextLoader(URLClassPath.java:457)
at sun.misc.URLClassPath.access$100(URLClassPath.java:64)
at sun.misc.URLClassPath$1.next(URLClassPath.java:239)
at sun.misc.URLClassPath$1.hasMoreElements(URLClassPath.java:250)
at java.net.URLClassLoader$3$1.run(URLClassLoader.java:601)
at java.net.URLClassLoader$3$1.run(URLClassLoader.java:599)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader$3.next(URLClassLoader.java:598)
at java.net.URLClassLoader$3.hasMoreElements(URLClassLoader.java:623)
at sun.misc.CompoundEnumeration.next(CompoundEnumeration.java:45)
at sun.misc.CompoundEnumeration.hasMoreElements(CompoundEnumeration.java:54)
at org.slf4j.LoggerFactory.findPossibleStaticLoggerBinderPathSet(LoggerFactory.java:238)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:138)
... 13 more
Can some one suggest me to solve this problem, Can find one stackoverflow link where it was telling about weblogic and not a generalized solution which can be applied on Hadoop2.7 also (JSON Parser -java.lang.NoSuchFieldError: defaultReader)
As hadoop environment(Pig, hdfs, Hive & etc) is using json-path-2.3.0, Its better user Mapper logic should use another version "jsonpath-1.0.jar" will solve the problem
Provide the custom implementation to load/parse the JSON so that we can avoid using Json-smart-2.x/1.x of Hadoop/lib
public static void changeJsonPathConfig() {
if (!configChanged) {
Configuration.setDefaults(new Configuration.Defaults() {
private final JsonProvider jsonProvider = new GsonJsonProvider(
new GsonBuilder().serializeNulls().create());
private final MappingProvider mappingProvider = new GsonMappingProvider();
#Override
public JsonProvider jsonProvider() {
return jsonProvider;
}
#Override
public MappingProvider mappingProvider() {
return mappingProvider;
}
#Override
public Set<Option> options() {
return EnumSet.noneOf(Option.class);
}
});
configChanged = true;
}
}

Running jTSS in Eclipse

I am trying to run the Trusted Computing API JSR321 in Eclipse by following the tutorial provide at Getting Started with JSR321 in Windows 7.
After successfully enabling my TPM (manufacturer: STM & version: 1.2).
I tried to run the code given in the tutorial,
import javax.trustedcomputing.tpm.TPMContext;
public class HellowWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
TPMContext context = TPMContext.getInstance();
context.connect(null);
//Do somthing cool here
context.close();
}
catch (Exception e){
e.printStackTrace();
}
}
}
I also added the external jar files as Classpaths in eclipse for the IAIK jTSS (jTSS 0.7.1a), they also mentioned that
It is necessary to set the jsr321.tpmcontextimpl property to the classname of your TPMContext implementation.
For example java -cp YourClasspath -Djsr321.tpmcontextimpl=iaik.tc.jsr321.tpm.TPMContextImpl yourjavaapplication.class
So I added the above code by right clicking on the project and going to the Run As -> Run Configuration and in the Arguments tab in the section provided for VM arguments I inserted the following command
-cp C:\Users\workspace\HelloWorld\bin -Djsr321.tpmcontextimpl=iaik.tc.jsr321.tpm.TPMContextImpl HellowWorld
But I am getting the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/trustedcomputing/tpm/TPMContext
at HellowWorld.main(HellowWorld.java:10)
Caused by: java.lang.ClassNotFoundException: javax.trustedcomputing.tpm.TPMContext
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
I have already added all the mentioned dependencies in Java Build Paths inside Project Properties.
Kindly suggest a solution.
Thanks

flexjson: Could not load class

I'm new to flexjson.
I tried the following java code for my test: "FlexjsonTest.zip".
The result of running the program is in "Protocol.txt".
I ran the code from the command line:
javac FlexjsonTest.java
java Flexjson
I use flexjson 2.1 .
Using Java 6 or Java 7 doesn't make any difference.
The result is always:
Exception in thread "main" flexjson.JSONException: [ _address ]: Could not load Address
at flexjson.ObjectBinder.findClassInMap(ObjectBinder.java:235)
at flexjson.ObjectBinder.findClassName(ObjectBinder.java:202)
at flexjson.ObjectBinder.bind(ObjectBinder.java:83)
at flexjson.ObjectBinder.bindIntoObject(ObjectBinder.java:139)
at flexjson.factories.ClassLocatorObjectFactory.instantiate(ClassLocatorObjectFactory.java:38)
at flexjson.ObjectBinder.bind(ObjectBinder.java:86)
at flexjson.ObjectBinder.bind(ObjectBinder.java:65)
at flexjson.JSONDeserializer.deserialize(JSONDeserializer.java:158)
at FlexjsonTest.<init>(FlexjsonTest.java:22)
at FlexjsonTest.main(FlexjsonTest.java:32)
Caused by: java.lang.ClassNotFoundException: Address
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:188)
at flexjson.ObjectBinder.findClassInMap(ObjectBinder.java:230)
... 9 more
So, what am I doing wrong?
igel
it seems that you're trying to deserialize a JSON into an object called Address but the class Address seems not to be in your classpath
at flexjson.JSONDeserializer.deserialize(JSONDeserializer.java:158)
at FlexjsonTest.<init>(FlexjsonTest.java:22)
at FlexjsonTest.main(FlexjsonTest.java:32)
Caused by: java.lang.ClassNotFoundException: Address
also, you should post the code that actually throws this stacktrace in your question

Exception in thread "main" java.lang.NoClassDefFoundError with NetBeans

Im getting this Exception with my project,after I run the project X times, I get it, but it is not always in the same class, sometimes it happens with other classes, or being more especific, with other frames, as far as I have seen, I have got it only with my frames.
when I get this error, I only retype the package of the frame that throws the exception and done!, but of course, that is not a solution.
Exception in thread "main" java.lang.NoClassDefFoundError: xoxo/Vistas/VistaLogin$1
at xoxo.Vistas.VistaLogin.initComponents(VistaLogin.java:49)
at xoxo.Vistas.VistaLogin.<init>(VistaLogin.java:19)
at xoxo.Controlador.ControladorLogin.<clinit>(ControladorLogin.java:17)
at xoxo.princ.Principal.main(Principal.java:7)
Caused by: java.lang.ClassNotFoundException: xoxo.Vistas.VistaLogin$1
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 4 more
thanks for the help.
See my answer of this i am sure that is Desired Solution. and if You sure 100% that there is exist same class which is shown in error.
This is my ans
Try it that will be helpful.

Java file input and output

I have the below method which is meant to append information to a file but I get the error below. In the method I use parts of robocode API which inherits from java.io.InputStream
All the permissions on the files and folders seem fine and the file does exist
static public void logInfo(String info)
{
RobocodeFileWriter in;
try {
in = new RobocodeFileWriter("log.txt");
in.append(info);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
SYSTEM: An error occurred during initialization of itc.solomon
SYSTEM: java.security.AccessControlException: Preventing itc.solomon from access: (java.io.FilePermission log.txt read): You may only read files in your own root package directory.
java.security.AccessControlException: Preventing itc.solomon from access: (java.io.FilePermission log.txt read): You may only read files in your own root package directory.
at robocode.security.RobocodeSecurityManager.handleSecurityProblem(Unknown Source)
at robocode.security.RobocodeSecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(SecurityManager.java:888)
at java.io.File.exists(File.java:748)
at robocode.RobocodeFileOutputStream.(Unknown Source)
at robocode.RobocodeFileOutputStream.(Unknown Source)
at robocode.RobocodeFileWriter.(Unknown Source)
at itc.CFile.logInfo(CFile.java:16)
at itc.solomon.(solomon.java:43)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at java.lang.Class.newInstance0(Class.java:372)
at java.lang.Class.newInstance(Class.java:325)
at robocode.peer.proxies.HostingRobotProxy.loadRobotRound(Unknown Source)
at robocode.peer.proxies.HostingRobotProxy.run(Unknown Source)
at java.lang.Thread.run(Thread.java:636)
See this sample:
http://code.google.com/p/robocode/source/browse/robocode/trunk/robocode.samples/src/main/java/sample/SittingDuck.java
I think getDataFile("log.txt") will give you proper location.
I've searched a bit about this problem. It seems that there's a bug in the robocode package, awkwardly solved by:
while (!dataIsLoaded) {
try {
tryToReadData;
dataIsLoaded = true;
} catch (AnyException e) {}
}
It's a quite awful way to solve the problems, for many reasons (ignoring exceptions, busy-waiting, etc.) A more sane way would be downgrading the robocode package to a previous, more stable version.
See search results here.

Categories

Resources