Right way of Creating Java Module
Below given are two ways to build modules in IntelliJ9
Way 1
File imlFile = new File(projectDir, moduleName);
Module module = null;
module = moduleManager.findModuleByName(moduleName);
if (module == null) {
if (imlFile.exists()) {
imlFile.delete();
}
module = moduleManager.newModule(imlFile.getAbsolutePath(), StdModuleTypes.JAVA);
}
ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
//Set content entry path
//Set JDK
modifiableModel.commit();
Way 2
File imlFile = new File(projectDir, moduleName);
JavaModuleBuilder modulebuilder = new JavaModuleBuilder();
ModifiableModuleModel model =ModuleManager.getInstance(prj).getModifiableModel();
modulebuilder.setName(projectName);
modulebuilder.setModuleFilePath(newProjectImplimentationFilePath);
//Set content entry path
//Set JDK
modulebuilder.createModule(model);
modulebuilder.setModuleJdk(projectjdk);
model.commit();
Ambiguity is in setting compilerOutput path
1. In way 1, it is done by CompilerModuleExtension.getInstance(module).setCompilerOutputPath(compilerOutputPath) but is giving error
Configuring project failed for unexpected reason
java.lang.AssertionError: Writable model can be retrieved from writable ModifiableRootModel
at com.intellij.openapi.roots.impl.CompilerModuleExtensionImpl.a(CompilerModuleExtensionImpl.java:225)
at com.intellij.openapi.roots.impl.CompilerModuleExtensionImpl.setCompilerOutputPath(CompilerModuleExtensionImpl.java:196)
at com.intellij.openapi.roots.impl.CompilerModuleExtensionImpl.setCompilerOutputPath(CompilerModuleExtensionImpl.java:186)
at com.yolus.intellij.yde.ProjectConfigurer$YDEModule.configureModuleOrFail(ProjectConfigurer.java:340)
Should the CompilerModuleExtension be used after the ModifiableModuleModel commit method or it does not matter
2. In way 2, it is done by modulebuilder.setCompilerOutputPath(path)
Please resolve.
Please sign in to leave a comment.
Guyz please help. I am still stuck with this issue.