Solved

importing..easy points

Posted on 2004-04-23
10
197 Views
Last Modified: 2010-03-31
Hello,
I'm using Jdev.

I have two projects and one workspace

Workspace
   -project1
      -myClassA.class
   -project2
      -myClassB.java
      -myClassB.class


I want to import myClassA into myClassB

can anyone give me the line of code to do that please?
Ghost
0
Comment
Question by:copyPasteGhost
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10899655
keep your classpath upto "workspace"

// if you want you myClassA in myClassB then add the following in the top of myClassB.java

import project1.*;


// if you want you myClassB in myClassA then add the following in the top of myClassA.java

import project2.*
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10899658
in myClassB.java

import  x.y.z.myClassA;


with x.y.z the "package path"
0
 
LVL 13

Author Comment

by:copyPasteGhost
ID: 10900308
that didn't work..
I have this set up

Workspace
   -project1
      -com
         -mypack1
            -myClassA.class
   -project2
      -com
         -mypack1
            -myClassB.class
            -myClassB.java
I get this error..

Error(20,1): cannot access directory project1.com.mypack1; verify that directory is reachable from classpath and/or sourcepath

from myClassB.java
import project1.com.mypack1*;

thanks,
Ghost
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10900367
write a own batch file like..named it as compile.bat

javac -classpath C:\\..project1\com\mypack1;  myClassA.java myClassB.java

from the command prompt type compile.bat thats all...it will compile all the specified .java files

and run it later...

all the best...

R.K.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10900437
if both classes are in mypack1 then there's no need for an import.

just ensure both .java files contain

package mypack1;

as the first line

0
 
LVL 13

Author Comment

by:copyPasteGhost
ID: 10900601
they aren't..

one is from project 1 and the other is from project 2...
see what I"m saying?
Ghost
0
 
LVL 13

Author Comment

by:copyPasteGhost
ID: 10900769
>rama_krishna580
dude I have no idea what you are saying.. but it looks good :)
can you explain a bit more please?
Ghost
0
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 10905333
assuming both are in package com.mypack1 then add the follwoing directories to your classpath:
..../project1
..../project2

no need for an import because they are both in the same package.

If this is not the case can you tell us what packjage they are in exactly.
0
 
LVL 13

Author Comment

by:copyPasteGhost
ID: 10907231
well it turns out that Jdev has this feature to add additional class paths. once I put in the path to the floder ie..
project1.com.mypack1, the class was found and I was able to import it without a problem.

>>no need for an import because they are both in the same package.

I needed an import cause the even though the packages had the same name they were not the same package..if you notice my directory diagram above you will see this to be the case.

Nevertheless, Thanks Objects for the tip,
Ghost
0
 
LVL 92

Expert Comment

by:objects
ID: 10909571
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet  URL Rewriting 1 38
egit plugin on eclipse 8 65
even odd program using while loop 3 44
eclipse console opening separately 2 21
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question