how can i get javac to search child directories of classpath?
I have 3 files: /a/A.java /a/aa/AA.java /b/B.java and B.java depends on A.java and AA.java.
I basically want javac -classpath /a /b/B.java to work (i.e. have javac search below /a). Is there any way I can do this?
Asked by: Max482 | Posted: 23-01-2022
Answer 1
The short answer is no, that's not how classpath directories work.
Each classpath directory is regarded as the root of a package structure. Each package is a directory within the root. So, javac will do so automatically if aa is a package directory and a is the root. You're classes would look like this:
/a/A.java
class A {}
/a/aa/AA.java
package aa;
class AA {}
/b/B.java
package b;
import aa.AA;
class B {
private AA aaInstance;
private A aInstance;
}
Because A has no package, it's placed in the root package.
Otherwise, you have to set each source dir explicitly.
Answered by: Connie756 | Posted: 24-02-2022Similar questions
java - How to read from text files in classpath across directories?
I'm working on a program (with JavaSE 1.6) that will read from text files located in the project's classpath.
The files are in a different folder than the class that's trying to access them, though, and directing my code to their location is baffling me.
The class I'm running is located in a package in the "src/test/java" folder, while the text files are separated into multiple folders (for organizational p...
java - What is meant by the classpath root when the classpath contains many directories?
The spring boot documentation says that it looks in the classpath root for application.properties. I'm trying to figure out what my classpath root is, but when I print the classpath it contains many directories separated by colons....
java - issue printing current project classpath // How can I print all directories and libraries in the classpath?
I have an Oracle Form running on the client's workstation.
When the JVM that loads the form is started we have a several jar files loaded into the JVM classpath. I am trying to print the content of the classpath in one of the jars being loaded to the JVM, but every time is being printed only the one below:
classpath= C:\Program Files (x86)\Java\jre1.8.0_281\lib\deploy.jar
I used several ways one ...
java - Can I extract a file from a jar that is 3 directories deep?
I have a jar file that has a file named "client.ts" in (when viewing in ZipGenius) "/com/something/messaging". When I do
JarFile jarFile = new JarFile("Client.jar");
JarEntry zipFile = jarFile.getJarEntry("client.ts");
It can't find the "client.ts" file. If I package the file in "/resources/" instead it can find it. Does JarFile.getEntry() only drill down one directory? The j...
file io - Deleting non-empty directories in Java
Supposing I have a File f that represents a directory, then f.delete() will only delete the directory if it is empty. I've found a couple of examples online that use File.listFiles() or File.list() to get a...
java - Can I use JAVAC to compile a project with multiple files and directories?
I'm working on a very large project that has associated class files in multiple directories, all stemming from the root dir \src.
I'm trying to compile a file in src\solution\ (called Console.java) that uses imports from other directories in the src, which are still uncompiled.
So if I want to compile Console.java outside of an IDE, how do I go about doing that? Oh yeah, I also have some external JARs which...
directory - Java: Proper Way of Making Directories
Directories some_folder, some_folder_1, some_folder_2, and some_folder_3 don't exist initially.
File folder1 = new File("some_folder/some_folder_1");
File folder2 = new File("some_folder/some_folder_2");
File folder3 = new File("some_folder/some_folder_3");
if(!folder1.exists()) {
folder1.mkdirs();
}
if(!folder2.exists()) {
folder2.mkdirs();
}
if(!folder3.exists()) {
folder3.mkdirs();
}
eclipse - How to suppress Java warnings for specific directories or files such as generated code
I'm using a parser generator that creates somewhat ugly code. As a result my Eclipse project has several dozen warnings emanating from generated source files. I know I can use the @SuppressWarning annotation to suppress particular warnings in particular elements, but any annotations I add by hand will be lost when the parser generator runs again. Is there a way to configure Eclipse to suppress warnings for a p...
Method in Java to create a file at a location, creating directories if necessary?
I am attempting to write a file using java.io, where I am trying to create it at the location "some/path/to/somewhere/then-my-file". When the file is being created, any of the directories on the path may or may not exist. Rather than throw an IOException because there are no such directories, I would like the directories to be created transparently, as and when required.
Is there a method that will cre...
java - Create all directories up to a point?
I need to be able to build all directories up to and including the directory specified by my File object. For example, suppose I have something like this:
File file = new File( "/var/a/b/c/d/" );
But only /var/ exists. I need a method that builds up to d, and I was wondering if there was a method in a java io library somewhere that does this already.
java - Different lib directories of JBoss
There is a number of different lib directories JBoss (5.1.0) uses: I can find jboss/lib, jboss/lib/endorsed, jboss/common/lib, jboss/server/default/lib and of course the jboss/server/default/deploy/myapp/WEB-INF/lib (am I missing something ?).
From the above, I know that I need to use the last one (WEB-INF/lib) to put any jars my app needs. What about all the others ? What is their use and what should I put there ?...
java - How to create a new file together with missing parent directories?
When using
file.createNewFile();
I get the following exception
java.io.IOException: Parent directory of file does not exist: /.../pkg/databases/mydb
I am wondering is there a createNewFile that creates the missing parent directories?
Decompress a 7zip archive with multiple files & directories in Java
Closed. This question needs debugging detai...
Still can't find your answer? Check out these amazing Java communities for help...
Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)