Solved

importing..easy points

Posted on 2004-04-23
10
179 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now