Exception Error in creating an instance of RandomDataImpl - 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.

Related

running junit testcase application from command line causes initialization errors

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

ClassNotFoundException while replacing java 6 rmi w/ java 8 [duplicate]

The following method :
private void startServer() { // snippet that starts the server on the local machine
try {
RemoteMethodImpl impl = new RemoteMethodImpl();
Naming.rebind( "Illusive-Server" , impl );
}catch(Exception exc) {
JOptionPane.showMessageDialog(this, "Problem starting the server", "Error", JOptionPane.ERROR_MESSAGE);
System.out.println(exc);
}
}
throws this exception :java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: Interfaces.RemoteMethodIntf
When i start my project, i am greeted with the message in JOptionPane saying problem starting the server and then the above exception. What could be the reason for this ?
I don't understand why does the last statement of exception says class not found exc when i have imported the right packages
There are four cases of this exception.
When exporting: you didn't run 'rmic' and you didn't take the steps described in the preamble to the Javadoc for UnicastRemoteObject to make it unnecessary.
When binding: the Registry doesn't have the stub or the remote interface or something they depend on on its classpath.
when looking up: the client does't have these things on its classpath.
When calling a remote method: you either sent something to the server of a class not present on its CLASSPATH, or received something from the server (including an exception) of a class not on your CLASSPATH: in both cases possibly a derived class or interface implementation of a class or interface mentioned in the remote interface's method signature.
This is case 2. The Registry can't find the named class.
There are several solutions:
Start the Registry with a CLASSPATH that includes the relevant JARs or directories.
Start the Registry in your server JVM, via LocateRegistry.createRegistry().
Use dynamic stubs, as described in the preamble to the Javadoc of UnicastRemoteObject. However you may then still run into the same problem with the remote interface itself or a class that it depends on, in which case 1-3 above still apply to that class/those classes.
Ensure that case (4) above doesn't occur.
Use the codebase feature. This is really a deployment option and IMO something to be avoided at the initial development stage.
Remote Server Error:RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: mathInterface
The error very simple to solve to be perform following steps:
For example your java file consider D drive
Start rmiregistry D drive( example D:\start rmiregistry)then don't start rmiregistry on the other drives, it will yield the above error
(Wherever your file is, start rmiregistry)
I will try to explain it as better as possible what I did:
1st. I declared the classpath variable like follow:
set classpath=%classpath%
set classpath=C:\compiler
set classpath=C:\compiler\libro\cap07\rmi\hello\Hello.java
set classpath=C:\compiler\libro\cap07\rmi\hello\Server.java
set classpath=C:\compiler\libro\cap07\rmi\hello\Client.java
(All in one lineset:
set classpath=%classpath%;C:\compiler;C:\compiler\libro\cap07\rmi\hello\Hello.java;C:\compiler\libro\cap07\rmi\hello\Server.java;C:\compiler\libro\cap07\rmi\hello\Client.java)
(I'm not sure if the .java files were nesesary, but I also wrote them for doubts).
2nd. I compilered with the line javac -d C:\compiler Hello.java Server.java Client.java. Where C:\compiler is the root directory like src on Eclipse IDE.
3rd. I ran the start rmiregistry line. (and don´t matter where you run it, it's the same).
4th. I ran:
start java -classpath C:\compiler -Djava.rmi.server.codebase=file:C:\compiler/ libro.cap07.rmi.hello.Server
You already know C:\compiler, but you need define packages address on the last to that the command can find the .class files. Open any .java file and copy the package address without packages sentense. You will see when you open the src directory (in my case C:\compiler), you find all directory sequence created. When this command line is created correctly, no matter where you will run it, C:, D:, src, anywhere it wil run.
5th. And finally, I ran the Client class with:
java -classpath C:\compiler libro.cap07.rmi.hello.Client
In conclusion, if the classpath variable won't created or it's to created wrong or the sentence of 4th point is not addressed well the JVM throws the same or similar error. Search there!
(Sorry my english).
You can launch rmiregistry from anywhere but you have to make sure that the compiled classes are already in your classpath. For example:-
E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes>set classpath=%classpath%;E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes <ENTER>
E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes>c: <ENTER>
C:\>rmiregistry
And the above should work fine.
In general, if you launch rmiregistry from the root location of the compiled classes (above example it is E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes), that will work because . (dot - current directory) is already set in your classpath.
But as soon as you remove . (dot - current directory) from your classpath, the above working condition will also fail.
Hope I have explained in details.
I got this same issue, and a different solution worked for me. I was running two different IntelliJ projects, with a copy of the interface in each project. One of them was in a package, and the other one wasn't, and that was what was causing this error.
Solutions:
Make sure the interface copies aren't in a package.
Make sure the interface copies have the exact same package name.

Why am I getting a NoClassDefFoundError in java?

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

ZMQ - libzmq.so.3: cannot open shared object file: No such file or directory

I'm trying to embed zeroMQ in my app, I followed this guideline to install ZMQ, so till here everything works fine.
I have this line of code in my app:
ZMQ.Context m_context = ZMQ.context(1);
but above line of code raise below exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError: /tmp/libjzmq-812339378390536247.lib: libzmq.so.3: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1939)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1864)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1825)
at java.lang.Runtime.load0(Runtime.java:792)
at java.lang.System.load(System.java:1059)
at org.zeromq.EmbeddedLibraryTools.loadEmbeddedLibrary(EmbeddedLibraryTools.java:136)
at org.zeromq.EmbeddedLibraryTools.<clinit>(EmbeddedLibraryTools.java:22)
at org.zeromq.ZMQ.<clinit>(ZMQ.java:38)
at com.castaclip.verticals.Messenger.<init>(Messenger.java:125)
at com.castaclip.verticals.PushMessenger.<init>(PushMessenger.java:30)
at com.castaclip.verticals.pushserver.App.setup(App.java:60)
at com.castaclip.verticals.pushserver.App.main(App.java:41)
The error is exactly pointing to this line.
P.S: its a little bit difficult to fully explain this question.. if you have any question plz let me know. thanks.
If you've successfully built libzmq and jzmq in that order, I would run:
$ sudo ldconfig
to update the system library cache. Then I would check to see if LD_LIBRARY_PATH is defined like Raffian mentioned, or set your library path explicitly to something like:
$ java -Djava.library.path=/usr/lib:/usr/local/lib
Finally I tried to figure out the problem.
I was using zeromq-2.1.10 and this was part of the problem.
So I installed zeromq-3.2.3 from the source and problem resolved.
I encountered a mystifying instance of this message when I:
# java -Djava.library.path=/usr/hf/zmq/lib/ -cp '/usr/hf/lib/*:.' com.zmqtest.MA
Exception in thread "main"
java.lang.UnsatisfiedLinkError: /usr/hf/zmq/lib/libjzmq.so:
libzmq.so.3: cannot open shared object file: No such file or directory
which was fixed with a solution that makes no sense at all to me:
# LD_LIBRARY_PATH=/usr/hf/zmq/lib/ java -Djava.library.path=/usr/hf/zmq/lib/ -cp '/usr/hf/lib/*:.' com.zmqtest.MA
wierd.

Java RMI Remote Interface Tutorial - error: unmarshalling arguments [duplicate]

The following method :
private void startServer() { // snippet that starts the server on the local machine
try {
RemoteMethodImpl impl = new RemoteMethodImpl();
Naming.rebind( "Illusive-Server" , impl );
}catch(Exception exc) {
JOptionPane.showMessageDialog(this, "Problem starting the server", "Error", JOptionPane.ERROR_MESSAGE);
System.out.println(exc);
}
}
throws this exception :java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: Interfaces.RemoteMethodIntf
When i start my project, i am greeted with the message in JOptionPane saying problem starting the server and then the above exception. What could be the reason for this ?
I don't understand why does the last statement of exception says class not found exc when i have imported the right packages
There are four cases of this exception.
When exporting: you didn't run 'rmic' and you didn't take the steps described in the preamble to the Javadoc for UnicastRemoteObject to make it unnecessary.
When binding: the Registry doesn't have the stub or the remote interface or something they depend on on its classpath.
when looking up: the client does't have these things on its classpath.
When calling a remote method: you either sent something to the server of a class not present on its CLASSPATH, or received something from the server (including an exception) of a class not on your CLASSPATH: in both cases possibly a derived class or interface implementation of a class or interface mentioned in the remote interface's method signature.
This is case 2. The Registry can't find the named class.
There are several solutions:
Start the Registry with a CLASSPATH that includes the relevant JARs or directories.
Start the Registry in your server JVM, via LocateRegistry.createRegistry().
Use dynamic stubs, as described in the preamble to the Javadoc of UnicastRemoteObject. However you may then still run into the same problem with the remote interface itself or a class that it depends on, in which case 1-3 above still apply to that class/those classes.
Ensure that case (4) above doesn't occur.
Use the codebase feature. This is really a deployment option and IMO something to be avoided at the initial development stage.
Remote Server Error:RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: mathInterface
The error very simple to solve to be perform following steps:
For example your java file consider D drive
Start rmiregistry D drive( example D:\start rmiregistry)then don't start rmiregistry on the other drives, it will yield the above error
(Wherever your file is, start rmiregistry)
I will try to explain it as better as possible what I did:
1st. I declared the classpath variable like follow:
set classpath=%classpath%
set classpath=C:\compiler
set classpath=C:\compiler\libro\cap07\rmi\hello\Hello.java
set classpath=C:\compiler\libro\cap07\rmi\hello\Server.java
set classpath=C:\compiler\libro\cap07\rmi\hello\Client.java
(All in one lineset:
set classpath=%classpath%;C:\compiler;C:\compiler\libro\cap07\rmi\hello\Hello.java;C:\compiler\libro\cap07\rmi\hello\Server.java;C:\compiler\libro\cap07\rmi\hello\Client.java)
(I'm not sure if the .java files were nesesary, but I also wrote them for doubts).
2nd. I compilered with the line javac -d C:\compiler Hello.java Server.java Client.java. Where C:\compiler is the root directory like src on Eclipse IDE.
3rd. I ran the start rmiregistry line. (and don´t matter where you run it, it's the same).
4th. I ran:
start java -classpath C:\compiler -Djava.rmi.server.codebase=file:C:\compiler/ libro.cap07.rmi.hello.Server
You already know C:\compiler, but you need define packages address on the last to that the command can find the .class files. Open any .java file and copy the package address without packages sentense. You will see when you open the src directory (in my case C:\compiler), you find all directory sequence created. When this command line is created correctly, no matter where you will run it, C:, D:, src, anywhere it wil run.
5th. And finally, I ran the Client class with:
java -classpath C:\compiler libro.cap07.rmi.hello.Client
In conclusion, if the classpath variable won't created or it's to created wrong or the sentence of 4th point is not addressed well the JVM throws the same or similar error. Search there!
(Sorry my english).
You can launch rmiregistry from anywhere but you have to make sure that the compiled classes are already in your classpath. For example:-
E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes>set classpath=%classpath%;E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes <ENTER>
E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes>c: <ENTER>
C:\>rmiregistry
And the above should work fine.
In general, if you launch rmiregistry from the root location of the compiled classes (above example it is E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes), that will work because . (dot - current directory) is already set in your classpath.
But as soon as you remove . (dot - current directory) from your classpath, the above working condition will also fail.
Hope I have explained in details.
I got this same issue, and a different solution worked for me. I was running two different IntelliJ projects, with a copy of the interface in each project. One of them was in a package, and the other one wasn't, and that was what was causing this error.
Solutions:
Make sure the interface copies aren't in a package.
Make sure the interface copies have the exact same package name.

Categories