Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2006

Tip: Looking for answers? Try searching our database.

How to compile using non packaged classes

Thread view: 
Sumant  Sankaran - 16 Sep 2006 14:11 GMT
Using JDK 1.4

Folks would be great if you could help me out here :

Lets say I have a file called Sample1.java under

<directory>/a/b :

The file Sample1.java is as follows :
package a.b;
public class Sample1
{
       public Sample1()
       {

       }

   public static void main(String []args)
   {
       Sample a =new Sample();
       System.out.println("hello world");
   }
}

and under <directory>
I have got a class.jar that contains just Sample.class ( no package or
anything,just the class file)

How do I compile this??
I do the following:
<directory>/a/b/javac -classpath .:<directory>/class.jar Sample1.java

I get the following error:
--------------------------------------------------------------
Sample1.java:12: cannot resolve symbol
symbol  : class Sample
location: class a.b.Sample1
       Sample a =new Sample();
       ^
Sample1.java:12: cannot resolve symbol
symbol  : class Sample
location: class a.b.Sample1
       Sample a =new Sample();
--------------------------------------------------------------

How do I resolve this issue?What am I doing wrong here.
Please dont ask me to put the Sample.class in a package , I wont be
able to do that since that jar is actually already available.
Thomas Hawtin - 16 Sep 2006 15:28 GMT
Sumant Sankaran wrote:
> package a.b;

>         Sample a =new Sample();

> I have got a class.jar that contains just Sample.class ( no package or
> anything,just the class file)

You cannot import from a default package. To use the compiled class
unaltered, you would need to move your class into the same package.

> Please dont ask me to put the Sample.class in a package , I wont be
> able to do that since that jar is actually already available.

Can I ask you to give the person responsible a slap?

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Sumant  Sankaran - 16 Sep 2006 16:20 GMT
> Sumant Sankaran wrote:
> > package a.b;
[quoted text clipped - 11 lines]
>
> Can I ask you to give the person responsible a slap?

Unfortunately this was done when the project was being done using
jdk1.3 and importing classes alone was allowed. :(
Thanks for the response Tom

> Tom Hawtin
> --
> Unemployed English Java programmer
> http://jroller.com/page/tackline/
Knute Johnson - 16 Sep 2006 18:16 GMT
Sumant Sankaran wrote:
>> Sumant Sankaran wrote:
>>> package a.b;
[quoted text clipped - 15 lines]
>> Unemployed English Java programmer
>> http://jroller.com/page/tackline/

The simple solution is to unjar the Sample.class file.

Signature

Knute Johnson
email s/nospam/knute/

Knute Johnson - 16 Sep 2006 18:29 GMT
Sumant Sankaran wrote:
>> Sumant Sankaran wrote:
>>> package a.b;
[quoted text clipped - 15 lines]
>> Unemployed English Java programmer
>> http://jroller.com/page/tackline/

Please kindly ignore my last post as that won't work either.

What you can do is create a new class in the default package that
references your Sample.class file and your a.b.Sample1.class.  You just
can't reference the default package from another package.

Can anybody explain why that limitation would exist?

Thanks,

Signature

Knute Johnson
email s/nospam/knute/

Andrew Thompson - 16 Sep 2006 18:43 GMT
(no import for default package)
> Can anybody explain why that limitation would exist?

<http://groups.google.com/group/comp.lang.java.programmer/msg/b156ba75c3ec0e8b>

Maybe Sun got sick of people ignoring their strong
hint that once test classes get beyond the 'test'
phase - they should be jar'd.

(I am *way* guilty of deploying default package
classes, it will probably return to bite me in the
posterior when Sun decides to disallow them
from JWS apps. as well! ..groan)

Andrew T.
Sumant  Sankaran - 17 Sep 2006 05:18 GMT
> (no import for default package)
> > Can anybody explain why that limitation would exist?
[quoted text clipped - 11 lines]
>
> Andrew T.

Someone helped me out on this issue on another java forum.The only way
to access Sample from Sample1 in such a case is to use reflection. I
guess that works .  Thanks guys for all the help

Sumant


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.