简体   繁体   中英

NetBeans/Maven/Ant Build Script Errors - Environment Variables (Linux)

I've been tasked with maintaining a large Java/C++ project, using NetBeans (7.0.1) and Maven/Ant for building, all running on CentOS 6.

I am currently having an issue with the build scripts.

The script is Maven, but calls an ant task:

<!-- create jar launch script -->
<echo file="${techsas.home}/run-exe-jar"
  message="#!/bin/bash${line.separator}java -jar -Dlog4j.configuration=file:///${TECHSAS_HOME}/log4j.xml bin/${project.artifactId}-${project.version}.jar" append="false">
</echo>

The problem is with the first line. Running the script will result in this error:

BUILD ERROR
--------------------------------------------------
An Ant BuildException has occured: java.io.FileNotFoundException: /home/techsas/NetbeansProjects/<snip>/${TECHSAS_HOME}/run-exe-jar (No such file or director)

$TECHSAS_HOME is a valid environment variable - running

echo $TECHSAS_HOME

at the command line will give the correct value.

I'm new to NetBeans and Maven - my research online hasn't turned up any solutions. I guess probably I'm making some fundamental error here.

NetBeans seems to have trouble resolving the ${TECHSAS_HOME} variable - although I don't know why it's appending it to the end of ${techsas.home} in the first place (is there a way to print the value of ${techsas.home} from within NetBeans?)

Anyway, any help is much appreciated - I'm a bit lost at the moment.

If you're using Gnome (eg on Ubuntu) you need to set environment variables in ~/.gnomerc for them to be visible to apps launched from the desktop.

See: How do I pass an environment variable to a Netbeans Makefile on Ubuntu?

Well, I worked it out. Kind of.

In the root pom, the project's home directory is defined like this:

<techsas.home>${TECHSAS_HOME}</techsas.home>

ie, copy the environment variable $TECHSAS_HOME to the Maven variable techsas.home.

However, for some reason, ${TECHSAS_HOME} isn't resolving - even though the variable is correctly set (via .gnomerc as well as .bashrc - thanks @therefromhere). ${env.TECHSAS_HOME} doesn't work either, and as far as I can tell that's the correct way to do this (eg http://docs.codehaus.org/display/MAVENUSER/MavenPropertiesGuide )

Changing it to the actual path - ie

<techsas.home>/usr/local/techsas</techsas.home>

makes it work fine. Why it's behaving like this (AFAIK the build scripts in the repo should be correct) is still a mystery to me - but at least I have a work around for the time being.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM