• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem compiling packages

 
Ranch Hand
Posts: 226
1
jQuery Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
marten koomen
Ranch Hand
Posts: 226
1
jQuery Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 koomen
Ranch Hand
Posts: 226
1
jQuery Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can type javac in your command prompt to get the list of options available in javac.

The period means current working directory.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic