Re: Java JAR files
Teber wrote:
I've a Java library file which is called Klavye.jar. I write a
program which uses this library. This library is in
com.boragungoren.java package. the program looks like this:
Having "java" inside package names is a bad idea. Isn't the whole program
written in Java?
It's also illegal to have 'java' or 'javax' be top-level package names, but
that doesn't apply here.
import com.boragungoren.java.Klavye;
Do you have a class called 'Klavye' inside the JAR, in that package?
What package is 'Main' in? It needs to be in a package.
public class Main {
public static void main(String[] args) {
int k;
long l;
System.out.println("Two number please:");
k=Klavye.intOku();
l=Klavye.longOku();
}
}
the Klavye.jar is in C:\Program Files\Java\jdk1.6.0_03\jre\lib
CLASSPATH is C:\Program Files\Java\jdk1.6.0_03\jre\lib
That classpath will not pull in the JAR - you need to explicitly include JARs
in the classpath, or use the wildcard form.
The CLASSPATH envar is not the best way to set a classpath. Use the
-classpath or -cp options to the command instead.
when compile it says
Main.java:2: package com.boragungoren.java does not exist
import com.boragungoren.java.Klavye;
^
what shall i do
what is wrong with this
You did not include the JAR in your classpath.
rossum wrote:
In Java your package name must match the location of the files for
that package. Your Klavye.jar needs to be in
###/com/boragungoren/java/, which is where the compiler will be
Not even close to correct. The class file needs to be in the correct package
directory *inside the JAR*, not the JAR inside the directory.
looking for it. The error message is telling you that it cannot find
anything at ###/com/boragungoren/java. "###" will vary depending on
where in your directory tree you keep your java programs.
Don't put application JARs in the Java installation directories.
$JDK_HOME/jre/lib is for the JRE, not for application code.
Put the JAR in the class path, not in the package directory.
Read
<http://java.sun.com/javase/6/docs/technotes/tools/findingclasses.html>
--
Lew