Jump to content
  • Advertisement
Sign in to follow this  
SteveTaylor

[java] package keyword behaviour changed?

This topic is 4627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I remember a few years ago writing some java code and using the 'package' keyword. Suppose I had a file called NonPlayerCharacter.java that looked something like this:
[source="java"]package game.server;

public class NonPlayerCharacter implements CellOccupant
{
    // ...
}

If I compiled it, as far as I can remember, the compiler would generate game/server/NonPlayerCharacter.class, creating the directories as needed. Now with JDK 5.0 it just puts the class files in the same directory as the java files. Am I right or is it just my imagination?

Share this post


Link to post
Share on other sites
Advertisement
The compiler creates a class game.server.NonPlayerCharacter. The source should be
game/server/NonPlayerCharacter.java
relative to the source directory tree root. If nothing else is given, the compiler will generate
game/server/NonPlayerCharacter.class
relative to the same directory tree root. If the class directory root should be elsewhere, use the
javac -d where/to/put/classes/to
switch. The man page says
Quote:
man page
Sets the destination directory for class files. The destination directory must already exist; javac will not create the destination directory. If a class is part of a package, javac puts the class file in a subdirectory reflecting the package name, creating directories as needed.


This works fine for me since 2001. Don't know how the behaviour was before.

Share this post


Link to post
Share on other sites
Quote:
Original post by SteveTaylor
Am I right or is it just my imagination?


It's not your imagination. If you use the -d option (for directory) when you use javac (compiler) it will create your directory structure for you.

So if you type:

$mkdir ../bin
$javac -d ../bin *.java

It will create all your package directories in the ../bin directory.

Good luck!

Share this post


Link to post
Share on other sites
Ah yes, thanks for that. I just use -d . and it creates the whole stucture in the current dirctory. Come to think of it I think that's what I used all that time ago. So nothing has changed.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!