简体   繁体   English

通过Ant脚本在Java中加载环境变量

[英]Loading Environment Variables in java through the Ant script

I'm using jibx to convert a xml to JAVA and vice versa. 我正在使用jibx将xml转换为JAVA,反之亦然。 Here, in an Ant script, I'm using the following code to load the JIBX_HOME path from the environment variable: 在这里,在一个Ant脚本中,我正在使用以下代码从环境变量加载JIBX_HOME路径:

<property environment="env"/>
<property name="jibx-home" value="${env.JIBX_HOME}"/>

I have set the JIBX_HOME environment variable to .bashrc as follows: 我将JIBX_HOME环境变量设置为.bashrc ,如下所示:

export JIBX_HOME=/rezsystem/jibx_1_2_2/jibx

But this path is not loaded to the jibx-home property. 但是此路径未加载到jibx-home属性。 When I simply type $ set command in the terminal it prints. 当我在终端中简单地输入$ set command时,它将打印出来。 JIBX_HOME=/rezsystem/jibx_1_2_2/jibx successfully. JIBX_HOME=/rezsystem/jibx_1_2_2/jibx成功。 What have I missed here? 我在这里错过了什么? My OS is Ubuntu 12.10 and my IDE is Eclipse kepler. 我的操作系统是Ubuntu 12.10,而我的IDE是Eclipse kepler。

I think you also have to add your environment variable with PATH also 我认为您还必须使用PATH添加环境变量

like: 喜欢:

export JIBX_HOME=/rezsystem/jibx_1_2_2/jibx

export PATH=$PATH:$JIBX_HOME

If you print out the environment property using echo then is it set properly? 如果使用echo打印输出环境属性,那么它是否设置正确?

Ant properties are immutable anyway so you can just remove the entire not condition as you can't override the jibx-home property using your condition. 无论如何,Ant属性是不可变的,因此您可以删除整个not条件,因为您无法使用条件覆盖jibx-home属性。

Try running eclipse with: 尝试使用以下命令运行eclipse:

    bash -ic "path to eclipse" 

Do this after exporting JIBX_HOME variable. 导出JIBX_HOME变量后执行此操作。

I had to change my link to eclipse to this because it was not loading all env variables. 我不得不改变我的链接,以蚀到此,因为它没有加载所有环境变量。

请尝试在.bash_profile设置这些环境变量。

Make sure you add the line to the current bashrc like, key in on a shell, 确保将行添加到当前的bashrc中,例如在shell中键入,

vi ~/.bashrc

or 要么

gedit ~/.bashrc

then enter the line at the end, 然后在最后输入一行

export JIBX_HOME=/rezsystem/jibx_1_2_2/jibx

don't use sudo command, save the file and restart the system. 不要使用sudo命令,保存文件并重新启动系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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