I have a program in java I run through a service I wrote who uses JNI to start a JVM and launch the program. The program dynamically loads other jni dlls when it needs to.
The problem is that if i run the service as NetworkService, the jni dlls load fine, but if i run it as a LocalService (which has more privileges and should be able to access the network) I get a java.lang.UnsatisfiedLinkError: C:\Netstar\build_0704_24_02\lib\JobExecutable.dll: The specified procedure could not be found
Some more details:
I run the service from a windows share, but before it runs java it copies all the jars and dlls locally. I tried using dependancy walker but it led me nowhere. I also made sure there are no network paths in my Path environment variable. One of the java directives is -Djava.library.path=C:\Netstar\build_0704_24_02\lib
Thanks for the help
Related
It could be basic java question. can we run java on my machine pointing to the other machine's JAVA Path?
Example: I have a test.class file in my machine (system-A). But my machine does not have java(no JDK or No JRE). Shall I run this test.class by using other system's java path?
Java does not need to be "installed" to function correctly. At least not the core Java, though some tools of Java may need extra setup.
If your machine can see a Java home directory on a network share, you can simply run java.exe directly from that share.
Example: If you have access to a network share like \\Server1\Software and it has a Java installed in directory Java\jdk1.8.0_65, then you can run your code like this:
\\Server1\Software\Java\jdk1.8.0_65\bin\java.exe -cp . test
This of course assumes that test.class exists in the current working directory, and that the class is in the unnamed package.
Using the above will work, even without setting up JAVA_HOME or CLASSPATH.
No, you must have access to a java executable to run java. The original post states that there is no java runtime environment on the computer.
If, however, you have access to java.exe then you can execute that java.exe
I have a C++ application which deals with the image processing (by OpenCV 2.4.10). When I call this program from the command line or from another local Java application with the following code snippet:
ProcessBuilder pb = new ProcessBuilder(_IMG_PROC_ENGINE_PATH, imgPath);
pb.redirectError();
Process p = pb.start();
exitCode = p.waitFor();
everything is working and the CPP-application returns the correct outcome.
But when I call the same CPP-program on the same PC with absolutely the same user account from Java Tomcat Servlet, I get an error return code -1073741515 from the CPP. After some searching, I discovered that this code error occurs when there is a problem with an external library loading. And it's true if I remove the OpenCV libraries usage from my C++ program, everything is OK.
Why, when I execute the program locally from the command line or from another local Java application, everything is OK, but when I call the same C++ EXE from the Java Servlet, I get an error of library loading? How can I fix the issue?
P.S. There is no antivirus or any other security software (e.g. Internet Security, EMET, etc.) on the PC, which can interrupt the process.
I think the environment variables are somehow different when running in a Tomcat Servlet. That can explain why you program cannot load runtime library.
I would try to copy necessary OpenCV runtime library files to the same directory as the C++ executable.
Is anyone having a problem running a Windows Service with JavaExe, and is there a solution?
The JavaExe examples all work except for the Service examples, Example3, Example5, and Example23.
In each case, the Windows Service gets created, but any attempt to start the service brings a popup error message:
"The system cannot find the file specified."
There is a registry entry for the serivce which contains the following:
Name: ImagePath
Type: REG_EXPAND_SZ
Data: "\JavaExe\JavaExe\doc\examples\3 - Service\Example3.exe" __RunService__
If I run Example3.exe from a command line with the argument __RunService__, then a Java process starts and runs briefly before crashing.
The examples are all self-contained in the JavaExe download, so it's hard to see how there could be missing libraries.
Background: JavaExe (http://devwizard.free.fr/html/en/JavaExe.html) appears to implement a sound approach to allowing a Java application program to be invoked from another Java program running as a service. Windows prevents services from accessing the desktop, so JavaExe sets up a socket connection between the service and the application Java program, each running as a User process, as outlined here:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683502(v=vs.85).aspx
Windows 7 x64 (but it fails in the same way on XP [SEE UPDATE BELOW])
Java version 1.7.0_45
--
UPDATE:
The developer replied to my email and advised that 32-bit and 64-bit Java versions were being confused.
I straightened this out. The Example3 Service, run from the .exe and .jar files obtained from the
JavaExe .zip download (which are all 32 bit by default), now run correctly on WinXP (x86).
For x64 machines, it is necessary to recompile the jar files using the package's compilx64.bat script.
(And to use the x64 versions of JaveExe.exe as stated in the documentation.)
I did these things but the Example3 service still fails to start, with the error,
"The system cannot find the file specified."
The .jar files built from compilx64.bat are mostly identical to the x86 versions, but a few
contain .class files that are a few bytes larger. I assume that the code must therefore be referring to native libraries? And maybe some are not found? But which ones?
When I type sc qc Example3 I get:
TYPE: : 10 WIN32_OWN_PROCESS
START_TYPE: 2 AUTO_START
ERROR_CONTROL: 1 NORMAL
BINARY_PATH_NAME : "[...filepath...]\JavaExe\JavaExe\doc\examples\3 - Service\Example3.exe" __RunService__
LOAD_ORDER_GROUP: 0
DISPLAY_NAME: JavaExe : Example3
DEPENDENCIES: eventlog
SERVICE_START_NAME: LocalSystem
Answer:
The filepath to the Example3.exe was on a network drive.
To get a Windows Service to run from a network drive is either impossible or requires considerable contortions. See for example,
Map a network drive to be used by a service
When I moved everything to the local C: drive, it worked.
Thank you to bb67 for providing the hints that led to figuring this out.
When I work with JAI from the Eclipse (all the classes specified)
it works very fine, but when I bundle everything in a jar and make a shell script file from that and try to run that script I have a problem with javax.media.jai.OperationRegistry
looking for a initialization file.
Has anyone else seen this problem?
Exception:
java.lang.RuntimeException: Registry initialization file not found.
at
javax.media.jai.OperationRegistry.initializeRegistry(OperationRegistry.java:365)
at javax.media.jai.JAI.(JAI.java:566)
There is something on this page but I was not able to understand.
Any Help?
So the problem is that the JAI jar exported with the Java application do not work on the Linux. We have to explicitly install JAI on the Linux machine for the installed Java application to use.
The one solution that we found out is we exported our Java Application into a jar file and created a installation script, which when run on the Linux machine install the JAI first and after that it install our application.
So this is a one time installation process while installing the application on any fresh Linux machine.
I know this question has been asked/answered several times, but I still couldn't find a solution to this ClassNotFoundException error, because it works on my computer but not on my RasPi (on which I installed OpenJDK7).
My application uses JDBC to access a MySQL database, and that's the main problem. As has been pointed out on lots of websites ([1], [2], [3]), this is, unfortunately, a common problem.
So, I'm using the mysql-connector-java-5.0.8.jar as a driver. My folder structure is something like /src/de/web/project/ I'm calling the main method via java de.web.project.WakeOnLan (which is the main class that starts all other classes etc.) I got the common ClassNotFound exception and therefor added the -cp parameter so I called the project via java -cp .;mysql-connector-java-5.0.8.jar de.web.project.WakeOnLan to add the driver to classpath.
This worked nicely on my Windows computer from command line, but now I want to push this code to my Raspberry Pi and execute it there. As I said, I installed OpenJDK7 there (using apt-get, if this should be important), used SFTP to upload the folder structure and the code to /home/pi/java/ where there is also the ejre1.7.0_10 folder (so the code is now actually in /home/pi/java/de/web/project/).
I now went back to /home/pi/java and entered java -cp .;mysql-connector-java-5.0.8.jar de.web.project.WakeOnLan as I did on my Windows computer, but it refuses to work (I've put the connector in any folder on the way, just in case). When I call this function, I get a long list of hints Java wants to give me which parameters are allowed for java, finally stating: -bash: mysql-connector-java-5.0.8.jar: command not found. I also tried to turn ".;mysql..." around to "mysql...;." which didn't work as well. If I don't include the -cp parameter, my program says "Thread started" and in the next line: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver etc., so the program does indeed start and writes "Thread started" to System.out.
For some reason, it looks like Java on the Pi ignored the second value of the classpath parameter for which I don't see a good reason.
You might just have problem in classpath setting, there is difference for windows and linux
The classpath syntax is OS-dependent. From Wikipedia :
Being closely associated with the file system, the command-line
Classpath syntax depends on the operating system. For example:
on all Unix-like operating systems (such as Linux and Mac OS X), the
directory structure has a Unix syntax, with separate file paths
separated by a colon (":").
on Windows, the directory structure has a Windows syntax, and each
file path must be separated by a semicolon (";").
This does not apply when the Classpath is defined in manifest files,
where each file path must be separated by a space (" "), regardless of
the operating system.