I've a build file which will be called from java. Please find the build.xml below.
我有一个将从java调用的构建文件。请在下面找到build.xml。
<property environment="env"/>
<echo message="${env.PATH}"/>
<echo message="${env.SSH_CONNECTION}"/>
<echo message="${env.JAVA_HOME}"/>
<echo message="${env.HOME}"/>
<echo message="${env.IS_HOME}"/>
<echo message="${basedir}"/>
Unable to fetch the environment variables if its run through java class. But the same works fine if run as ant command like "ant". Please help
如果环境变量通过java类运行,则无法获取环境变量。但是如果像“ant”这样的ant命令运行,同样的工作正常。请帮忙
iF run as JAVA then error is
iF作为JAVA运行然后错误
--- MESSAGE LOGGED
Property ${env.JAVA_HOME} has not been set
--- MESSAGE LOGGED
[echo] ${env.JAVA_HOME}
But i could see that the environment variables are set fine. If i echo the variables command line , im able to see the value.
但我可以看到环境变量设置得很好。如果我回显变量命令行,我能够看到值。
2 个解决方案
#1
I guess that the intershop studio sets environment variables for spawned processes (jobs). I cannot check it as it's a commercial product.
我想,intershop studio为衍生进程(作业)设置环境变量。我不能检查它,因为它是商业产品。
But for instance in Jenkins you have a list of environment variables which are passed to your job.
但是,例如在Jenkins中,您有一个传递给您的工作的环境变量列表。
Check the documentation for the intershop studio.
查看intershop studio的文档。
#2
Any environment variables set or pulled into Ant are instance variables.... they are only available to that instance of Ant and any process that Ant creates / calls.
设置或拉入Ant的任何环境变量都是实例变量....它们仅适用于Ant的实例以及Ant创建/调用的任何进程。
I would need to see more of how you are running the java command in order to know if your JAVA_HOME is getting over ridden elsewhere.
我需要了解更多关于如何运行java命令的信息,以便了解你的JAVA_HOME是否已经越过其他地方。
EDIT:
I think I found the issue.... In a java program (aka, a class you are running) you need to explicitly call getenv in order to import the environment variables for that instance of the java program. THEN, you need to pass that environment (aand all the variables in it) to the call to Ant so ant has access to it.
我想我发现了这个问题....在一个java程序(也就是你正在运行的类)中,你需要显式调用getenv才能导入java程序实例的环境变量。那么,你需要将该环境(及其中的所有变量)传递给Ant调用,以便ant可以访问它。
By default, ant gathers up all the enviroment variables. Java needs an explicit call to get the environment variables.
默认情况下,ant会收集所有环境变量。 Java需要显式调用来获取环境变量。
Found via: docs.oracle.com/javase/tutorial/essential/environment/env.html
发现方式:docs.oracle.com/javase/tutorial/essential/environment/env.html
#1
I guess that the intershop studio sets environment variables for spawned processes (jobs). I cannot check it as it's a commercial product.
我想,intershop studio为衍生进程(作业)设置环境变量。我不能检查它,因为它是商业产品。
But for instance in Jenkins you have a list of environment variables which are passed to your job.
但是,例如在Jenkins中,您有一个传递给您的工作的环境变量列表。
Check the documentation for the intershop studio.
查看intershop studio的文档。
#2
Any environment variables set or pulled into Ant are instance variables.... they are only available to that instance of Ant and any process that Ant creates / calls.
设置或拉入Ant的任何环境变量都是实例变量....它们仅适用于Ant的实例以及Ant创建/调用的任何进程。
I would need to see more of how you are running the java command in order to know if your JAVA_HOME is getting over ridden elsewhere.
我需要了解更多关于如何运行java命令的信息,以便了解你的JAVA_HOME是否已经越过其他地方。
EDIT:
I think I found the issue.... In a java program (aka, a class you are running) you need to explicitly call getenv in order to import the environment variables for that instance of the java program. THEN, you need to pass that environment (aand all the variables in it) to the call to Ant so ant has access to it.
我想我发现了这个问题....在一个java程序(也就是你正在运行的类)中,你需要显式调用getenv才能导入java程序实例的环境变量。那么,你需要将该环境(及其中的所有变量)传递给Ant调用,以便ant可以访问它。
By default, ant gathers up all the enviroment variables. Java needs an explicit call to get the environment variables.
默认情况下,ant会收集所有环境变量。 Java需要显式调用来获取环境变量。
Found via: docs.oracle.com/javase/tutorial/essential/environment/env.html
发现方式:docs.oracle.com/javase/tutorial/essential/environment/env.html