I am trying to create java code using jcodemodel in my maven project. My maven project has three modules. I wrote a jcodemodel sample in one of my modules for testing purposes. But when I execute it, it causes an error in the line. But I created a directory and also checked. I checked this example in a simple maven project, it works. But when I give it inside the maven module, it throws an error. where does it check the build file?
codeModel.build(new File("src/main/java/check"));
java.io.IOException: src \ main \ java \ check: nonexistent directory at com.sun.codemodel.writer.FileCodeWriter. (FileCodeWriter.java:73)
public class Consumer {
public static void main(String[] args) throws JClassAlreadyExistsException, IOException, JAXBException {
writeCodeModel("com.cts");
}
public static JType getTypeDetailsForCodeModel(JCodeModel jCodeModel, String type) {
if (type.equals("Unsigned32")) {
return jCodeModel.LONG;
} else if (type.equals("Unsigned64")) {
return jCodeModel.LONG;
} else if (type.equals("Integer32")) {
return jCodeModel.INT;
} else if (type.equals("Integer64")) {
return jCodeModel.LONG;
} else if (type.equals("Enumerated")) {
return jCodeModel.INT;
} else if (type.equals("Float32")) {
return jCodeModel.FLOAT;
} else if (type.equals("Float64")) {
return jCodeModel.DOUBLE;
} else {
return null;
}
}
public static void writeCodeModel(String factroyPackage) throws JAXBException {
try {
JCodeModel codeModel = new JCodeModel();
JDefinedClass foo = codeModel._class( "Foo" );
JMethod method = foo.method( JMod.PUBLIC, Void.TYPE, "doFoo" );
method.body()._return( JExpr.lit( 42 ) );
codeModel.build(new File("src/main/java/check"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Ramya source
share