• Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting my own package  RSS feed

 
martin ramboäpple
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Not sure how the package-settings work, followed book and get error.
I have these two classes in the following directories:

\com\example\web\BeerSelect.java
\com\example\modelBeer\Expert.java

BeerSelect has a BeerExepert-object.

Top of BeerExpert:


and BeerSelect:


Compiling BeerExpert goes well.
But, compiling BeerSelect gives complaints, "com.example.model does not exist". That is, where BeerExpert resides. Im not sure why.
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your file located at \com\example\modelBeer\Expert.java ?
It should be \com\example\model\BeerExpert.java
 
martin ramboäpple
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paweł Baczyński wrote:Is your file located at \com\example\modelBeer\Expert.java ?
It should be \com\example\model\BeerExpert.java


Sorry, I mistyped. It is \com\example\model\BeerExpert.java
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How exactly are you compiling BeerSelect?
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This recommendation has links in about how to copy error messages, file structures, etc. It might help you copy the exact paths to your files, too.
 
martin ramboäpple
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jelle Klap wrote:How exactly are you compiling BeerSelect?


Hi,
For BeerExpert:

javac PATHTOCOMFOLDER\com\example\model\BeerExpert.java

for BeerSelect I use classpath for servlet-library:

javac -classpath PATHTOAPACHE\apachetomcat\lib\servlet-api.jar PATHTOCOMFOLDER\com\example\model\BeerSelect.java

Perhaps worth mentioning;
In my system-variables I have JAVA_HOME set to the jdk-folder, and Path-variable to jdk\bin.
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to include the BeerSelect.class file on the classpath you use to compile BeerExpert.java.
For convenience it is also helpful to separate sources files, class files and libraries into different directories, like so:

Before you begin make sure these files and directories all exist.
Now you can compile BeerSelect.java like so, relative to PATH-TO-BEER_PROJECT:

This will compile BeerSelect.java and put the .class file in the appropriate package structure into PATH-TO-BEER-PROJECT\classes.
Now you can compile BeerExpert.java like so:

See, now it's easy to specify all the .jar files and classes you need to compile BeerExpert.java simple by including lib\* and classes on the classpath.
 
martin ramboäpple
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved, Thanks for your help!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!