0
# Command Line Interface (CLI)
1
2
The JAXB XJC command-line interface provides comprehensive schema compilation capabilities for batch processing and build automation workflows.
3
4
## Capabilities
5
6
### Main Entry Points
7
8
Primary command-line execution entry points for XJC compilation.
9
10
```java { .api }
11
/**
12
* Core CLI implementation with comprehensive execution options
13
*/
14
public final class Driver {
15
public static void main(String[] args) throws Exception;
16
public static int run(String[] args, PrintStream status, PrintStream out) throws Exception;
17
public static int run(String[] args, XJCListener listener) throws BadCommandLineException;
18
public static void usage(Options opts, boolean privateUsage);
19
public static String getBuildID();
20
}
21
```
22
23
**Usage Examples:**
24
25
```bash
26
# Basic schema compilation
27
xjc schema.xsd
28
29
# Compile with specific package name
30
xjc -p com.example.generated schema.xsd
31
32
# Compile to specific output directory
33
xjc -d target/generated-sources schema.xsd
34
35
# Verbose output with warnings
36
xjc -verbose schema.xsd
37
38
# Multiple schema files
39
xjc schema1.xsd schema2.xsd schema3.xsd
40
41
# Using binding customization
42
xjc -b bindings.xjb schema.xsd
43
44
# Generate with episode file for separate compilation
45
xjc -episode generated.episode schema.xsd
46
```
47
48
### CLI Options Configuration
49
50
Configuration class containing all command-line options and parsing logic.
51
52
```java { .api }
53
/**
54
* Configuration and command-line options for XJC compilation
55
*/
56
public class Options {
57
// Core compilation options
58
public boolean debugMode;
59
public boolean verbose;
60
public boolean quiet;
61
public boolean readOnly;
62
public String encoding;
63
public File targetDir;
64
public String defaultPackage;
65
public Language schemaLanguage;
66
public int strictCheck;
67
public boolean packageLevelAnnotations;
68
public boolean automaticNameConflictResolution;
69
public Set<String> recognizedExtensions;
70
public List<Plugin> activePlugins;
71
72
// Parsing methods
73
public int parseArgument(String[] args, int i) throws BadCommandLineException;
74
public void parseArguments(String[] args) throws BadCommandLineException;
75
76
// Configuration methods
77
public FieldRendererFactory getFieldRendererFactory();
78
public void setFieldRendererFactory(FieldRendererFactory frf, Plugin owner);
79
public ClassLoader getUserClassLoader(ClassLoader parent);
80
public List<Plugin> getAllPlugins();
81
public CodeWriter createCodeWriter();
82
public CodeWriter createCodeWriter(CodeWriter core);
83
}
84
```
85
86
### Command Line Execution Modes
87
88
XJC supports several execution modes for different use cases.
89
90
```java { .api }
91
/**
92
* Extended options class with CLI-specific modes
93
*/
94
static class OptionsEx extends Options {
95
protected Mode mode;
96
public boolean noNS;
97
98
public int parseArgument(String[] args, int i) throws BadCommandLineException;
99
}
100
101
enum Mode {
102
CODE, // Normal code generation mode
103
SIGNATURE, // Dump signature of generated code
104
FOREST, // Dump DOM forest
105
DRYRUN, // Parse and validate but don't generate code
106
ZIP, // Pack all outputs into a zip
107
GBIND // Testing binding mode
108
}
109
110
/**
111
* Supported schema languages for XJC compilation
112
*/
113
public enum Language {
114
DTD("DTD", "dtd"),
115
XMLSCHEMA("XML Schema", "xsd"),
116
RELAXNG("RELAX NG", "rng"),
117
RELAXNG_COMPACT("RELAX NG (compact syntax)", "rnc"),
118
WSDL("WSDL", "wsdl");
119
120
public final String displayName;
121
public final String[] expectedExtensions;
122
123
Language(String displayName, String... expectedExtensions);
124
}
125
```
126
127
**Usage Examples:**
128
129
```bash
130
# Generate code (default mode)
131
xjc schema.xsd
132
133
# Dry run - validate schema without generating code
134
xjc -mode dryrun schema.xsd
135
136
# Generate signature information
137
xjc -mode signature schema.xsd
138
139
# Package output as ZIP
140
xjc -mode zip schema.xsd
141
142
# Help and version information
143
xjc -help
144
xjc -version
145
xjc -fullversion
146
```
147
148
### Progress and Status Reporting
149
150
Progress reporting system for long-running compilation tasks.
151
152
```java { .api }
153
/**
154
* Abstract listener for compilation progress and error reporting
155
*/
156
public abstract class XJCListener extends ErrorReceiver {
157
public abstract void generatedFile(String fileName, int count, int total);
158
public abstract void message(String msg);
159
public void compiled(Outline outline);
160
public boolean isCanceled();
161
162
// Error handling from ErrorReceiver
163
public abstract void error(SAXParseException exception);
164
public abstract void warning(SAXParseException exception);
165
public abstract void info(SAXParseException exception);
166
public void pollAbort() throws AbortException;
167
}
168
```
169
170
**Usage Example:**
171
172
```java
173
// Custom listener for build tool integration
174
XJCListener listener = new XJCListener() {
175
@Override
176
public void generatedFile(String fileName, int count, int total) {
177
System.out.printf("Generated %s (%d of %d)%n", fileName, count, total);
178
}
179
180
@Override
181
public void message(String msg) {
182
System.out.println(msg);
183
}
184
185
@Override
186
public void error(SAXParseException exception) {
187
System.err.println("Error: " + exception.getMessage());
188
}
189
190
@Override
191
public void warning(SAXParseException exception) {
192
System.err.println("Warning: " + exception.getMessage());
193
}
194
195
@Override
196
public void info(SAXParseException exception) {
197
System.out.println("Info: " + exception.getMessage());
198
}
199
};
200
201
// Execute XJC with custom listener
202
int result = Driver.run(args, listener);
203
```
204
205
### Exception Handling
206
207
Exception types specific to command-line processing.
208
209
```java { .api }
210
/**
211
* Exception thrown when command line arguments are invalid
212
*/
213
public class BadCommandLineException extends Exception {
214
public BadCommandLineException();
215
public BadCommandLineException(String message);
216
public BadCommandLineException(String message, Throwable cause);
217
public void initOptions(Options opts);
218
public Options getOptions();
219
}
220
```
221
222
### Common CLI Patterns
223
224
**Basic Schema Compilation:**
225
```bash
226
xjc schema.xsd
227
```
228
229
**Package and Output Control:**
230
```bash
231
xjc -p com.example.generated -d src/main/java schema.xsd
232
```
233
234
**Multiple Schemas with Binding Customization:**
235
```bash
236
xjc -b bindings.xjb schema1.xsd schema2.xsd
237
```
238
239
**Plugin Usage:**
240
```bash
241
xjc -Xfluent-api schema.xsd
242
```
243
244
**Episode Generation for Modular Compilation:**
245
```bash
246
# First compilation generates episode
247
xjc -episode common.episode common.xsd
248
249
# Second compilation uses episode
250
xjc -extension common.episode specific.xsd
251
```
252
253
**Quiet Mode for Build Scripts:**
254
```bash
255
xjc -quiet -d target/generated schema.xsd
256
```
257
258
**Verbose Debugging:**
259
```bash
260
xjc -verbose -debug schema.xsd
261
```