jnativehook build failed jni.h not found - java

I have been trying to build jnativehook from source. I am using windows 7. I went through all the stages described on the website. Including change the environment variables Currently I am getting a build failed from the command prompt.
I have pasted it below.
Im not sure where the jnativehook files where supposed to extraxted too, so I have tried building the file while it is in different locations including the root directory, the java directory and inside the java folders.
I checked if jni.h is anywhere in the jnativehook (jhook) files and it isnt but there is a folder called jni one step up.
There is jni.h file in the java directory but it doesnt say anywhere that I have to move and files out of java to jhook directory.
Does anyone know if it supposed to extracted to specific place?
Also does anyone know what this error means and how to solve it?
Any help appreciated
:
[apply] C:\jhook\src\native\common/NativeErrors.h:36:17: fatal error: jni.h
: No such file or directory
[apply] compilation terminated.
[apply] gcc.exe: Files\Java\jdk1.7.0_07\include: No such file or directory
[apply] gcc.exe: Files\Java\jdk1.7.0_07\include\win32: No such file or directory

Try to use other versions of jdk such as jdk1.6.0
Hope this helps.

Its because you installed java to a location with spaces in it. This shouldn't be a problem in version 1.2 or the trunk. If you need to compile 1.1, escape the space with a \ or two in the java.include property. You can set that in the build.properties file.

Related

Running a java project in terminal with multiple .java files (multiple attempts described inside)

I have been doing a coding exercise inside the IntelliJ IDEA Community Edition 14 IDE, using OpenJDK.
The project is split over 4 .java files all in the same package.
My end goal is to run this in the terminal/bash (I use System.console().readLine() which doesnt play nicely in the IDE's console).
I've tried navigating to the directory where these 4 files reside (they all reside in the same dir) and tried:
javac -classpath . BibliotecaApp.java Book.java BookManager.java LibraryDB.java
This creates 4 corresponding .class files fine.
The Main is in bibliotecaApp.java/class, so I try run it by:
java BibliotecaApp
But I get the error
Exception in thread "main" java.lang.NoClassDefFoundError: BibliotecaApp (wrong name: com/twu/biblioteca/BibliotecaApp)
Plus about 13 lines of specifics.
Now googling this error seems to be a class path problem, and this is where I get stuck.
From places I've read, usingecho $PATH gives me:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
This is still from the directory of the .java files above.
That path means nothing to me. I have no idea what it is or what it does, or what even a classpath is! Theres alot of resources out there on setting a classpath, but they aren’t helping me because I don't know what it's meant for.
That was a dead end for me. I tried to create a .jar instead using IDEA's Build Artifacts as seen HERE. It created a .jar file but when I navigate to that directory and try run it via:
java -jar biblioteca_jar
I get
Error: Invalid or corrupt jarfile biblioteca_jar
Another issue is that in the file explorer, the file actually comes out as biblioteca.jar, but ls on that dir shows biblioteca_jar. Is that normal?
The code is on my GitHub if that helps anything
https://github.com/botagar/twu-biblioteca-JohnGeddes
Based on your compiler step, change this
java BibliotecaApp
to
java -cp . BibliotecaApp
Which will add the current directory to the classpath for the java runtime environment. See also the Oracle Technote Setting the Class Path.
A jar file is a kind of zip, and should have a .jar extension. So this
java -jar biblioteca_jar
should probably be
java -jar biblioteca.jar
And you can check if the file is valid with any zip archive reader. Including jar itself,
jar tvvf biblioteca.jar
Edit
Based on your comments below,
cd ~/Documents/ThoughtWorks Uni/TWU_Biblioteca-master/src/
and then
java -cp . com.twu.biblioteca.BibliotecaApp

'Java' is not recognized as an internal or external command and program running

This is probably the most frequent question you get in the world, and I apologize, but I have to ask anyway. I recently downloaded the newest version of java (1.7.0_45-b18), and I recently finished making a small program for a local community of mine in Eclipse. I'd like to share it with them so anyone can run it by clicking it, but opening the jar file just hasn't seemed to work for me.
I attempted opening it with command prompt by using
java -jar StatCalc.jar
but it always tells me
'java' is not recognized as an internal or external command, operable program or batch file.
I looked up many solutions for this, the most common being to change your Path. So I went to the environment variables, and changed the path to
C:\Program Files (x86)\Java\jre7\bin\java.exe
But it still gives me the same result. Only when the directory is exactly in java, and the jar file is in the java bin folder can I run the program. I wan't any person to be able to run this.
How do I get command prompt to work and allow this program to be run by both me and other people in this small community?
The path shouldn't contain the executable itself - just the directory containing java.exe. So you want this on your path:
C:\Program Files (x86)\Java\jre7\bin
Restart your console, check that the path is correct (just run path and look at the output) and all should be well.
Note that if you're going to be developing Java code, you should probably use the JDK path instead of the JRE path. For example, my path contains c:\Program Files\Java\jdk1.7.0_17\bin. (Yes, I need to update :)
I hope you do not have changed your PATH variable, only added (...);C:\Program Files (x86)\Java\jre7\bin\ (on UNIX systems, use a colon (:) as the separator instead) at the end. Otherwise, you will have many issues with all other Windows applications. Note that you must add the folder that contains java.exe, not the path to the executable itself.
Then, try to restart your Command-Line or even your Windows session.
Optional: You may set JAVA_HOME to specify JDK location. See this link.
Here you have a tutorial of oracle for setting the path
http://docs.oracle.com/javase/tutorial/essential/environment/paths.html
C:\Program Files (x86)\Java\jre7\bin --> This would be your PATH variable.

Java jar running

Any idea why
java -jar jarname.jar
works, but double clicking the jar gives a
"Could not find the main class:"
error? Manifest is correctly placed and double clicking was working until recently, but all of a sudden it gives that error. I'm not sure what changes I made though.
EDIT:
The command I used to create the jar was (in cmd):
jar cfe jarname.jar files.Main *
Main is part of the package files.
Add this entry in your manifest file:
Main-Class: com.abc.def.YourMainClass
Hope this'll help!
Some time ago I had a comparable problem. And it was caused by multiple JDK/JRE versions on my machine.
What is used by double-clicking differs from what is used by typing jar in a shell.
I think JarFix could help. Or you lookup what is associated with double-click in the file-associations (reinstall java might also help)
It seems to have been some weird compiler version problem. When I complied the class files using an older version of java, then compiled it into a .jar file, it was able to run.

Matlab cannot start, error: "Cannot locate com/mathworks/jmi/OpaqueJavaInterface class"

Hey dear all, I try to start Matlab(version 7.6.0 R2008) and received the error: "Cannot locate com/mathworks/jmi/OpaqueJavaInterface".
I did some googling, and it seems this is related with the jre Matlab is using.
Here is what I have done:
I checked my java project and found that my source lookup path is: "c:\Program Files\Java\jre6", so I added one MATLAB_JAVA environment variable as follows in the advance tab in system property:
MATLAB_JAVA C:\Program FIles\JAVA\Jre6
Still I received this error, How can I solve it?
thank you for your help.
BTW: how can I check this newly added environment variable?
That sounds like your MATLAB installation is corrupted - it could be that one of the files is missing (in this case, I believe that java class would reside in <matlab>/java/jar/jmi.jar). You should also check <matlab>/toolbox/local/classpath.txt to see if that has been modified.
It may be simplest to re-install MATLAB.
Your solution is incorrect: there's no .class file named com.mathworks.jmi.OpaqueJavaInterface in that directory, not in an JAR file it contains.
It's a MATLAB class, so you should find it in a JAR file that ships with MATLAB. Find out which one and add it to your CLASSPATH for Java.
There are lots of places that tell you how to set CLASSPATH if you don't know how.
Either you didn't create an Environment Variable or your java folder has the wrong name in your program files for Matlab.

I am having problems in running my Java program

I'm a beginner in Java so this question might seem a little stupid, my JDK and JRE are installed in C:\program files. I write my program and save it in in my folder, G:\start.
Now my program compiles without any error (the .class file is also generated), but when I run my program it says "unable to locate G:\lib\amd64\jvm.cfg", so I copy the 'lib' folder from my JDK folder and paste it in G:. Again program compiles without any error, but when I run it, it gives me a new error saying "unable to locate G:\bin\server\jvm.dll", so I copy the 'bin' folder to g:, but now when I run, it gives me the same error again "unable to locate G:\bin\server\jvm.dll". Where am I going wrong?
Create an environment variable called JAVA_HOME and point it to the bin directory of your Java installation. Also add the same directory to your PATH variable. This should solve your problem.
PS: JAVA_HOME may not be required, but it will help if you have tomcat and stuff installed.
try to save it as a .jar, go to your cmd and use:
java -jar G:\bin\server\jvm.jar
this should work.
The best advise I can give you is to download an IDE to get started. BlueJ is an IDE aimed at getting people started using java and is used in many universities world wide.
take a look at www.bluej.org and you should be up and running in seconds.
Karl

Categories

Resources