When I fire the following from command line:
D:\workspace 2\project\lib>java -javaagent:myagent.jar -cp asm-all-3.3.jar;. AgentMain
I get the following error
java.lang.NullPointerException
java.lang.NullPointerException
Exception in thread "main" java.lang.NoSuchMethodError: java.lang.VerifyError: method(init) (Ljava/lang/String;) V not found
java.lang.NullPointerException
Couldnot find the main class AgentMain. Program will exit.
I have all the files and jar in the working directory. AgentMain is the compiled class that I put it here from the bin folder. I dont know what is the problem.
I would check first whether the Agent is implemented OK?
You did follow the structure as set forth in java.lang.instrument (public static void premain(String agentArgs);) including the MANIFEST entries? And there's no way that the Agent can throw NPEs during initialization?
Also, you may want to try out wheter it's the Agent or the AgentMain.class, by running java -javaagent:myagent.jar -cp asm-all-3.3.jar;. -version
Have you tried setting the classpath to the current folder (-cp . ) ?
Related
I have a testing application running as expected when executed on Eclipse IDE.
We want to export it to a jar and execute it via command line.
After executing, and running the application with the following comand, i encounter an error
java -jar testclient.jar -info
Error: Unable to initialize main class testclient.Main
Caused by: java.lang.NoClassDefFoundError: org/junit/runners/model/InitializationError
( -info) is an argument for the main method in the class.
Manifest file is pointing to the correct class.
On research of this topic, i checked whether the required libraries are added to the path. They are correctly added.
Could anyone provide some guidance
I have a java gradle projectA that references another java gradle projectB, that builds as a lib.
My gradle build configuration seems to be fine, since I can import and use classes from the other project, and it compiles. But when I try to run the application from the command line I get an error...
Exception in thread "main" java.lang.NoClassDefFoundError:
dawcore/SamplerInstrument at DawCLI.main(DawCLI.java:17) Caused by:
java.lang.ClassNotFoundException: dawcore.SamplerInstrument at
java.net.URLClassLoader.findClass(URLClassLoader.java:382) at
java.lang.ClassLoader.loadClass(ClassLoader.java:424) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at
java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 1 more
It seems to be complaining that it can't load the classes in the jar at runtime....which makes sense. But I don't know how to have it successfully load those classes.
my current run command that does not reference the jar, is as follows....
/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/bin/java -ea -cp "build/classes/main/" DawCLI
Running this gives the initially mentioned error.
I then read the docs on java -cp argument. It says to provide additional classpath directories, to separate them by semicolon.
I susequently updated my run command to be as follows....
/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/bin/java -ea -cp "build/classes/main/;../DawCore/build/libs/DawCore.jar" DawCLI
This gives me the following error....
Error: Could not find or load main class DawCLI
My main function is as follows..
import dawcore.*;
public class DawCLI {
public static void main (String [] args) throws IOException {
SamplerInstrument samplerkick = new SamplerInstrument();
}
}
According to the docs I seem to be doing this correctly, but am still getting errors. Any insight on this would be greatly appreciated!
Thanks
The solution was to replace the delimiting semi-colon with a colon instead. Even though the first line of the javadocs on -cp command indicate that you should use a semi-colon.
This could be because I am running on linux and those docs indicate Windows.
https://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html
i would like to use jdb,i'm trying to run it couple of hours already and i have searched all over the examples there are.i think its a syntax problem..
i'm trying to run it like this:
>jdb Main
Initializing jdb ...
>run
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
VM Started:Error: Could not find or load main class Main
The application exited
//-----------------------------
I also tried to put the full path which is:
C:/Users/Daniel/Documents/NetBeansProjects/Try/src/pkgtry/Main.java
Try to use -sourcepath and -classpath. sourcepath should point to source codes (.java) and classpath should point to compiled code (.class).
It's also good idea to put your source inside package (in case of Java just create directory and put sources there).
Use full name of source file with extension (filename.java)
in directory with your source file:
C:/Users/Daniel/Documents/NetBeansProjects/Try/src/pkgtry>
>jdb Main.java
Initializing jdb ...
>run
or
C:/Users/Daniel/Documents/NetBeansProjects/Try/src/pkgtry>
>jdb
Initializing jdb ...
>run Main.java
I am getting this exception error at
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/commons/math3/random/RandomDataImpl
at this line of code:
randomData_ = new RandomDataImpl();
and this is how the class is imported in the code :
import org.apache.commons.math3.random.RandomDataImpl;
i have added all of the math common classes to the classpath while running the code. any ideas whats going on ?
It looks like you did not set the appropriate classpath.
You can set it as follows:
java -classpath lib/*.jar:. mypackage.MyClass
Try that and I am sure it will work.
If you are using maven, then read this article
You can also check your current classpath with:
System.getProperty("java.class.path")
Just write simple app printing this property out and run it just as you run an app with which you are having problems.
I managed to successfully compile my code, but I'm not able to execute it. How do I fix this?
scannerTesting is my package and ScannerTesting.java is my main file.
D:\Java>javac Testing\src\scannerTesting\ScannerTesting.java
D:\Java>java Testing\src\scannerTesting\ScannerTesting
Exception in thread "main" java.lang.NoClassDefFoundError: Testing\src\scannerTesting\ScannerTesting <wrong name: scannerTesting/ScannerTesting>
.
.
.
java -cp ./Testing/src scannerTesting.ScannerTesting
When you run java, it looks for matching classes within its classpath. So what these arguments are doing is add your source folder to the classpath using -cp, and specify that the class that should be run is scannerTesting.ScannerTesting.
For more information, check out java cli tool documentation at Oracle
scannerTesting is your package name,right?
If so, I suggest you run command "java" under the workspace D:\Java\Testing\src
java scannerTesting.ScannerTest