If I have all my .java and .class files in one place (i.e. in the default package) then everything is OK and I do all the JNI stuff, etc.
But in this case I have package-ception (lots of directories), my class and Java files are separated in /bin and /src and so on. And I need to generate the header file, but I am getting errors all the time. I tried so many commands, I saw different tutorials. I am already out of options.
So my project is in c://gvk/SEP3 and then the class and Java files with the native methods that I am gonna use are in /bin/CalculatorServer and /src/CalculatorServer
I have all the time run the javah command from the directory where the class file with the native methods is. The commands I tried so far are:
javah -d ./CalculatorServer NativeMethodsCalculator
Error: Could not find class file for 'NativeMethodsCalculator'.
javah -d ./CalculatorServer CalculatorServer.NativeMethodsCalculator
Error: Could not find class file for 'CalculatorServer.NativeMethodsCalculator'.
javah -d c://gvk/SEP3/bin/CalculatorServer -classpath c://gvk/SEP3/bin/CalculatorServer NativeMethodsCalculator
Error: Could not find class file for 'NativeMethodsCalculator'.
javah -classpath c://gvk/SEP3/bin/CalculatorServer -o NativeMethodsCalc.h src.CalculatorServer.NativeMethodsCalculator
Error: Could not find class file for 'src.CalculatorServer.NativeMethodsCalculator'.
javah -jni bin.CalculatorServer.NativeMethodsCalculator
Error: Could not find class file for 'bin.CalculatorServer.NativeMethodsCalculator'.
What you didn't try: go just to /bin/ (not into CalculatorServer) and run
javah -jni CalculatorServer.NativeMethodsCalculator
This is the only way how to run it. Just look at the javah doc. It says "fully-qualified-classname" in the synopsis. "Fully qualified" means full classpath. You were giving it only the classname. It worked for you so far only because you were using a default package, which means that your fully qualified classname was equal to a bare classname.
Option -d and -o doesn't influence the class lookup, only the storage of native result. All the variants you tried do not make any difference to your mistake.
I have all the time run the javah command from the directory where the class file with the native methods is
That's your mistake. You should run it from the directory that contains the outermost package, with the inner packages and their .class files below it. Then you don't need a -d argument or a -classpath argument. Assuming your outermost package is CalculatorServer, you should be in the directory containing CalculatorServer, and the command line required is javah CalculatorServer.NativeMethodsCalculator.
Related
i'd like to run a java class on other folder, i have a mysqlcon.jar on the current path and a PetsGUI.class on ./classes/
when i try to run it by doing
java -cp .:mysqlcon.jar -d classes/PetsGUI
i receive
classes/PetsGUI not found
if i move mysqlcon.jar on classes and type
java -cp .:mysqlcon.jar PetsGUI
on classes/ it runs, so the code is correct. what's the correct command to run it?
So you need the jar file, and the classes directory in the classpath:
java -cp ./classes:mysqlcon.jar PetsGUI
java doesn't expect a file path as argument. It expects the fully quelified name of a class. And that class is then searched on the classpath.
I'm following book HeadFirst Servlets and JSPs.
In an example, to compile the servlet, it uses the command javac -classpath /usr/share/tomcat7/lib/servlet-api.jar:classes:. -d classes src/com/example/web/BeerSelect.java
I don't understand the effect of ":." after classes in this command.
The : is the separator and . stands for the current directory. So it's saying "the class path should contain the jar file '/usr/share/tomcat7/lib/servlet-api.jar' and the 'classes' directory, as well as the current directory."
i am triyng to generate header file for native use (c/c++) from a java file using eclipse.
from the command line i can only reach the javah when i am in this location :
C:\Program Files (x86)\Java\jdk1.7.0_51\bin>
but i cant reference my java class like so :
C:\Program Files (x86)\Java\jdk1.7.0_51\bin>javah -jni com.or.jnihelloworld.nativeclass
because the class located outside of this folder at :
C:\Users\Or Azran\workspace\JniHelloWorld\src\NativeLib.java
and i want to make this file in to a jni folder in :
C:\Users\Or Azran\workspace\JniHelloWorld\jni
how can i do it from command line?
a good toturial will be also great
There appears to be a couple of issues to solve here.
First. I'm not sure that your source code is set up correctly. If indeed your class is com.or.jnihelloworld.nativeclass then it should be in directory: C:\Users\Or Azran\workspace\JniHelloWorld\src\com\or\jnihelloworld\nativeclass.java
However, assuming that the class/directory is correct. The javah command uses -d to specify the output directory, and you can specify the path with -classpath so
javah -classpath "C:\Users\Or Azran\workspace\JniHelloWorld\src\" \
-d "C:\Users\Or Azran\workspace\JniHelloWorld\jni" com.or.jnihelloworld.nativeclass
should put the file where you want it.
Your PATH doesn't include the bin directory of the JDK.
I've just wasted 2 hours trying to do something which I've already done twice before. I can't remember the exact procedure I used the previous two times, but it really shouldn't be giving me this much trouble:
I have a project folder called "BoardGUIv3". I want to produce a header file based on a class called "CANController", with the source located in "BoardGUIv3/src/model" and the class file in "BoardGUIv3/bin/model".
I've done exactly this thing before, but for some reason I can't seem to do this simple, one-line command again.
I'm pretty sure it's something along the lines of
javah -classpath <classpath> src/model/CANController
My classpath should just be the root directory, shouldn't it?
Here is the javah command usage:
{javahLocation} -o {outputFile} -classpath {classpath} {importName}
and it should be used like this for you class:
javah -o "CANController.h" -classpath "C:\pathToYourProjDir\BoardGUIv3\bin" model.CANController
Just correct the path to your classfile with the real path and the package structure if required.
I created a Java project to call a Web service.
It has one Main java file and another class file.
I have used some jar files for HTTP client.
In Eclipse it runs fine.
I need to run the Java program in command prompt by passing some arguments.
In command prompt I went to src folder containing main java and sub class java file and gave the following command
javac mainjava.java
I'm getting following error
mainjava.java:14: cannot find symbol
symbol : class SubClass
here SubClass is my another java class file used to call the web service.
How to run the program by passing arguments?
javac is the Java compiler. java is the JVM and what you use to execute a Java program. You do not execute .java files, they are just source files.
Presumably there is .jar somewhere (or a directory containing .class files) that is the product of building it in Eclipse:
java/src/com/mypackage/Main.java
java/classes/com/mypackage/Main.class
java/lib/mypackage.jar
From directory java execute:
java -cp lib/mypackage.jar Main arg1 arg2
A very general command prompt how to for java is
javac mainjava.java
java mainjava
You'll very often see people doing
javac *.java
java mainjava
As for the subclass problem that's probably occurring because a path is missing from your class path, the -c flag I believe is used to set that.
You can use javac *.java command to compile all you java sources. Also you should learn a little about classpath because it seems that you should set appropriate classpath for succesful compilation (because your IDE use some libraries for building WebService clients). Also I can recommend you to check wich command your IDE use to build your project.
All you need to do is:
Build the mainjava class using the class path if any (optional)
javac *.java [ -cp "wb.jar;"]
Create Manifest.txt file with content is:
Main-Class: mainjava
Package the jar file for mainjava class
jar cfm mainjava.jar Manifest.txt *.class
Then you can run this .jar file from cmd with class path (optional) and put arguments for it.
java [-cp "wb.jar;"] mainjava arg0 arg1
HTH.
javac only compiles the code. You need to use java command to run the code. The error is because your classpath doesn't contain the class Subclass iwhen you tried to compile it. you need to add them with the -cp variable in javac command
java -cp classpath-entries mainjava arg1 arg2 should run your code with 2 arguments