I am trying to inject a .jar file in a running VM.
I've added tools.jar in the build path in eclipse, but when I try to run the injector, this error pops up. How should I add tools.jar to the project?
Full error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/attach/VirtualMachine
at src.testinjector.MainClass.main(MainClass.java:13)
Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine
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
you may try:
Give the path to tools.jar instead of being dependent on JAVA_HOME.
Note: JAVA_HOME/path to jdk/bin/ should not have any space.
By default, the "tools.jar" classes are not loaded, your options are to either use a jdk that does load it, include tools.jar in your jar, or forcefully load it with the method below, (note: this might not work on certain jdk/jvm's)
private static void prepareAttach() throws NoSuchMethodException, MalformedURLException, InvocationTargetException, IllegalAccessException {
String binPath = System.getProperty("sun.boot.library.path");
// remove jre/bin, replace with lib
String libPath = binPath.substring(0, binPath.length() - 7) + "lib";
URLClassLoader loader = (URLClassLoader) [This Class].class.getClassLoader();
Method addURLMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
addURLMethod.setAccessible(true);
File toolsJar = new File(libPath + "/tools.jar");
if (!toolsJar.exists()) throw new RuntimeException(toolsJar.getAbsolutePath() + " does not exist");
addURLMethod.invoke(loader, new File(libPath + "/tools.jar").toURI().toURL());
}
Related
I am trying to progamatically compile and load protobuf code in an eclipse plugin but for some reason it gives me this error:
java.lang.NoClassDefFoundError: com/google/protobuf/ExtensionRegistryLite
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
I know I have the dependencies set up correctly because I am able to import ExtensionRegistroyLite and use it. Also when I run this code as a Java application it works fine. Here is how I am compiling and loading the class:
compiler.run(null, null, null, "-d", "path/to/dir, "-classpath", "protobuf-java-3.11.4.jar", "myProtoClass.java")
URL url = protoDir.toUri().toURL();
URL[] urls = new URL[]{url};
// load compiled class
ClassLoader cl = new URLClassLoader(urls);
// create object of compiled class
Class<?> cls = Class.forName(fullMessageName, true, cl); // Crashes at this line
If I scroll down further in the errors it says:
Caused by: java.lang.ClassNotFoundException: com.google.protobuf.ExtensionRegistryLite
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
Any hints as to what may be causing this would be appreciated!
how i can get real path of file.xml from web-inf in ZUL, i try this:
org.zkoss.zrss.RssFeed feed;
org.zkoss.zrss.RssBinder binder = new org.zkoss.zrss.RssBinder();
try {
feed = binder.lookUpFeed(new File("/WEB-INF/lesscoutsBeRss.xml").toURI().toURL().toString());
} catch (Exception e) {
e.getStackTrace();
}
but i have problem ,I think the problem because of the bad good recovery path
Failed to load /MainPage/rss_lesscouts.zul
Cause: Null Pointer in Method Invocation
java.lang.NullPointerException: Null Pointer in Method Invocation
at bsh.Name.invokeMethod(Unknown Source)
at bsh.BSHMethodInvocation.eval(Unknown Source)
at bsh.BSHPrimarySuffix.doSuffix(Unknown Source)
at bsh.BSHPrimaryExpression.eval(Unknown Source)
at bsh.BSHPrimaryExpression.eval(Unknown Source)
at bsh.BSHVariableDeclarator.eval(Unknown Source)
at bsh.BSHTypedVariableDeclaration.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
...
You may try to use this, in order to retrieve the full path of WEB-INF folder in a ZK project:
Sessions.getCurrent().getWebApp().getRealPath("")+"/WEB-INF/"
Hope this helps you.
I executed a main class and got the following error and trace.
This is the console command:
java -cp . net.sf.tinyPayroll.Main
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.hsqldb.Trace
at org.hsqldb.Database.reopen(Unknown Source)
at org.hsqldb.Database.open(Unknown Source)
at org.hsqldb.DatabaseManager.getDatabase(Unknown Source)
at org.hsqldb.DatabaseManager.newSession(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.<init>(Unknown Source)
at org.hsqldb.jdbcDriver.getConnection(Unknown Source)
at org.hsqldb.jdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at net.sf.tinyPayroll.dao.DBConnector.connectDataFile(DBConnector.java:88)
at net.sf.tinyPayroll.dao.DBConnector.<init>(DBConnector.java:72)
at net.sf.tinyPayroll.dao.DBConnector.getInstance(DBConnector.java:106)
at net.sf.tinyPayroll.model.DataFile.<init>(DataFile.java:53)
at net.sf.tinyPayroll.Main.main(Main.java:42)
However, all the necessary classes are in the same folder.
Here is the file which is extracted and available in the same folder (the entire library is available in extracted form).
find . -name Trace*
./org/hsqldb/Trace.class
./org/hsqldb/util/Traceable.class
Your exception is:
NoClassDefFoundError: Could not initialize class org.hsqldb.Trace
Which doesn't mean that it cannot find the class org.hsqldb.Trace in your classpath, it means that the class could not be initialized for some reason.
It generally means that a RuntimeException was thrown while either trying to assign a value to a static field or while trying to execute some code in a static block.
For example we will get such issue in the next cases:
class Trace {
static MyClass foo = MyClass.newInstance(); // If it fails while calling newInstance
static {
SomeClass.init(); // If it fails while calling SomeClass.init()
}
...
}
As Nicolas has mentioned this doesn't mean that it cannot find the class org.hsqldb.Trace in your classpath, it means that the class could not be initialized for some reason.
I've checked the code (This might change based on version) http://grepcode.com/file/repo1.maven.org/maven2/hsqldb/hsqldb/1.8.0.1/org/hsqldb/Trace.java
In the class it has some static block which do some processing. Most probably some of the resources are missing in your class path
I have developed a runner module for my automation framework which will allow testers author and execute the tests using Eclipse IDE.
Now I am looking to add a module to connect to QC and upload my tests to the respective test plan. For this I am using qcutils.jar.
My Code:
public static void QCConnect()
{
File fUser = new File("lib");
File fNat = new File(fUser, "jacob-1.18-x64.dll");
// Set java library path at runtime
String javaPath = System.getProperty("java.library.path");
javaPath = javaPath+";"+fUser.getAbsolutePath()+";";
System.setProperty("java.library.path", javaPath);
String javaPath1 = System.getProperty("java.library.path");
// Load dll
System.load(fUser.getAbsolutePath()+"\\jacob-1.18-x64.dll");
IQcConnection conn = QcConnectionFactory.createConnection("https://<myqc>/qcbin");
conn.connect("user", "pass", "domain", "project");
TestClient tc = conn.getTestClient();
Test t = new Test();
t.setTestFolder(TestFolder.ROOT_FOLDER + "\\Demo");
t.setDescription("This is a QcTools4j Test");
t.setStatus("Design");
t.setName("myTest");
tc.saveTest(t)
}
Encountered Exception:
org.qctools4j.utils.DllLoader loadLibrary
SEVERE: DLL not found in the class path!
Exception in thread "main" org.qctools4j.exception.QcException: Can't get object clsid from progid
at org.qctools4j.clients.QcConnectionImpl.initConnection(Unknown Source)
at org.qctools4j.clients.QcConnectionImpl.<init>(Unknown Source)
at org.qctools4j.QcConnectionFactory.createConnection(Unknown Source)
at QCJavaConnect.main(QCJavaConnect.java:37)
Caused by: com.jacob.com.ComFailException: Can't get object clsid from progid
at com.jacob.com.Dispatch.createInstanceNative(Native Method)
at com.jacob.com.Dispatch.<init>(Dispatch.java:99)
at com.jacob.activeX.ActiveXComponent.<init>(ActiveXComponent.java:58)
at org.qctools4j.clients.QcConnectionImpl.initConnection(Unknown Source)
... 3 more
I am a looking for a solution on handling QC using java, I do not mind using any other java package.
Thanks in Advance!
I get following exception with new cobertura (2.0.2..). I guess it is some how related to new object creation immediately in a new block.
WARN instrumentClass, Unable to instrument file c:\apps\ijprojects\TrickyInstrument\out\production\TrickyInstrument\InstrumentationFailsOnFirstNewClassInTryBlock.class
java.lang.RuntimeException: java.lang.ClassNotFoundException: DataAccess
at org.objectweb.asm.ClassWriter.getCommonSuperClass(Unknown Source)
at org.objectweb.asm.ClassWriter.a(Unknown Source)
at org.objectweb.asm.Frame.a(Unknown Source)
at org.objectweb.asm.Frame.a(Unknown Source)
at org.objectweb.asm.MethodWriter.visitMaxs(Unknown Source)
at org.objectweb.asm.MethodVisitor.visitMaxs(Unknown Source)
at org.objectweb.asm.util.CheckMethodAdapter.visitMaxs(Unknown Source)
at org.objectweb.asm.MethodVisitor.visitMaxs(Unknown Source)
at org.objectweb.asm.commons.LocalVariablesSorter.visitMaxs(Unknown Source)
at org.objectweb.asm.tree.MethodNode.accept(Unknown Source)
at org.objectweb.asm.util.CheckMethodAdapter$1.visitEnd(Unknown Source)
at org.objectweb.asm.MethodVisitor.visitEnd(Unknown Source)
at org.objectweb.asm.util.CheckMethodAdapter.visitEnd(Unknown Source)
at org.objectweb.asm.ClassReader.b(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:204)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:121)
at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.addInstrumentationToSingleClass(CoberturaInstrumenter.java:233)
at net.sourceforge.cobertura.instrument.Main.addInstrumentationToSingleClass(Main.java:274)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:283)
at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:292)
at net.sourceforge.cobertura.instrument.Main.parseArguments(Main.java:373)
at net.sourceforge.cobertura.instrument.Main.main(Main.java:395)
8 Jul, 2013 2:05:07 PM net.sourceforge.cobertura.coveragedata.CoverageDataFileHandler saveCoverageData
INFO: Cobertura: Saved information on 2 classes.
The following is the code related to above exception.
public class InstrumentationFailsOnFirstNewClassInTryBlock {
public void saveToDatabase() {
//
try {
// boolean b=false;
// if ( b) {
// System.out.println("no action");
// }
DataAccess da = new DataAccess();
System.out.println("nothing");
} catch (Exception e) {
}
}
}
class DataAccess {
public DataAccess() {
//To change body of created methods use File | Settings | File Templates.
}
}
If I un-comment the code block some dummy statements , then instrumentation works fine. Has any one seen this? Any potential fixes?
Edit: Error occurs with java6 and java7.
Original problem was due to a Cobertura defect. It is not fixed. Cobertura now supports an additional argument for auxillary classpath.. This will be used to resolve any classes required for instrumentation.
cobertura-ant task documentation
Adding auxClasspath
auxClasspath argument is designed to remove the ClassNotFoundException
during instrumentation. See
https://github.com/cobertura/cobertura/wiki/FAQ#classnotfoundexception-during-instrumentation
for more information on this argument
I had a similar issue, and it may be a bug, see: https://github.com/cobertura/cobertura/issues/49
Your test case may be useful to debug the issue...
From https://github.com/cobertura/cobertura/wiki/FAQ#classnotfoundexception-during-instrumentation:
"This is because during instrumentation in cobertura 2.0, we use ASM to rebuild the .class files. We rebuild the stackmap which is a requirement to be compatible with java 7 and anything after. This does not mean that we recompile the code, however ASM requires that we provide the binaries of the other classes just in case it needs to look up any super methods. To fix this we use an argument called auxClasspath."
Adding the following code to your ant file (build.xml) should resolve the issue.
<path id="cobertura.auxpath">
<pathelement location="${bin}"/>
</path>
<target name="instrument_coverage" depends="init_coverage"
description="Instruments source code for coverage measurement">
<cobertura-instrument datafile="${coverage.datafile}">
<fileset refid="coverage-files"/>
<auxClasspath>
<path refid="cobertura.auxpath" />
</auxClasspath>
</cobertura-instrument>
</target>
This worked for me.