• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Problem with Package execution

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

I am facing some problem regarding compilation of a class in a package.

I am trying to compile the below test.java file by using the command

javac -d classes src\com\example\web\test.java

but its not recognising Hello.java even though its compiled.
Please help me out as i got stuck up here.I attached the 2 files below


/**************test.java********************/
package com.example.web;
import com.example.model.Hello;

public class Test

{

public static void main(String args[])
{
Hello t=new Hello();

t.calledMethod();

}
}


/***********Hello.java***********************/



package com.example.model;


public class Hello

{


public void calledMethod()
{
System.out.println("Hi im in the Called method");

}


}
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

To help you, I'd have to know what "It is not recognizing Hello.java" means. "It" is the compiler, or the JVM itself? What did you type, and what was the error message you received?
 
Vinay Kumar chowdary
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The directory structure of my project is
c:\project\helloTest\src\com\example\

Hello.java is placed in c:\project\helloTest\src\com\example\model

test.java is placed in c:\project\helloTest\src\com\example\web

I am trying to place the generated class files in
c:\project\helloTest\classes\com\example\

I am executing the following command to compile the file test.java

C:\project\helloTestTest>javac -d classes src\com\example\web\test.java


but is giving error as below

package com.example.model does not exist


Please help
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are basically trying to figure out how to use javac to compile multiple files. Please refer to javac: Java Programming Language Compiler

What you need is:

javac -d classes com/example/model/Hello.java com/example/web/test.java
 
Vinay Kumar chowdary
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for your solution...

The problem is resolved now...
 
what if we put solar panels on top of the semi truck trailer? That could power this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic