I am coding a RMI program with 3 JAR:
RMIServer, contains server-side classes
RMIClient contains client-side classes
RMIResource contains server & client shared content (interfaces, custom exceptions)
To make separate JAR files, I created 3 projects in NetBeans, then I declared the shared Jar in the "Libraries/Build" section of the other 2 projects.
Everything just build-up fine, no error.
But when I try to launch the server through the command-line, which was simple before I had the idea to put the shared files in a distinct JAR, this is suddenly pain in the a**...
Here are a few examples of commands I tried:
Keeping the ClassPath pointing to the server resources, but using dual CodeBase
java -cp ~/NetBeansProjects/RMIServer/dist/RMIServer.jar -Djava.rmi.server.codebase="file:/home/myuser/netbeansprojects/rmiserver/dist/rmiserver.jar file:/home/myuser/netbeansprojects/rmiserver/dist/lib/rmiresource.jar" rmiserver.Shop
Result:
Network exception: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: rmiresource.BookingManager
...
Using dual ClassPath but keeping the CodeBase pointing to the server resources
java -cp "~/NetBeansProjects/RMIServer/dist/RMIServer.jar;~/NetBeansProjects/RMIServer/dist/lib/RMIResource.jar" -Djava.rmi.server.codebase=file:/home/myuser/netbeansprojects/rmiserver/dist/rmiserver.jar rmiserver.Shop
Result:
Exception in thread "main" java.lang.NoClassDefFoundError: rmiserver/Shop
Caused by: java.lang.ClassNotFoundException: rmiserver.Shop
...
Using dual ClassPath & dual CodeBase
java -cp "~/NetBeansProjects/RMIServer/dist/RMIServer.jar;~/NetBeansProjects/RMIServer/dist/lib/RMIResource.jar" -Djava.rmi.server.codebase="file:/home/myuser/netbeansprojects/rmiserver/dist/rmiserver.jar file:/home/myuser/netbeansprojects/rmiserver/dist/lib/rmiresource.jar" rmiserver.Shop
Result:
Exception in thread "main" java.lang.NoClassDefFoundError: rmiserver/Shop
Caused by: java.lang.ClassNotFoundException: rmiserver.Shop
...
EDIT:
I am working on the local computer, simulating distant connections. Thus I use 'file' protocol and not 'http'.
Am I missing something? Thanks for any help you would provide
I tested out again my 1st solution since it was the most promising:
java -cp ~/NetBeansProjects/RMIServer/dist/RMIServer.jar -Djava.rmi.server.codebase="file:/home/myuser/netbeansprojects/rmiserver/dist/rmiserver.jar file:/home/myuser/netbeansprojects/rmiserver/dist/lib/rmiresource.jar" rmiserver.Shop
It still failed.
Then I tested out on Windows:
Setup the rmiregistry with an empty classpath (and cd to the java/bin directory)
set CLASSPATH=""; export CLASSPATH
start rmiregistry
Launch the server with an equal command as before (moduo the Win env changes)
java -cp c:/NetBeansProjects/RMIServer/dist/RMIServer.jar -Djava.rmi.server.codebase="file:/c:/netbeansprojects/rmiserver/dist/rmiserver.jar file:/c:/netbeansprojects/rmiserver/dist/lib/rmiresource.jar" rmiserver.Shop
And... It worked!
I cleaned-up/rebuilt the solution both on Linux & Windows and it is still not working on Linux and working on Windows... I use the same Netbeans version on both!
Can someone explain that to me? I am using the JDK 6 on Linux & JDK 7 on Windows: would that have an impact?
A file: codebase can't work out of the local machine. You need to use HTTP. You could possibly use a file: URL pointing to a shared directory, such that the URL makes sense at a client, but this won't work outside the LAN.
Unless you are using the codebase feature, the RMI Registry needs access to the shared classes via its classpath: rmiregistry -J-Dclasspath=... It's simpler to use LocateRegistry.createRegistry(), then it's in the same JVM as your remote objects and uses the same classpath of course.
Related
I am trying to program in java using both jdbc and rmi but i am not able to to run the program without exporting classpath for stub for e.g. if my stub is located "home/java" i need to export it using "export CLASSPATH="home/java" and if i don't export it is throwing following exception :
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: GImplement_Stub
Now the problem is when i am exporting the path for the stub may be mysql database path is getting overwritten and it is throwing :
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
though if i am not exporting any path other jdbc programs are working fine.
How can this be resolved?
You can have multiple entries in the CLASSPATH variable and the -cp command-line argument separated by the colon character :.
However I would strongly recommend maven for this job, as it makes building way, way easier than juggling classpaths by hand...
I just downloaded some java applets from this site: http://www.surendranath.org/Apps.html to run them offline on my laptop. Take for example this one: http://www.surendranath.org/Applets/Oscillations/Lissajous/Lissajous.html
By inspecting the source code I downloaded the file: wget http://www.surendranath.org/Applets/Oscillations/Lissajous/LissajousApplet.class
Then I tried it to run it on my ubuntu box via gappletviewer-4.8 -code LissayousApplet.class
However I got the following error message:
Exception in thfully qualifiedread "main" java.lang.NoClassDefFoundError: loaded class LissajousApplet was in fact named Applets.Oscillations.Lissajous.LissajousApplet
at java.lang.VMClassLoader.defineClass(libgcj.so.14)
at java.lang.ClassLoader.defineClass(libgcj.so.14)
at java.security.SecureClassLoader.defineClass(libgcj.so.14)
at java.net.URLClassLoader.findClass(libgcj.so.14)
at java.lang.ClassLoader.loadClass(libgcj.so.14)
at java.lang.ClassLoader.loadClass(libgcj.so.14)
at java.lang.ClassLoader.loadClass(libgcj.so.14)
at gnu.classpath.tools.appletviewer.Main.createApplet(libgcj-tools.so.14)
at gnu.classpath.tools.appletviewer.StandaloneAppletWindow.<init>(libgcj-tools.so.14)
at gnu.classpath.tools.appletviewer.StandaloneAppletViewer.createWindows(libgcj-tools.so.14)
at gnu.classpath.tools.appletviewer.StandaloneAppletViewer.<init>(libgcj-tools.so.14)
at gnu.classpath.tools.appletviewer.Main.main(libgcj-tools.so.14)
So what is the correct way to run this applet offline? Running it online within my browser and the icetea plugin works. However I need a way to run it offline.
Edit
Trying the fully qualified class-name results in:
gappletviewer-4.8 -code Applets.Oscillations.Lissajous.LissajousApplet.class -codebase codebase="../../../"
WARNING: CURRENTLY GAPPLETVIEWER RUNS WITH NOSECURITY MANAGER.
THIS MEANS THAT APPLETS YOU LOAD CAN DO ANYTHING A JAVA APPLICATION
THAT YOU DOWNLOAD AND RUN CAN DO. BE *VERY* CAREFUL WHICH APPLETS YOU RUN.
DO NOT USE GAPPLETVIEWER ON YOUR SYSTEM IF YOUR SYSTEM STORES IMPORTANTDATA.
THIS DATA CAN BE DESTROYED OR STOLEN IF YOU LOAD A MALICIOUS APPLET.
[press 'c' or 'C' to continue or anything else to quit]
c
java.lang.ClassNotFoundException: Applets.Oscillations.Lissajous.LissajousApplet not found in gnu.classpath.tools.appletviewer.AppletClassLoader{urls=[file:/home/null,file:/home/], parent=gnu.gcj.runtime.SystemClassLoader{urls=[file:./], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}}
at java.net.URLClassLoader.findClass(libgcj.so.14)
at gnu.classpath.tools.appletviewer.AppletClassLoader.findClass(libgcj-tools.so.14)
at java.lang.ClassLoader.loadClass(libgcj.so.14)
at java.lang.ClassLoader.loadClass(libgcj.so.14)
at gnu.classpath.tools.appletviewer.Main.createApplet(libgcj-tools.so.14)
at gnu.classpath.tools.appletviewer.StandaloneAppletWindow.<init>(libgcj-tools.so.14)
at gnu.classpath.tools.appletviewer.StandaloneAppletViewer.createWindows(libgcj-tools.so.14)
at gnu.classpath.tools.appletviewer.StandaloneAppletViewer.<init>(libgcj-tools.so.14)
at gnu.classpath.tools.appletviewer.Main.main(libgcj-tools.so.14)
Try using the fully qualified classname
gappletviewer-4.8 -code Applets.Oscillations.Lissajous.LissajousApplet.class -codebase codebase="http://www.surendranath.org/"
Read: gappletviewer Man page
First of all, I have a basic example of OpenCV running in a main method.
However, if I use OpenCV in a Spring Web Controller, an error is thrown.
I am getting an UnsatisfiedLinkError when running the following code inside a Tomcat Server, within STS (Spring Tool Suite), and have boiled the problem down to the following code:
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
CascadeClassifier cascadeClassifier = new CascadeClassifier();
The run configurations of both the server and the "main" application contain the VM Arguments pointing to the OpenCV DLLs:
-Djava.library.path="C:\opencv\build\java\x64;C:\opencv\build\x64\vc10\bin"
For reference, I have also included the pertinent bits of the stacktrace below:
org.springframework.web.util.NestedServletException: Handler processing failed;
nested exception is
java.lang.UnsatisfiedLinkError: org.opencv.objdetect.CascadeClassifier.CascadeClassifier_0()J
...
Caused by: java.lang.UnsatisfiedLinkError:
org.opencv.objdetect.CascadeClassifier.CascadeClassifier_0()J
at org.opencv.objdetect.CascadeClassifier.CascadeClassifier_0(Native Method)
at org.opencv.objdetect.CascadeClassifier.<init>(CascadeClassifier.java:38)
at com.immersion.test.controllers.SimpleController.createClassifier(SimpleController.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
Note: I have read in several StackOverflow threads that the main cause of the UnsatisfiedLinkError is the missing System.loadLibrary(Core.NATIVE_LIBRARY_NAME) call. This is clearly not the case here, since it is being called just above where the exception is thrown.
Same thing here.
I try what Dylan said, but did not work here.
But I added "C:\opencv\build\java\x64;C:\opencv\build\x64\vc10\bin" on my PATH variable. On my sys variables.
ps: I'm using windows.
It turns out that the default run configuration to start a Tomcat server within STS/Eclipse is essentially just a launcher for Tomcat.
This means that any VM Args that are added to the Tomcat 'run configuration' will not be transferred to the actual Tomcat instance.
On looking in tcruntime-instance.bat within the Tomcat directory (this is what ends up creating the tomcat java instance), we can see that simply by adding our intended VM Args to the JAVA_OPTS environment variable, the dlls will be available to Tomcat.
TL;DR:
So.. Simply add the the locations of the OpenCV binaries to your JAVA_OPTS environment variable:
-Djava.library.path="C:\opencv\build\java\x64;C:\opencv\build\x64\vc10\bin"
For more information on setting JAVA_OPTS for Tomcat, see this SO question.
I'm using Tomcat and PHP5 with JavaBridge. I have bridged PHP and Java so I can screencap web pages within PHP. This was working on another server but after moving to a new server I can not get it working, so I'm reaching for straws here.
require_once("http://localhost:8080/JavaBridge/java/Java.inc");
java_autoload("/web/sites/madfrog/domain.com/cron/bin/html2image.jar");
$JavaHTML2Image = new Java("com.elance.proposal.html2image.client.MainBridge");
It should have loaded all of the project html2image.jar when the script _autoloaded it, however when you create the new Java object I get the error
Class Not Found: Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: CreateInstance failed: new com.elance.proposal.html2image.client.MainBridge. Cause: java.lang.ClassNotFoundException: com.elance.proposal.html2image.client.MainBridge
I asked the guys over in Java and they said I needed to put the jar file in the lib so Java could find it, so I dumped it into Tomcat's webapps folder an into /usr/share/java. But that did nothing. With that said the PHP has a direct reference to it, so it should be loaded.
I'm at a lost after two days. any help is appreciated!
Which version of Tomcat do you use?
For Tomcat 6 or Tomcat 7 put the jar either in ${tomcat.home}/lib or in ${tomcat.home}/webapps/${your.war}/lib
While tomcat.home is your tomcat installation directory. And your.war is the name of your war file.
Created a Java application to upload documents via CIS (Content Integration Suite) to a storage application. The app runs successfully in RAD, but as a executable jar in a unix environment, getting a NoClassDefFoundError. I can not find the class on my local machine and there are not references to the class on the internet.
The manifest contains that class path for the needed jar files and the main class.
Can anyone help?
Fri Sep 04 16:47:25 EDT 2009 : StandardBatchApplication startup() completed.
java.lang.NoClassDefFoundError: com.stellent.cis.support.spring.ResourceHelper
at com.stellent.cis.common.classloader.IsolatedJarClassLoader$TemporaryF
at com.stellent.cis.common.classloader.IsolatedJarClassLoader$TemporaryF
at com.stellent.cis.common.classloader.IsolatedJarClassLoader$TemporaryF
at com.stellent.cis.common.classloader.IsolatedJarClassLoader.<clinit>(I
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:196)
at com.stellent.cis.impl.CISApplicationFactory.getCisClassloader(CISAppl
at com.stellent.cis.impl.CISApplicationFactory.getCisApplication(CISAppl
at com.stellent.cis.impl.CISApplicationFactory.initialize(CISApplication
at com.lowes.ipt.edi.processor.CISApp.initialize(CISApp.java:48)
at com.lowes.ipt.edi.processor.EDItoEDAMUploadProcessor.main(EDItoEDAMUp
Caused by: java.lang.ClassNotFoundException: com.stellent.cis.support.spring.Res
at java.net.URLClassLoader.findClass(URLClassLoader.java:496)
at java.lang.ClassLoader.loadClass(ClassLoader.java:631)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:597)
... 11 more
Update: There is only one jar file I have that deals with CIS. I have looked in the jar and there is no class within. I am unfamiliar with any other RAD default classes that have CIS classes. This is not only happening for this class but also for a class that is contained in the webservices.jar. I can see the class and it is part of my class path because when I remove the Jar from the path, it complains about another missing class. When I place it back in my path, it gets further in the program and gives the same error.
The missing class is probably in some JAR file that is installed on your local machine and not on the remote machine. Or more likely - it is installed in the remove machine in a different location then in your local machine (which is expected if the remote machine is a Unix machine and your local is a Windows box).
The classpath set in the MANIFEST.MF file in the JAR that you build must specify the classpath for finding all related JARs on the remote machine - you have to find where that JAR is installed and then add that path to the manifest classpath. JARs in Unix machines are often installed in /usr/share/java but I can't tell you more then that because I'm not familiar with CIS and I don't know what JAR files it normally distributes.
The issue was caused by the permissions on the tmp directory in UNIX. The CIS API uses the tmp directory to create and store needed files/classes for execution. Because I was running the process under my own ID, it was unable to access the tmp files that were created by the wsadmin. To resolve the issue, the process has to be ran as wsadmin.