-1

I am trying to use user defined package from one directory to another directory. (i.e D to E) In the time of compiling the main java file I had faced an error theat package is not available. So, my question is can we use user defined packages from different drives?

I tried by setting the path of my user defined packages. But my concept is only working within in the same drive.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • Although possible with some problems, this is not normal to do. Sounds like you're actually talking about separate *libraries*, not just *packages*. If so, you should package the one in a JAR, and put that JAR on the classpath of the other. – Mark Rotteveel Nov 10 '22 at 15:41
  • Please provide enough code so others can better understand or reproduce the problem. – Community Nov 11 '22 at 10:06

1 Answers1

0

If I understand your question correctly, you want to use two java packages which are stored in different directories.

To access the classes within those packages, you have to add them to the class-path / module-path. At this, you can specify different directories.

The following questions might be interesting in this context.

What is a classpath and how do I set it?

Is it possible to mix --class-path and --module-path in javac (JDK 9)?

Gerhard
  • 118
  • 5
  • Anyways tq for your reply. But classpath concept is not working. I have already tried..! – Guna Sekhar Venkata Chennaiah Nov 11 '22 at 01:42
  • Exactly my problem is that I had one user-defined package file in d drive and one main java file in e drive which importing the created user defined package. When the time of compiling the main java program, jvm shows that error that specified package is not defined . So, i need some clear clarification that whether my concept will work or not..? – Guna Sekhar Venkata Chennaiah Nov 11 '22 at 01:47
  • It seems, I have not understood your question … Can you please clarify: What do you mean with "user-defined package"? Is this your code? How is this package available – java-files, compiled class-files in a directory, or a jar-file. Which java-version do you use? If your java-version is >= 9: Are you aware of the concept of java-modules and do you use it? – Gerhard Nov 11 '22 at 07:35
  • User defined package in the sense that I had create some classes and methods under one package and I had successfully compiled the package in one directory. My idea is to import the package which I had mentioned in the above. In the time of compiling that java program jvm arises the error that the package is not available. I would like to inform that my main java file is in one drive and the created user defined package file in another drive. Even u didnt understand my problem then share the mail of urs then I will keep my video of my probelm. – Guna Sekhar Venkata Chennaiah Nov 11 '22 at 11:19