Colin747
Colin747

Reputation: 5013

Cowardly refuses to write to a non-existent directory - JAXB

I'm getting the following error when trying to generate Java classes from an XSD schema using JAXB. I'm specifying a directory that I want them to be in but I am getting the following error when I try to run the command.

Command:

java -jar /home/Alison/Programs/jaxb-ri-2.2.6/lib/jaxb-xjc.jar xmlSchema.xjb -d com.q1labs.qa.xmlgenerator.model.xmlclasses xmlSchema.xsd

Error:

cowardly refuses to write to a non-existent directory "com.q1labs.qa.xmlgenerator.model.xmlclasses"

I found the following patch http://jira.codehaus.org/browse/MJAXB-2 but from the comments it seems that it no longer works with the current revision.

Is there any way I can specify to create the directory if it does not exist?

Upvotes: 5

Views: 3748

Answers (4)

Esai
Esai

Reputation: 1

I also faced the issue but solved it using following way.

xjc -d src/main/java -p com.sample.utils.jaxbJavaClass /Users/XXXX/Documents/Project_workspace/src/test/resources/xsd_files/out.xsd

In the above command -d represents source directory, -p the package where you want the java classes to be generated. Then use your project director path and your "xsd" file path. This above command works fine and java classes will be generated.

Upvotes: 0

Vikas Chowdhury
Vikas Chowdhury

Reputation: 775

I also get this issue when I try to generate java package and files at runtime. Issue occurs when I already have a specified java package which is created at runtime and again I am trying to create the same jaxb classes(first time when it got created,there were some functional errors and after that files didnt get deleted) it says "cowardly refuses to write to a non-existent directory "employee"". For me the issue got solved when i manually deleted the already created package ,after that it worked fine.

Upvotes: 0

Colin747
Colin747

Reputation: 5013

Manged to get this to work the way I wanted using the following command:

java -jar /home/Alison/Programs/jaxb-ri-2.2.6/lib/jaxb-xjc.jar -b xmlSchema.xjb -d src -p com.q1labs.qa.xmlgenerator.model.xmlclasses xmlSchema.xsd

Upvotes: 4

Stephen C
Stephen C

Reputation: 718996

Is there any way I can specify to create the directory if it does not exist?

The simple answer is to create the directory before you run the application. In general, there is no way to get an application to create a directory for you if the application doesn't already have the capability to create directories.

FWIW, it is generally a bad idea for an application to create "missing" directories ... unless the user has indicated that that is what is required; e.g. via a command line option. The reason is that "missing" directories are usually due to the user mistyping a pathname, or due to the current directory being different to what the user thinks it is. In other words, the user usually wouldn't want the application to create the "missing" directories.

Upvotes: 4

Related Questions