class file for javax.serverlet.GenericServlet not found - java

I have stuck in the class->header file for couple days!
I have tried on jni on Client by http://netbeans.org/kb/docs/cnd/beginning-jni-linux.html and http://ringlord.com/jni-howto.html. And it succeeded in return "hello JNI C++" from JNI's (.cpp)file. Here are my steps:
create native function and in client.java
clean &build this client.java on Netbeans IDE, then result a client.class file
javah –jni [package].[classname]
create a dynamic library C++ project as first reference does, and put client.h into source file, and put some hello code into (.cpp)file ---> It works!
However, I tried to do the same thing on the servlet side and it's not working
Servlet.java->Servlet.class : ok!
Servlet.class->Servlet.h: fail!!!!
Error : cannot access javax.servlet.GenericServlet
class file for javax.servlet.GenericServlet not found
The following are solutions I have found and tried so far,
check the package name
sudo gedit /etc/profile,sudo gedit .bashrc, sudo /etc/environment; add JAVA_HOME & CLASSPATH on them, and source them to update, then echo $JAVA_HOME, echo $CLASSPATH to verify
download servlet-api-6.0.14.jar & servlet-api-5.0.16.jar from http://www.jarfinder.com/index.php/java/info/javax.servlet.GenericServlet
,and add above two (.jar) by netbeans IDE->server->property->libraries->Add JAR
Please tell me how to figure it out this issue, thank you very much!!Btw, I am using hessianServlet

NativeWrapper.java (you run javah only on this class)
class NativeWrapper {
// either
static {
System.loadLibrary("MyOpenCVNative");
}
// or
public NativeWrapper() {
System.loadLibrary("MyOpenCVNative");
}
public native void callNative();
}
MyServlet.java
class MyServlet extends javax.servlet.GenericServlet {
private NativeWrapper nativeWrapper = new NativeWrapper();
public void someServletMethod() {
nativeWrapper.callNative();
}
}

Related

How do I compile my main Java program on the command line when it includes an external java package?

I'm a relative Java newbie so apologies if the question appears somewhat basic. I've googled high and low for an answer here and I'm not finding anything that's helping.
Problem:
Whilst I'm able to integrate external packages into my Java programs from an IDE environment, I am trying to do run a very basic program from the command line that calls on a separate, basic package file that I have written - and am simply doing all this as I want to have a bottom-up understanding of how package files are related to a main program by Java.
I have a program that sits on my desktop named MyProgram.java:
import org.somepackage;
public class MyProgram {
public static void main(String arguments[]) {
System.out.println("Programme up and running...");
Human myHuman = new Human();
myHuman.scream();
}
Still on the Desktop, I then have another folder which I've named src, inside of which I have created the necessary subfolders corresponding to the package name, i.e. ./src/org/somepackage - and in this location, I have the Human.java file which defines the Human class with the following contents:
package org.somepackage;
public class Human {
public void scream() {
System.out.println("I exist!!");
}
}
I then created a classes folder, again on the Desktop, and ran the following compile command on the command line:
javac -d ./classes/ ./src/org/packagename/Human.java
This ran fine and created - as expected - the Human.class file within the ./classes/org/packagename/ location.
However, where I fall down is when I then try to compile MyProgram.java on the command line, i.e.
javac -cp ".:./classes/" MyProgram.java
As you'll see, my class path contains a reference to the current location (".") for the MyProgram.java file, and it contains a reference to the classes folder ("./classes/") which is the base location for the org.somepackage package inside whose subfolders (./classes/org/somepackage/) on can find the Human.class file.
At this stage, I was simply expecting the java engine to compile MyProgram.java into the program MyProgram.class - but, instead, I get an error:
MyProgram.java:1: error: package org does not exist
I've been following the instructions listed here:
https://www3.ntu.edu.sg/home/ehchua/programming/java/J9c_PackageClasspath.html
and I don't appear to be deviating from the instructions - yet I'm unable to locate an explanation on Stackoverflow or anywhere else as to a possible reason for this compile failure. If anyone has an idea, your help would be very much appreciated.
Thanks,
Your mistake is here
import org.somepackage; <--
public class MyProgram {
public static void main(String arguments[]) {
System.out.println("Programme up and running...");
Human myHuman = new Human();
myHuman.scream();
}
you forgot to import class actually, you need to write this name
import org.somepackage.Human; import all package content import org.somepackage.*; or write full qualified name of class in your code
org.somepackage.Human myHuman = new org.somepackage.Human();
myHuman.scream();
correct mistake:
import org.somepackage.Human;
public class MyProgram {
public static void main(String arguments[]) {
System.out.println("Programme up and running...");
Human myHuman = new Human();
myHuman.scream();
}
after that compile your Human.java by this command:
javac -d classes Human.java
and MyProgram.java
javac -d classes -cp "classes" MyProgram.java
and run MyProgram by
java -cp "classes" MyProgram

Make an extendable java program

I'm making a java command prompt (like the Windows CMD).
But I want to make it possible for other developers to add some commands to my program by putting their own *.jar files in a folder called "extensions".
I know this is possible because Minecraft can be modded with MC Forge like that (by putting your mod jars in a folder called "mods")
Example:
public class myExtension extends Extension {
//A method called by my program
#Override
public void onLoad() {
//Register a command in the main class...
Command cmd = Commands.registerCommand("hello");
//Add an event listener...
cmd.addEventListener(new CommandEventListener() {
public void onCommandExecute() {
//Print "Hello World !" to console when the command is executed...
Console.getConsole().print("Hello World !");
}
});
}
}
So now the guy who made this should be able to export this program as a jar file and put it in the "extensions" folder. But how can I make that my program register this jar as an extension ?
I you know the answer the please write it down ! Thank you !

Connecting java with constraint logic programming

i'm trying to connect java with constraint logic, i'm using netbeans for java and eclipse 6.1 for constraint logic, but when i'm trying to run the code there is an exception appears java.lang.IllegalArgumentException: Missing eclipse.directory property
i've used a tutorial that explain how to connect them, which says that After compilation, to run the program, start the Java interpreter as you normally would but before the name of the class, supply the command line option
-Declipse.directory=<eclipse_directory>
and i don't know where to place it in netbeans
here is the code
import com.parctechnologies.eclipse.*;
import java.io.*;
public class eclipseConnection {
public static void main(String[] args) throws Exception
{
try{
EclipseEngineOptions eclipseEngineOptions = new EclipseEngineOptions();
EclipseEngine eclipse;
eclipseEngineOptions.setUseQueues(false);
eclipse = EmbeddedEclipse.getInstance(eclipseEngineOptions);
eclipse.rpc("write(output, 'hello world'), flush(output)");
((EmbeddedEclipse) eclipse).destroy();
}catch(Exception e){
System.out.println(e);
}
}
}
You can add the property definition in the 'Run' menu: Run > Set Project Configuration > Customize.... Make sure you enter the property definition -Declipse.directory=<eclipse_directory> in the VM Options section.
Let's use the command line and the example source file Quicktest.java.
Copy the example:
copy "C:\Program Files\ECLiPSe 6.1\doc\examples\JavaInterface\Quicktest.java" .
Compile it:
javac -classpath "C:\Program Files\ECLiPSe 6.1\lib\eclipse.jar" QuickTest.java
Run it:
java -classpath ".;C:\Program Files\ECLiPSe 6.1\lib\eclipse.jar" -Declipse.directory="C:\Program Files\ECLiPSe 6.1" QuickTest
hello world

Javah work some class, but doesnt work some class

There are a alot of questions about javah, but I couldnt find any solution for my issue for 3 day.
My java file work normally and no error.
I copied my java file "I2CInterface.java" to "jdk/bin" directory.
Then "javac I2CInterface.java" the I2CInterface.class created succesfully.
But "javah -jni I2CInterface" is not work the header file cant created. The error is "class not found" I try with classpath but not work. I set my environtmental and add path C:\Program Files\Java\jdk1.8.0\bin. No work.
That is interesting javah work on some class and it can create header. But on this class and some class not work.
The problem is about java file? My java file below.
package com.multitek.ipintercomflatunit;
public class I2CInterface {
private static native int i2cwrite(byte[] data);
private static native byte[] i2cread(int data_len);
public static int write(byte[] data) {
return(i2cwrite(data));
}
public static byte[] read(int data_len) {
return(i2cread(data_len));
}
static
{
System.loadLibrary("i2cinterface");
}
If the class is in a package, say xxx, the correct command line will be
javah xxx.I2CInterface
I copied my java file "I2CInterface.java" to "jdk/bin" directory
Why? There's no need to do that. Don't pollute the Java installation directory with your own stuff. Leave it where it was and compile it there. Adjust your PATH if necessary so you can execute the JDK tools.

How do I run a Java application from the command line when it is in a package? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
package in .java file makes class file unuseable
My Hellow World runs fine.
But as soon as I add a package reference I cannot run it from the command line:
package pv;
public class hcw2 {
public static void main(String[] args) {
System.out.println("Hello Cruel World.");
}
}
compiles fine, then I expect to use java pv.hcw2 to run it, as:
>java pv.hcw2
>Error: Could not find or load main class pv.hcw2
I have also tried just java hcw2, to no avail.
Running in the same directory as the original which runs. Running on Windows 7 64b.
Thank you
You should have a folder called pv under which your file hcw2.java should lie. The folder pv is nothing but your package. Then outside the directory you may issue a javac command as shown below followed by java.
braga#braga-laptop:~$ javac pv/hcw2.java
braga#braga-laptop:~$ ls pv
hcw2.class hcw2.java
braga#braga-laptop:~$ java pv.hcw2
Hello Cruel World.
You have to keep your class in the folder named your package. so for :
package pv;
public class hcw2 {
public static void main(String[] args) {
System.out.println("Hello Cruel World.");
}
}
The hcw2.java should be kept like pv\hcw2.java
once you compile successfully there should be the class file in same folder like :
pv\hcw2.class
While running you have to change directory to the base directory. so if your directory structure like : d:\java\pv\hcw2.java
then
Change dir to d:\java>
Run the java command there with the package name. So :
d:\java> java pv/hcw2 or
D:\java>java test.Test
Your java class needs to be inside a subdirectory called pv. So:
mkdir pv
mv hcw2.java hcw2.class pv
then you can run
java pv.hcw2

Categories