[Scons-users] replacing ant with java

William Blevins wblevins001 at gmail.com
Wed Oct 19 17:46:34 EDT 2016


Pierre-Luc,

I will let Bill give his own thoughts, but SCons wasn't designed as a Java
build tool like Maven for example. In past builds with heterogeneous code
bases (C++/Fortran/Java/ETC), I really liked having consistent build
mechanisms. I tend to build Java with SCons in these situations. I
personally hate ANT configuration scripts with a passion, so in some
regards, this was a no brainer for me, but as I said before, SCons will not
support Java the same way that tools specifically designed for Java support
Java. If you have a lot of C++ and a little Java, then using SCons would
probably be cleaner and more flexible.

Keep in mind that my comment about the JAVACLASSPATH isn't huge, but that
behavior isn't necessarily orthogonal with how some other language builders
work. SCons aims to build correctly, but Java developers like to declare
dependencies like "dir/**" or "dir/*/*" even for shared directories like
/usr/share/java which include all the Linux java packages. Obviously, your
package wouldn't depend on ALL of these.

A sample Java sconscript might look something like below. You need to do a
little more legwork than necessary (IMO) but it's better than ANT. Just
need to learn the nuances. Once we finish the Python3 support work, I would
like to improve the Java support a bit. This is next on my personal list.

Import( 'env' )
>
> from os.path import join
>
> jars = [
>     File( join( env['JAVA_LIB_DIR'], 'antlr4-runtime' + env['JARSUFFIX'] ) ),
>     File( join( env['JAVA_LIB_DIR'], 'javax.json' + env['JARSUFFIX'] ) ),
>     File( join( env['Z3_LIB_DIR'], 'com.microsoft.z3' + env['JARSUFFIX'] ) ),
> ]
>
> env = env.Clone()
>
> for jjj in jars:
>     env.Append( JAVACLASSPATH = jjj.get_path() )
>
> manifest = env.Textfile(
>     'manifest.txt',
>     [
>         'Manifest-Version: 1.0',
>         'Main-Class: org.whitebox.Main',
>         'Class-Path: ' + '\n  '.join( env['JAVACLASSPATH'] ),
>         '',
>     ]
> )
>
> classes = env.Java(
>     env['CLASS_DIR'],
>     'org'
> )
>
> for jjj in jars:
>     Depends( classes, jjj )
>
> classes.append( manifest )
> jar = env.Jar(
>     join( env['JAR_DIR'], 'whitebox' + env['JARSUFFIX'] ),
>     classes
> )
> env.Clean( jar, env['CLASS_DIR'] )
> env.Replace( PSEUDO = jar )
>
> env = env.Clone()
> env.Append( JAVACLASSPATH = jar )
> env.AppendENVPath( 'LD_LIBRARY_PATH', Dir(env['Z3_LIB_DIR']).get_path() )
>
> pseudo = env.Pseudo( Glob('#test/test_*.pseudo') )
> env.Depends( pseudo, jar )
>
> env.Textfile( '#report.txt', pseudo )
>
>
V/R,
William

On Wed, Oct 19, 2016 at 5:16 PM, Pierre-Luc Boily <pierreluc.boily at gmail.com
> wrote:

> Bill, thx for the info, I'll have a look into that.  In an other hand, /my
> parallel build is working now/ with java.  As I said in a previous post, I
> was starting multiple time the same java compilation (through ant+scons).
> I
> kept only the main SConscript and now, it is OK.
>
> It brings me back in my original post.  I will narrow my question to "/Does
> it worth it to pass from ant to scons/"?
>
> Advantage I can see is :
> 1 - Only one build system (easier to maintain)
> 2 - Cleaning is better manage with scons (might be no longer a problem if I
> use correctly target as stated)
> 3 - With scons, I can use the powerful checksum feature.  Will not
> recompile
> for nothing
> 4 - Any other idea?
>
> But then, I am worried to do that change, I can read in a previous post :
>
> /but the builders have a lot of restrictions, so I have had difficulty in
> the past when porting from ANT -> SCons, but it is doable; some of this is
> related to bugs in the Java toolchain which didn't get appropriate
> community
> support./
>
> Plus :
> /For example, items added to the JAVACLASSPATH are not automatically added
> as dependencies./
>
> I want to hear your opinion =)
>
>
>
> --
> View this message in context: http://scons.1086193.n5.
> nabble.com/replacing-ant-with-java-tp40648p40662.html
> Sent from the Users mailing list archive at Nabble.com.
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20161019/3bd5c048/attachment.html>


More information about the Scons-users mailing list