java-native-access/jna · error · java.io.FileNotFoundException
Output directory NOT sucessfully created to: <comRootDir>
Error message
Output directory NOT sucessfully created to: <comRootDir>
What it means
TlbImp's createDir deletes any existing comRootDir and then calls mkdirs(); if directory creation fails (permissions, path in use, disk issues) it throws this FileNotFoundException. It means the type-library-to-Java generator could not prepare its output directory. Note the message text says 'to' but means the output path.
Source
Thrown at contrib/platform/src/com/sun/jna/platform/win32/COM/tlb/TlbImp.java:156
private void createDir() throws FileNotFoundException {
String _outputDir = this.cmdlineArgs.getParam(CMD_ARG_OUTPUT_DIR);
String path = "_jnaCOM_" + System.currentTimeMillis() + "\\myPackage\\"
+ this.typeLibUtil.getName().toLowerCase() + "\\";
if (_outputDir != null) {
this.comRootDir = new File(_outputDir + "\\" + path);
} else {
String tmp = System.getProperty("java.io.tmpdir");
this.comRootDir = new File(tmp + "\\" + path);
}
if (this.comRootDir.exists())
this.comRootDir.delete();
if (this.comRootDir.mkdirs()) {
logInfo("Output directory sucessfully created.");
} else {
throw new FileNotFoundException(
"Output directory NOT sucessfully created to: "
+ this.comRootDir.toString());
}
}
private String getPackageName() {
return "myPackage." + this.typeLibUtil.getName().toLowerCase();
}
private void writeTextFile(String filename, String str) throws IOException {
String file = this.comRootDir + File.separator + filename;
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(file));
bos.write(str.getBytes());
bos.close();
}
private void writeTlbClass(TlbBase tlbBase) throws IOException {View on GitHub (pinned to d036ad9781)
Solutions
- Verify the parent directory of comRootDir exists and is writable before running TlbImp
- Close any processes locking the output directory and delete it manually, then re-run
- Run the generator with sufficient privileges or choose an output path under a user-writable location
- Check the full path string in the message for typos or invalid characters
Example fix
// before
TlbImp imp = new TlbImp("C:\\Program Files\\MyLib\\my.tlb", "C:\\Program Files\\out");
// after
File out = new File("C:\\dev\\generated");
out.mkdirs(); // ensure parent exists and is writable first
if (!out.isDirectory()) throw new IllegalStateException("output dir not usable: " + out);
TlbImp imp = new TlbImp("C:\\dev\\libs\\my.tlb", out.getAbsolutePath()); Defensive patterns
Strategy: validation
Validate before calling
File dir = new File(outPath);
if (dir.exists() && !dir.delete()) throw new IllegalStateException("cannot delete old dir " + dir);
if (!dir.mkdirs() && !dir.isDirectory()) throw new IllegalStateException("cannot create " + dir); Try / catch
try { imp.startCOM2Java(); } catch (FileNotFoundException e) { log.error("output dir unusable: " + e.getMessage()); } Prevention
- Check parent directory writability before invoking TlbImp
- Avoid output paths other processes may lock
- Use user-writable paths, not Program Files
When it happens
Trigger: Calling com2java / TlbImp.startCOM2Java when comRootDir cannot be created: parent directory missing or unwritable, an undeletable file occupies the path, or the path is a locked/removable location.
Common situations: Running the JNA COM code generator with an output directory under a read-only or non-existent parent; insufficient Windows permissions on the target folder; another process (IDE, explorer) holding a handle on the directory so delete() fails and mkdirs() then fails too.
Understand the failure class
Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.
Related errors
- Commandline parameter not found: <key>
- remove
- advise: Interface must define a value for either iid via the
- ComInterface must define a value for iid
- Class type <paramTypes[i].getName()> not mapped to primitive
AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12).
Data as JSON: /api/errors/b85516c9a220f1c2.
Report an issue: GitHub.