Multiple Ant properties files - ant

Ant seems to be ignoring one of my properties files.
<property file="local.properties" />
<property file="build.properties" />
build.properties contains the typical properties my team wants to use. I'm introducing local.properties which contains overrides for my specific workstation. We're using Eclipse for this project (I'm using Kepler), but regardless of whether I build in Eclipse or build via the command line the build fails because it is using some values in build.properties even though local.properties contains overrides.
In my specific case, my version of Java is newer than the other developers/environments. Despite specifying the version I have in local.properties, it still tries to use the compiler for the version in build.properties.
I know the values are fine because if I put my local properties in build.properties everything works.

Eclipse doesn't care about your build.xml or your properties files. That's only with Ant.
Try running ant with the -d flag, and capture STDOUT and STDERR. This will show you whether or not the local.proeprties is being read in and what values are set. It will say whether or not it's attempting to read local.properties, whether it found local.properties, and if so, what properties are being set.
Also remember that properties are set first come/first serve. You didn't say where in your build.xml you're reading in local.properties. It could be that this is being read in a target while other properties are set outside of targets. Even if they appear later in the build.xml file, properties set outside of any target are set first. If these are set, and you read in local.properties, local.properties isn't going to over ride them. I mention this because it was a problem I ran into here. Someone had a bunch of <property/> tasks placed at the end of their build.xml,and they didn't realize that these would be set before any target was run.
Again, try this:
Unix and Mac:
$ ant -d 2>&1 | tee ant.out # Allows you to see and capture the results
Windows
$ ant -d > ant.out 2>&1 # There's no "tee" command in Windows.
The output of ant.out will be thousands of lines long, but it'll help you figure out what's going on. What you post looks correct.

Related

OpenEJB: How to exclude jar from module search?

I use OpenEJB to run unit tests for applications ultimately deployed to WebSphere Application Server. My problem is a(n unavoidable) dependency on the WAS runtime jar. I've added an expression to the exclude property (I've also tried the physical path):
p.put("openejb.deployments.classpath.exclude", ".*?runtime-6.1.*?");
// p.put("openejb.deployments.classpath.exclude", "C:/Users/user/.m3/repository/was/runtime/6.1/runtime-6.1.jar");
p.put("openejb.exclude-include.order", "include-exclude");
This value is confirmed in the logs:
OpenEJB.options-2014-08-07-main--INFO -OpenEJB.options:Using 'openejb.exclude-include.order=include-exclude'
OpenEJB.options-2014-08-07-main--INFO -OpenEJB.options:Using 'openejb.deployments.classpath.include=.*eed-jar.*'
OpenEJB.options-2014-08-07-main--INFO -OpenEJB.options:Using 'openejb.deployments.classpath.exclude=.*?runtime-6.1.*?'
but the jar is still being inspected for loadable modules:
OpenEJB.startup.config-2014-08-07-main--INFO -OpenEJB.startup.config:Found EjbModule in classpath: C:\Users\user\.m3\repository\was\runtime\6.1\runtime-6.1.jar
The result is startup failure for OpenEJB:
org.apache.openejb.OpenEjbContainer$InvalidApplicationException: org.apache.openejb.config.ValidationFailedException: Module failed validation. AppModule(name=)
and
WARNING: can't load com.ibm.ws.management.j2ee.ManagementBean
org.apache.openejb.OpenEJBRuntimeException: Management
I've been creating a 0-length dummy file and renaming runtime-6.1.jar to execute the tests in Eclipse, but I need to restore the jar to run the Maven build (which Eclipse will then bind to, necessitating a restart to rename the jar).
What's the right way to exclude this jar?
You might need to set openejb.deployments.classpath.filter.descriptors to true as well. See http://tomee.apache.org/application-discovery-via-the-classpath.html
Otherwise, filters will not be applied to resources that contain a descriptor file (ejb-jar.xml).
If you still have problems, you can debug through org.apache.openejb.config.DeploymentsResolves and see why your resources aren't excluded.

knownhosts for Ant scp and sshexec tasks

My question is similar to the one asked here:
Ant scp task failure
BUILD FAILED com.jcraft.jsch.JSchException: reject HostKey: ....
My question is why are the keys not found in my knownhosts file?
No matter what kind of known_hosts file I have, the host key is rejected. Connecting via ssh works perfectly fine, and adds the relevant entries, but maybe jsch is unable to read known_hosts files generated by OpenSSH?
The Ant docs mention that the knownhosts file needs to be in SSH2 format, not SSH1. Ironically, the SSH2 format known_hosts file from OpenSSH is supposed to be ~/.ssh/known_hosts2, but the default value for knownhosts is ~/.ssh/known_hosts.
The known hosts files created by SSH2 are in ~/.ssh2/knownhosts/, so it's probably safe to count that out for the expected format. So far I've been unable to get OpenSSH to create a known_hosts2 file, and the man pages aren't much help there either. So what do the docs actually mean that the file needs to be in SSH2 format?
I've tried dsa and rsa keys, and neither work (both work with OpenSSH).
I've searched for two days and the only answers I've found are 'set trust="true'. Yes, that gets the task working, but not without turning a blind eye to security.
Here's a format I found that works with more recent versions of jch:
[xx.xx.xx.xx]:22 ssh-rsa .......
In older versions it was like:
xx.xx.xx.xx ssh-rsa ......
i.e. no square brackets and no port number. (Not sure if the port number is necessary if you're using port 22, but I tested it with a server with a non-default port assigned for SSH. And, in case it's not obvious, xx.xx.xx.xx should be the IP address of the server, or hostname or whatever.)
I found this format by getting the JCraft/jsch library to generate the known_hosts file for me. If you visit www.jcraft.com you can download a zip of the jsch source code, and some examples. Either build the source to make a jar, or download the ready-made jar as well. I unzipped the zip download and then plopped the jar file in that same directory.
There's an examples folder containing KnownHosts.java. You need to compile that file and then run it - it will ask you for your known_hosts file (just create an empty file in the default location first (~/.ssh/known_hosts) and select that. It will then ask you for details to connect to a server... Enter those, for example sshusername#xx.xx.xx.xx, and the program will try to connect and then fill the known_hosts file for you.
For convenience for blundering Windows users like me who can never remember how to do stuff from the command line, here's what you need to compile and run that KnownHosts.java file:
First, navigate to the directory (having unzipped it and put the jar file inside, as I described above).
Then run:
javac -cp jsch-0.1.49.jar examples/KnownHosts.java
to compile KnownHosts.java. And then:
java -cp "examples;jsch-0.1.49.jar" KnownHosts
to run it. Follow through the instructions above and you should have a working known_hosts file.
One final note: the KnownHosts program assumes a port of 22. I edited it to allow me to enter something like sshusername#xx.xx.xx.xx:8888 so I could specify a server with a custom port and have it work as described above. In the source of KnownHosts.java I looked for a line like:
Session session=jsch.getSession(user, host, 22);
and replaced it with:
int port = 22;
final int colonIndex = host.indexOf(':');
if (colonIndex > -1) {
final String[] split = host.split(":");
host = split[0];
port = Integer.parseInt(split[1]);
}
Session session=jsch.getSession(user, host, port);
and then compiled and ran as above.
The sshexec ant task is looking for the file 'known_hosts' by default to ${user.home}/.ssh/known_hosts
Verify the value of 'user.home' system property. Probably it points to unsuspected place.
Or provide the 'knownhosts' value explicitly in the ant task's property.
There are two parameters you might be interested in:
trust: If set to true will trust unknown hosts. The default is set to false.
knownhosts: Set to the location of your known hosts file.
The first will allow you to set the tasks to not check whether or not it's a known host. The second will allow you to specify the file that contains the known hosts. This way, you could specify it as ${user.home}/.ssh/known_hosts2and override the default.
By the way, a good way to do this is to use properties for these values, and then use a property file to override those properties:
[...]
<property name="build.properties" value="build.properties"/>
<property file="${build.properties}"/>
<!-- Can be overridden via 'build.properies' file -->
<property name="knownhosts.file" value="${user.home}/.ssh/knownhosts"/>
<property name="remote.host" value="foo-system"/>
[...]
<scp file="${copy.this.file}"
todir="${user}#{host}:${remote.dir}"
knownhosts="${knownhosts.file}"/>
[...]

Why can't I quote ant arguments?

I'm trying to run an ant target specifying an argument with spaces and it's just not working (only using the first word). I'm sure I've done this many times before without incident.
ant myTarget -Dmy.property="Three Word Argument" -d
Will yeild a line in the output like
Setting ro project property: my.property -> Three
What's going on. It seems to have "broken" after my upgrade to Ubuntu 12.04, but that doesn't sound like a likely culprit to me...
I'm running ant 1.7.1, and the above ant command will provide enough output to solve this issue...
I've tried
updating ant to be #!/bin/bash
using Three\ Word\ Property and all sorts of combinations...
Found it - I had an old alias that ended up earlier on the path that was of the form
#!/bin/bash
~/development/Ant/bin/ant $#
Changing to ~/development/Ant/bin/ant "$#" works.
Why do this you ask? Because with multiple ants on the command line it gets really tedious referencing full paths all the time (and ANT_HOME is super-sticky to the point of really breaking stuff).
Of course, symbolic links work too, which is what I've replaced the above with.

Configuring log4j at runtime

I'm using org.apache.tools.ant.listener.Log4jListener to manage logging with my ant script. The ant script is highly configurable and designed to be run different ways with different parameters and therefore I need to be able to log to files specified at runtime. I have a log4j.properties which specifies a log file to be build.log, and despite my attempts to launch ant redefining properties defined in log4j.properties have been unsuccessful.
The build ignores them and continues to write to build.log. I haven't found much support regarding writing to custom files unless it's in Java with their Logger class.
Perhaps I'm thinking this through wrong. log4j.properties isn't treated in the same way as a property file in an ant script (hence overrideable from the command line)? Is there a way I can do this intelligently without writing a custom task or something?
You setup your log4j.properties file using a system property that you can define dynamically on the command line. The property below is "${logfile.name}". An example log4j configuration would be like this:
# logfile is set to be a RollingFileAppender
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=${logfile.name}
log4j.appender.logfile.MaxFileSize=10MB
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=[%-5p]%d{yyyyMMdd#HH\:mm\:ss,SSS}\:%c - %m%n
The command line option to pass a property, when calling "ant", is "-Dlogfile.name={runtime path/filename of log file}". Replace {runtime path/filename of log file} with your file name. When ant is run this value is set as a system property. That system property is then substituted into the log4j.properties at runtime.
http://ant.apache.org/manual/running.html

Ant variable does not exists in Ubuntu 10.10

I am trying to set up ANT build.
However when I invoke build command
helloworld_15/${NAME} does not exist.
BUILD FAILED (total time: 0 seconds)
Also the configure variables does not seems to be assigned.
However i have set them into /etc/envitonment
I tried echo $<varaiable_name> and value get displayed.
Tried to google but not solutions seems am the first one having this issue.
PS: OS Ubuntu 10.10
The environment variables of the calling shell are not, by default, converted into Ant properties. If you want to access them, you need to 'import' them using something like:
<property environment="e_pref" />
in your buildfile. Once you've done that, you can access them by means of the prefix you just set:
<echo message="NAME=${e_pref.NAME}" />
You can set environment="" - i.e. an empty prefix - but you would still need the dot to access:
<echo message="NAME=${.NAME}" />
Sorted out the issue.
Somehow netbeans ant does not access environment variables when run in sudo mode.
I didnt find out a solution for that but i settled down with non sudo UI fornetbeans.
Thanx for your valuable time and help.

Resources