和你的环境变量作斗争 :: Sharing
未识别博客 · mep · 2004-04-04
Sharing
|
首页
|
2004-04-04
和你的环境变量作斗争
使用
Java
的时候,需要设置很多的环境变量;特别当应用涉及到很多不同的部件,我们需要将所有的环境分别作设置。而当其中有些设置相互冲突的时候,环境变量简直成了灾难。
经过一段摸索,得出一套在命令行中设置环境的方法。
首先将你的环境变量进行分组。比如,JDK1.3和JDK1.4的PATH与CLASSPATH环境变量可以作为不同的组。我们把这种分组成为“profile”。我们就有了JDK1.3的profile和JDK1.4的profile。所有的profile可以分为两类,一类是活跃的profile即active profile;一类是不活跃的profile即inactive profile。然后提供这样一个工具,当在某目录上点击右键时,有这样的菜单:
选择了Commandline with Env,就会启动一个叫EnvCollection的程序(这可以通过设置资源管理器=〉工具=〉选项=〉文件类型中目录关联的命令实现):
你可以选择设定活跃的profile,点击“OK”以后会自动地启动一个命令行窗口,并且已经将所有的活跃的profile中的环境变量设置好。
在启动命令行窗口时,首先有EnvCollection设置自己的环境(putenv),然后使用CreateProcess启动命令行,子进程会自动地继承父进程的环境。
建议环境变量使用xml进行储存。首先为这个xml编写Schema,访问xml的代码可以由Schema生成。
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSPY v2004 rel. 3 U (
http://www.xmlspy.com
) by mep (pdl) -->
<xs:schema xmlns:xs="
http://www.w3.org/2001/XMLSchema
" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="EnvCollection">
<xs:annotation>
<xs:documentation>root element</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element ref="Profile" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="ProfileType">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element ref="Environment"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="active" type="xs:boolean" use="required"/>
</xs:complexType>
<xs:element name="Profile" type="ProfileType"/>
<xs:element name="Environment">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:schema>
如果需要这个程序或者源码,请给我发邮件。
mep
引用Trackback(0)
|
编辑
评论
发表评论
最后更新
微软的Domain-Specific Language
长沙丧葬风俗旁听
服务器端线程模型
多种持续集成工具全面比较
Outlook & Blog
贝克汉姆毁掉足球?
Gnome2.8 Released
安装X.org 6.8续
安装X.org 6.8
清朝的后宫
mep Homepage
原始快照:web.archive.org