aspose file tools*
The moose likes Beginning Java and the fly likes Problem compiling packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem compiling packages" Watch "Problem compiling packages" New topic
Author

Problem compiling packages

marten kay
Ranch Hand

Joined: Feb 03, 2007
Posts: 178

I am having a problem compiling with packages, I feel I have misunderstood something simple, any help would be appreciated.

As an example.

In directory C:\JSPproject\beerV1\src\com\example\model
I have



And in directory C:\JSPproject\beerV1\src\com\example\web
I have



And my javac result is



when in doubt put it in parenthesis and stick a dollar sign in front of it, only good can come from this.
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

First of all, when you import a class, you should tell which class that you want to import, e.g.

import com.example.web.TestString;

If you need to import all the classes in that package, you can use do this:
import com.example.web.*;

The other mistake is prints() method in TestString requires a parameter.

Hope that helps.


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 320
I would try stepping into the source directory, src, and trying

C:\JSPproject\beerV1\src> javac com\example\model\*.java
C:\JSPproject\beerV1\src> javac com\example\web\*.java


------------------------
Bob
SCJP - 86% - June 11, 2009
marten kay
Ranch Hand

Joined: Feb 03, 2007
Posts: 178

thanks for both your feedback, i fixed up my classes and tried suggestions, Unfortunately it is still not working (see below)

By way of background, I am completing the Head First servlets & JSP and I have encountered a problem on an excercise p85. This exercise is to help me understand that bigger problem while removing the tomcat complexity.

Could there be a problem with environment variables?

I fixed up the classes, as advised by Freddy as such

In C:\JSPproject\beerV1\src\com\example\model


and in C:\JSPproject\beerV1\src\com\example\web
there is


I then get

or using Bob's suggestion



Similarly, when I try compiling the other web folder first, I get

and


[ June 16, 2007: Message edited by: marten kay ]
[ June 16, 2007: Message edited by: marten kay ]
Mike Guze
Greenhorn

Joined: Jun 09, 2007
Posts: 11
Hi,

At firts, you don't need "import com.example.model.*;" in TestString class. compile your code without that import.

If TestString was compile well, you can call to javac like:

"C:\JSPproject\beerV1\src> javac -classpath . com\example\model\*.java "
marten kay
Ranch Hand

Joined: Feb 03, 2007
Posts: 178

Mike, wonderful


I'm still not sure why though, the period obviously has significant meaning

Can anybody point me to resource, or briefly explain, where I can find out what this statement

javac -classpath . com\example\model\*.java


and how it differs from

javac javac -d classes src/com/example/model/*.java

But I'm on my way, thanks to all!
[ June 16, 2007: Message edited by: marten kay ]
Mike Guze
Greenhorn

Joined: Jun 09, 2007
Posts: 11
Hi,

When use -classpath option, you are telling to the compiler, where to find your classes, resources what are necesar s to compile the source code.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41815
    
  62
One difference is where the compiled .class files are going to end up. The "-d classes" tells the compiler to put those in the "classes" directory. If you leave that out, they're going to end up in the same directory as the source files.


Ping & DNS - my free Android networking tools app
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

You can type javac in your command prompt to get the list of options available in javac.

The period means current working directory.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem compiling packages