• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

[Ant + Eclipse R2.0] NullPointerException accessing environment

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my Ant build scripts, I often access environment variables:
...
<property environment="env" />
...
<available classname="junit.framework.TestCase"
classpath="${env.ANT_HOME}/lib/junit.jar"
property="junit.present" />
<echo message="junit.present = ${junit.present}" />
...
When running such a build script in Eclipse, a NullPointerException is
reported at the line that declares the property for accessing the
environment:
--- BEGIN EXCEPTION ---
C:\projects\schemaloader\build.xml:6: java.lang.NullPointerException
at org.apache.tools.ant.ProjectHelper.parse(ProjectHelper.java:135)
at
org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:85)
at
org.eclipse.ant.internal.core.ant.InternalAntRunner.parseScript(InternalAntR
unner.java:237)
at
org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.ja
va:259)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.eclipse.ant.core.AntRunner.run(AntRunner.java:188)
at
org.eclipse.ui.externaltools.internal.core.AntFileRunner.execute(AntFileRunn
er.java:58)
at
org.eclipse.ui.externaltools.internal.core.DefaultRunnerContext.executeRunne
r(DefaultRunnerContext.java:334)
at
org.eclipse.ui.externaltools.internal.core.DefaultRunnerContext.run(DefaultR
unnerContext.java:384)
at
org.eclipse.ui.externaltools.internal.ui.AntLaunchWizard$1.run(AntLaunchWiza
rd.java:116)
at
org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext
.java:98)
--- Nested Exception ---
java.lang.NullPointerException
at
org.apache.tools.ant.taskdefs.Property.loadEnvironment(Property.java:253)
at org.apache.tools.ant.taskdefs.Property.execute(Property.java:183)
at
org.apache.tools.ant.ProjectHelper$TaskHandler.finished(ProjectHelper.java:4
85)
at
org.apache.tools.ant.ProjectHelper$AbstractHandler.endElement(ProjectHelper.
java:204)
at
org.xml.sax.helpers.XMLReaderAdapter.endElement(XMLReaderAdapter.java:347)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1536)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1779)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1507)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:500)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
at org.xml.sax.helpers.XMLReaderAdapter.parse(XMLReaderAdapter.java:223)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:314)
at org.apache.tools.ant.ProjectHelper.parse(ProjectHelper.java:117)
at
org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:85)
at
org.eclipse.ant.internal.core.ant.InternalAntRunner.parseScript(InternalAntR
unner.java:237)
at
org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.ja
va:259)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.eclipse.ant.core.AntRunner.run(AntRunner.java:188)
at
org.eclipse.ui.externaltools.internal.core.AntFileRunner.execute(AntFileRunn
er.java:58)
at
org.eclipse.ui.externaltools.internal.core.DefaultRunnerContext.executeRunne
r(DefaultRunnerContext.java:334)
at
org.eclipse.ui.externaltools.internal.core.DefaultRunnerContext.run(DefaultR
unnerContext.java:384)
at
org.eclipse.ui.externaltools.internal.ui.AntLaunchWizard$1.run(AntLaunchWiza
rd.java:116)
at
org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext
.java:98)
Build exception: C:\projects\schemaloader\build.xml:6:
java.lang.NullPointerException
--- END EXCEPTION ---
When running this script outside of Eclipse, there are no problems.
Development environment:
- Windows XP Professional
- Eclipse R2.0
- Installed Java SDKs: 1.3.1_03, 1.4.0_01
- Ant used externally from Eclipse: 1.4.1, 1.5
I have searched newsgroups and FAQs. I hope that I have done so adequately
and have not wasted anyone's time here.
Thanks,
Craig
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the ant script succeed when run from the command line?
Can you run ant as an external task?
 
Craig Demyanovich
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the ant script succeed when run from the command line?
Yes, as I said, it works fine outside Eclipse for either Ant 1.4.1 or 1.5.
Can you run ant as an external task?
I tried briefly, but I resorted to running via the command line.
I have not customized the Ant configuration from the default. Thus, I am quite surprised that the build fails. I suppose that I expected others to have this problem, based on my assumption that accessing the environment is a common thing to do in build scripts. However, I have found no indication that anyone else has experienced it. If others would try a build script that accesses the environment and share your results, I would greatly appreciate it. If your experience is the same as mine, perhaps a bug report is in order.
Thanks,
Craig
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been very frustrated by the Ant support in Eclipse. It seems full of this sort of wierdness. As a long-time Ant user, I have lots of Ant scripts which work fine on the command like but fail in one way or another in Eclipse.
I would have made command-line execution compatibility a main goal for Ant support, but it looks like the Eclipse folks prefer to let Eclipse produce the Ant script, and not use the features it doesn't like.
Grr.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We are using environment variables in our Ant scripts on Eclipse without any problems, both on Win2000 and Linux.
You probably should ask for help in the eclipse newsgroup or even post a bug report.
 
Craig Demyanovich
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There has been no response from the Eclipse newsgroup. I'm thankful for the replies here.
I'm hesitant to post a bug report until I'm somewhat confident that I'm not making some mistake. I have the impression that some people submit bug reports the moment that they encounter a problem.
I could post the script here; it's not lengthy or complex. I'm confident that it's correct, but more pairs of eyes couldn't hurt. If you are willing to have a look, please let me know.
Thanks again,
Craig
 
Frank Carver
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure, post it here. There are several Eclipse "power users" who hang around here, and many others of us who dabble. And if we can solve it, it may well help the next person who asks.
 
Craig Demyanovich
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Below is the build script that I've been using unsuccessfully inside Eclipse but successfully outside Eclipse. As I said earlier, the NullPointerException points to the line where I declare a property for accessing the environment.

Thanks,
Craig
[ July 23, 2002: Message edited by: Craig Demyanovich ]
 
Chris Reeves
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I too had some ant problems in eclipse.
I love ant.
So, I set it up as an external process in eclipse. This allows me to control ant, and even change the ant version without worrying about eclipse.
Plus, it puts a cool little button right there on the task bar - this makes my life much better.
See Eclipse Ant Integration (or, I want a big Ant Button)
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Craig, can you also post the Exception, please? Thanks!
 
Craig Demyanovich
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ilja Preuss:
Craig, can you also post the Exception, please? Thanks!


The exception is in my initial post, but I will include it again, formatted as code for readability. Note that the NullPointerException occurs at line 6. Line 6 becomes line 4 in the build script that I posted a little earlier in this thread: I did not account for blank lines as I did '<' and '>' when posting it. Anyway, here's the exception, generated just moment ago by a fresh attempt via Ant in Eclipse:

Thanks,
Craig
 
Craig Demyanovich
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm now thinking that I'm wrong about these things working with Ant 1.4.1 outside Eclipse. When I first switched to Windows XP Pro., I had problems with Ant. Somewhere, I set up my machine to return "Windows 2000" for the system property os.name. If it would return "Windows XP" as it first did (I still can't find where I changed that damn thing), the build script that I posted would not work outside Eclipse for Ant 1.4.1. So, for anyone with Eclipse 2.0 running on Windows XP, please verify that the script that I posted earlier fails.
If anyone knows how I can make os.name return the value it should, "Windows XP," please let me know. The search continues.
For the curious, the reason that Ant 1.4.1 fails to work properly on Windows XP for things like the environment access is that Windows XP does not meet any of the Windows-specific criteria when Ant checks on what OS it is running. Hence, Ant configures a default shell execution envrionment instead of using cmd as it would for Windows NT or 2000 or command.com for Windows 9x/ME.
Thanks for the replies,
Craig
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Craig Demyanovich:
If anyone knows how I can make os.name return the value it should, "Windows XP," please let me know. The search continues.


You could try the following:
- in "Window/Customize Perspective", make sure that "Other/External Tools" is checked
- choose "Run/External Tools/Configure"; you should get a list of recently run ant scripts
- select the one you have problems with and click "edit"
- prefix "Tool Arguments" with -Dos.name="Windows 2000"
- exit the configuration editor and start the script by selecting it from the run menu
- let us know how it worked out...
Hope it helps
 
Craig Demyanovich
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ilja.
Your suggestion works just like adding that command line parameter to ANT_HOME/bin/ant.bat, a solution I used with Ant 1.4.1. When Ant 1.5 was released, I upgraded, and I removed Ant 1.4.1 from my machine. Still, though, os.name is reported as "Windows 2000" when I run ant
-verbose. Since Ant 1.5 correctly recognizes Windows XP and I've removed Ant 1.4.1, I'm trying to determine how os.name can be reported as "Windows 2000." Perhaps I changed something outside of Ant, but I don't remember if, when or what! To further the confusion, JBoss 2.4.7 correctly reports os.name as "Windows XP" in the server log!
Anyway, I have various viable solutions: run Ant outside of Eclipse, use Ilja's above suggestion, or update the JARs in the Ant tool to those from 1.5.
Thanks all for your help.
Craig
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Craig Demyanovich:
Since Ant 1.5 correctly recognizes Windows XP and I've removed Ant 1.4.1, I'm trying to determine how os.name can be reported as "Windows 2000." Perhaps I changed something outside of Ant, but I don't remember if, when or what!


Perhaps you used the ANT_OPTS environment variable to set the os.name property?
 
Craig Demyanovich
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Ilja, for the suggestion. I finally discovered the problem. Yesterday, I posted the answer in another thread.
Craig
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the NPE in <property env> is a known bug in ant1.4.1 running on Java1.4 on windows XP. Ant1.5 fixes it, but it takes a while to propagate to the IDEs. Forte has the same problem.
The problem with IDE builds of ant is that they often make changes, so you cant just drop in your own jar. If you have to use eclipse+ant, maybe run them on a java1.3 runtime instead.
 
Whatever. Here's a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic