Java Module Help trent  2011-07-18 16:27
Status: Closed
 
Wondering if someone can point me in the right direction re: java modules?

So anyway, I've seen the Demo module, but I think it would be more beneficial for me to create my own to learn how everything ties in.

So anyway, I run the create_module ant script, give it a name of helloworld. Point it to the path of <labkey_src_root>servermoduleshelloworld

Just so its in the same directory as all the other modules, and so that I don't need to worry about more VM parameters, passing an external directory. Once I've got it working, i'll be more confident to do that.

At this stage, I have made no changes to the module, try running and building and go to Admin -> Manage Project -> Folder Settings. On the right, you can see a list of the available modules, but I see no presence of the one I have just created.

Back in intelliJ I notice the classes for said module, have a red circle with a line through them, like the no smoking graphic. I found the key for icons for IntelliJ - http://www.jetbrains.com/idea/webhelp/symbols.html - that this means "Java Class located out of the source root" so thought perhaps this is affecting it being included as a module.

So I saw in the File Menu the New Module… item, where you can import an existing module (which I guess is what you are talking about in the documentation when you mention about importing modules from an external directory). So I clicked that -> import existing module, pointed it to the .iml file and followed the steps. Now the red circle with line is gone.

I build again and run and go to Admin -> Manage Project -> Folder Settings. But, still see no presence of the module I have just created.

Am I doing something wrong or missing any steps? After running the create_module ant script, are there some other configs that need doing before the module appears in LabKey? Or is it because the generated module is too basic to be included as a module.

 
 
jeckels responded:  2011-07-18 17:42
Hi Trent,

Your module won't automatically get built by the Ant script, even if it's in the standard module directory.

To get your module added to the server's list, you'll need to either add it to the core system build (in <LABKEY_ROOT>/server/build.xml, add it to the lists in the "build_classes_parallel" and "build_classes_sequential" targets), or directly invoke the build.xml that was included as part of your module. Either way, you should end up with a helloworld.module in <LABKEY_ROOT>/build/deploy/modules, which will make the server notice it at startup time.

Thanks, Josh

 
trent responded:  2011-07-18 18:34
Hi, Thanks.

Not really sure what you mean to do when invoking the build.xml directly? Tried right clicking and selecting Make Module 'helloworld' but I don't think that's what you mean. Or is it just one of the ant targets you can use to invoke it?

In any case, I added a new target to the main build.xml file:

<target name="helloworld">
       <antcall target="sub_build_module">
           <param name="moduleName" value="helloworld" />        </antcall>
   </target>

(Possibly this is what you meant above? Have this target and then running that target from the list of ant scripts)

And, then did you what you mentioned above. Adding the antcall to both build_classes_parallel and build_classes_sequential

<antcall target="helloworld" />

its now appearing in the list of modules.

...Now to figure out how these work :)

 
jeckels responded:  2011-07-19 14:32
Hi Trent,

Yes, that's what I meant, though I forgot to mention that you'd need to introduce the new target for helloworld as well.

You could potentially use the build.xml that's inside of your module's directory (and either run it from the command line or add it to the list of build.xml files that IntelliJ looks at), but it's probably easiest to take the approach that you did with adding a new target.

Thanks, Josh

 
trent responded:  2011-07-19 21:18
So is it the expected behaviour for schema you create in a module not to be an option in the schema browser?

i.e. the demo module creates a demo schema, but this is not accessible through schema browser.

 
jeckels responded:  2011-07-27 17:50
Hi Trent,

For security reasons, we don't automatically expose all of the schemas and tables in the underlying database. In many cases, for example, the schema won't include a container column and you don't want a user who has access to any folder on the server to be able to access it.

If you have Java code, you can choose how to expose your tables. The simplest example is in org.labkey.api.module.SimpleModule - check out the startupAfterSpringConfig() method. It exposes all of the underlying database schemas that the module declares.

Thanks, Josh

 
trent responded:  2011-11-21 23:07
Just putting this here for documentation purposes. And in case im doing it a noobs way, someone can tell me...

For a file based module, the above method won't work. You instead need to just copy the directory to the module directory. So the target name would instead be:

<target name="helloworld" >
       <copy todir="${deploy.modules.dir}/helloworld">
           <fileset dir="${basedir}/customModules/helloworld">
           </fileset>
       </copy>
   </target>

With potential include or exclude elements inside the fileset node, to filter out particular files.