importing..easy points

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
LVL 13
copyPasteGhostAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
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
 
mmuruganandamCommented:
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
 
zzynxSoftware engineerCommented:
in myClassB.java

import  x.y.z.myClassA;


with x.y.z the "package path"
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
copyPasteGhostAuthor Commented:
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
 
rama_krishna580Commented:
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
 
zzynxSoftware engineerCommented:
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
 
copyPasteGhostAuthor Commented:
they aren't..

one is from project 1 and the other is from project 2...
see what I"m saying?
Ghost
0
 
copyPasteGhostAuthor Commented:
>rama_krishna580
dude I have no idea what you are saying.. but it looks good :)
can you explain a bit more please?
Ghost
0
 
copyPasteGhostAuthor Commented:
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
 
objectsCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.