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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Package & Import in Windows

Status
Not open for further replies.

villain89

Programmer
Feb 18, 2004
5
US
Hi-

I just installed XEmacs & J2SDK1.4.2_03 on my WindowsXP Home Edition.

I decided to test it out using some working java programs I had written before using XEmacs on Unix...but when I try to run them in WindowsXP I am getting loads of errors because Java is not recognizing the package and also not recognizing importing a local folder.

Here's my package and import statements:

package viewController;

import model.*;


The compiler is not recognizing either.

viewController is the directory(folder) that I'm working in and compiling from and model is in viewController.


So the complete path is this:

C:\prog\Minesweeper\viewController
C:\prog\Minesweeper\viewController\model

Anyone know what's going wrong? I'm sure it's a simple problem, but i've been looking online for a couple hours with no luck...so any help would be appreciated!!

thanks
jason
 
goto
C:\prog\Minesweeper and call
javac -d classes viewController\MainFoo.java

if this doesn't work:
Did you define JAVA_HOME?
Is javac in your PATH?
Is there a classpath-Variable defined?
 
I tried the first tip:
javac -d classes viewController\SwingMineSweeper.java

Still didn't work...wouldn't compile and find the java files in the model directory.

I haven't defined "JAVA_HOME" or a classpath-Variable. How should I go about doing this? I set the PATH by right-clicking MyComputer->Properties->Advanced->etc...

Sorry, I created these programs on the university network so I guess they must have done all the setting of the parameters. I always just comiled from XEmacs or Emacs and all the programs worked fine.

I am guessing that you are on the right track though because it looks like most of the errors are from not being able to find the directory/folder and compile the files in that folder necessary to make the programs work.

Any help on how and what I should set the
JAVA_HOME
classpath-Variable
PATH

variables to would be appreciated!
thanks
jason
 
set JAVA_HOME=C:\java\j2sdk1.4.2
set CLASSPATH=C:\root_of_my_classes

You can set these on the command line, or you could do it the same way you set the PATH
 
Thanks. I actually had the JAVA_HOME set.

I'll set the CLASSPATH and see if that helps. Is the Classpath the root where java looks for files? So if i had a directory

C:\java_programs

then I would just need to set CLASSPATH to this and refer to directories relative to this for package and import?

So if I had files in

C:\java_programs\interface

Do this to import them?

import interface.*

and package would be?

package java_programs

 
OK, so you have you java code (.java and .class) (for example) in :
C:\java\acme\com

and your code has a package of "package acme.com"

Your CLASSPATH would point to "C:\java" in order to pick up a class such as "acme.com.Main.class" through a command such as "java acme.com.Main"

and you would comile that code from C:\java as such "javac acme\com\Main.java"
 
Thanks, that worked!

I set the CLASSPATH to C:\prog, changed the package and import statements to make them relative to this....and no problems, it ran fine!

Compiled fine from both command line and in XEmacs. Thanks!
 
The JAVA_HOME may be set close to the PATH-variable.
(MyComputer->Properties->Advanced->etc...)

I'm running linux (well - I use Windos sometimes) and cannot have a short look in the menu.
This menu would be in german language and not fit to yours.

But I remember, that setting the PATH-Variable is an issue on it's own, while we like to define a own (maybe: user-) variable.

There is a extra section in the same dialog.
---
Another pitfall is the handling of Upper- and Lowercase letters.
Windows CAN distinguish upper- and lowercase letters, but if you call:
dir java
or
dir JAVA
you get the same result, and you aren't allowed to create a file 'foo.txt' if there is already a file 'FOO.txt'.
And you may not rename a file 'foo.txt' to 'FOO.txt'.

Often if you save a file for the first time, it is automatically converted to be of starting UpperCase letter and the rest in lowercase ('Foo.java').

Unfortunly for the windows-user, java is very intolerant in this issue.
But if you specify a class FooBar in a file 'Foobar.java' and compile, javac will look for the classname, and create the right classfile 'FooBar.class'.

If you were successful with XEmacs, perhaps you can spy out:
The working-directory and the Classpath.
---
If you want to include the CURRENT directory, you have to pass the single dot in your classpath:

javac -classpath ./;./sw.jar foo/Foo.java -d classes


The -d classes will seperate compiled classes from source, which is an advantage for packing a jar-file.

Suppose you want to compile your Minesweeper:

C:\prog\Minesweeper\viewController
C:\prog\Minesweeper\viewController\model

The package is viewController.
(Remember the lowercase! Packagenames are supposed to be in lowercase, but it's not a must.)

You have to start the comiler from ../Minesweeper directory, the source of your path.

javac -classpath . viewController\Main.java
or
javac -classpath . viewController\Main.java -d classes

If that doesn't help, please mail the exact errormessage.
---
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top