Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems with package and jar 1

Status
Not open for further replies.

rvy2k

Programmer
Jun 29, 2001
39
0
0
US
Hi guys,

I am trying to create a package, jar so that I can reuse it later.

- This is my package

/* START OF CODE */

package com.me.MyClass;

public class MyClass {
public void myMethod() {
/* ... */
}
}

/* END OF CODE */

- I compile it using
% javac -d c:\jdk1.3\jre\classes MyClass.java

- Then I jar it
%jar cf c:\jdk1.3\jre\classes\MyPackage.jar c:\jdk1.3\jre\classes\*.*

- I set the classpath to
c:\jdk1.3\jre\classes\MyPackage.jar

- Then I import it
I set the classpath in the environment variables (i run win2k)
c:\jdk1.3\jre\classes\MyPackage.jar

- But when i compile, i get the following error
MyProgram.java:4: cannot resolve symbol
symbol : class MyClass
location: package me
import com.me.MyClass;
^

Thanks for helping!
 
Hi,

Your class files should be in directory com\me\MyClass\, so jar-package must be created from the root. Lets assume that your sources are located in c:\classes\com\me\MyClass.
You have to create a jar package from c:\classes\
jar cvf ownPackage.jar com\me\MyClass\*.class

As you can see, the path defined in that jar-package will be com\me\MyClass. That's why because it is in package com.me.MyClass and when your jar is in a classpath, that is the path compiler is looking for.

-Vepo
 
Thanks Vepo.

%jar cvf ownPackage.jar com\me\MyClass\*.class

but what if I have:
com\me\MyClasscom\me\MyOtherClass
is there a way to jar both directories?

Thanks again.
 
It half worked:
I jared from the directory com and set the classpath.
I use Visual J++ and when I import the package, it seems to see it because it gives me its selection.

However when I compile, it is still giving me the error that the package com.me doesn't exist ....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top