1

Let's say I have JProjectOne and JProjectTwo. Will the public class I have in JProjectOne be visible in JProjectTwo or do I have to do some tweaking for it to be visible?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • 1
    "Projects" are not a concept that the Java Language knows about - that's just your IDE doing things its way. Before Java9, public classes were visible to any other class. Since Java9, with modules, there are some changes to that. – Erwin Bolwidt May 28 '18 at 05:53
  • As long, as JProjectTwo doesn't have JProjectOne in its classpath, nothing from the latter is accessible to the former – Lino May 28 '18 at 05:53

3 Answers3

1

private hides from other classes within the package. public exposes to classes outside the package. A protected member is accessible within all classes in the same package and within sub classes in other packages. May be JAVA Docs is helpful.

0

This is the place where JARs come handy, make a jar file of the public class you want in other project. Then add it to present project.

  1. Creating a JAR - How to make an executable jar file?
  2. How to add external JARs to a project - How to import a jar in Eclipse
Arun Sudhakaran
  • 2,167
  • 4
  • 27
  • 52
0

As Arun suggested try with jar, but if You are using Maven, that is quiet easy to do that, here is an example:

Here is how You could "install", send you jar file to .m2 (maven container),

mvn install:install-file
   -Dfile=<path-to-file>
   -DgroupId=<group-id>
   -DartifactId=<artifact-id>
   -Dversion=<version>
   -Dpackaging=<packaging>
   -DgeneratePom=true

Where: <path-to-file>  the path to the file to load
   <group-id>      the group that the file should be registered under
   <artifact-id>   the artifact name for the file
   <version>       the version of the file
   <packaging>     the packaging of the file e.g. jar

so this is how would this look like (example):

mvn install:install-file -Dfile=c:\test_0.0.1.jar -DgroupId= com.test
-DartifactId=project -Dversion=0.0.1 -Dpackaging=jar

...and simply calling in other project like this (also from maven):

<dependency>
    <groupId>com.test</groupId>
    <artifactId>project</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/src/main/resources/yourJar.jar</systemPath>
</dependency>

and just do always pom.xml import on file, to update it and You're good to go. This is just local jar importing.

Hope this helps.

Kovacic
  • 1,473
  • 6
  • 21