最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【记录】cygwin中给docbook的webhelp中的classpath的值加上环境变量中已有的java的CLASSPATH

makefile crifan 2363浏览 0评论

【背景】

之前在:

【已解决】docbook中去make webhelp编译webhelp结果出错:Error: Could not find or load main class com.nexwave.nquindexer.IndexerMain

已经写成了:

#classpath := $(INDEXER_JAR):$(TAGSOUP_JAR):$(LUCENE_ANALYZER_JAR):$(LUCENE_CORE_JAR)
#【已解决】docbook中去make webhelp编译webhelp结果出错:Error: Could not find or load main class com.nexwave.nquindexer.IndexerMain
#https://www.crifan.com/docbook_make_webhelp_error__could_not_find_or_load_main_class_com_nexwave_nquindexer_indexermain/
OS_NAME = $(shell uname -o)
LC_OS_NAME = $(shell echo $(OS_NAME) | tr '[A-Z]' '[a-z]')
ifeq ($(LC_OS_NAME), cygwin)
classpath := "$(INDEXER_JAR);$(TAGSOUP_JAR);$(LUCENE_ANALYZER_JAR);$(LUCENE_CORE_JAR)"
else
classpath := $(INDEXER_JAR):$(TAGSOUP_JAR):$(LUCENE_ANALYZER_JAR):$(LUCENE_CORE_JAR)
endif

然后此处,继续去:

对于classpath的路径,

至少是对于当前的cygwin,是windows的平台,

还是想要先从环境变量中获得原先的java的CLASSPATH的值

再去加上当前的要设置的classpath路径,

并且最后加上引号,

这样就实现了,在不影响路径的前提下,解决了cygwin中路径带空格等问题,

保证所用到的classpath的值,

是当前已经设置好的java的CLASSPATH,加上当前针对docbook的webhelp的classpath的值。

【折腾过程】

1.这就涉及到,makefile中,先要获得,环境变量中,已有的CLASSPATH的值是如何。

2.关于这部分,涉及到makefile中的,给变量赋值,的几种方式

  • :=
  • ?=
  • +=
  • =

需要去参考之前:

【整理】makefile的参考资料:在线手册

总结的makefile的在线文档:

6.5 Setting Variables

3.学习到的是:

  • =赋值:(recursively expanded)递归扩展变量
  • :=赋值:(simply expanded)简单扩展变量

但是看了:

6.2 The Two Flavors of Variables

的解释,还是很晕,很复杂。。

4.还是只是去看看:

6.9 Variables from the Environment

然后去试试:

CLASSPATH_FROM_ENV = $(CLASSPATH)

test_classpath:
	@echo $(CLASSPATH_FROM_ENV)

结果是:

无法执行:

CLi@PC-CLI-1 ~/develop/docbook/books/crifanlib_python/src
$ make test_classpath
.
/bin/sh: C:Program: command not found
/bin/sh: D:DevToolDD_ParserParserANTLRantlrantlr-4.0-complete.jar: command not found
make: *** [test_classpath] Error 127

5.再去试试:

#CLASSPATH_FROM_ENV = $(CLASSPATH)
CLASSPATH_FROM_ENV := $(CLASSPATH)

test_classpath:
	@echo $(CLASSPATH_FROM_ENV)

结果:

CLi@PC-CLI-1 ~/develop/docbook/books/crifanlib_python/src
$ make test_classpath
.
/bin/sh: C:Program: command not found
/bin/sh: D:DevToolDD_ParserParserANTLRantlrantlr-4.0-complete.jar: command not found
make: *** [test_classpath] Error 127

6.再去试试:

CLi@PC-CLI-1 ~/develop/docbook/books/crifanlib_python/src
$ echo $CLASSPATH
.;C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar;D:\DevTool\DD_Parser\Parser\ANTLR\antlr\antlr-4.0-complete.jar;

以及:

#CLASSPATH_FROM_ENV = $(CLASSPATH)
#CLASSPATH_FROM_ENV := $(CLASSPATH)
CLASSPATH_FROM_ENV ?= $(CLASSPATH)

test_classpath:
	@echo "$(CLASSPATH_FROM_ENV)"

结果是:

CLi@PC-CLI-1 ~/develop/docbook/books/crifanlib_python/src
$ make test_classpath
.;C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar;D:\DevTool\DD_Parser\Parser\ANTLR\antlr\antlr-4.0-complete.jar;

7.再回去试试:

#CLASSPATH_FROM_ENV = $(CLASSPATH)
CLASSPATH_FROM_ENV := $(CLASSPATH)
#CLASSPATH_FROM_ENV ?= $(CLASSPATH)

test_classpath:
	@echo "$(CLASSPATH_FROM_ENV)"

结果是:

CLi@PC-CLI-1 ~/develop/docbook/books/crifanlib_python/src
$ make test_classpath
.;C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar;D:\DevTool\DD_Parser\Parser\ANTLR\antlr\antlr-4.0-complete.jar;

8.试试:

CLASSPATH_FROM_ENV = $(CLASSPATH)
#CLASSPATH_FROM_ENV := $(CLASSPATH)
#CLASSPATH_FROM_ENV ?= $(CLASSPATH)

test_classpath:
	@echo "$(CLASSPATH_FROM_ENV)"

结果是:

CLi@PC-CLI-1 ~/develop/docbook/books/crifanlib_python/src
$ make test_classpath
.;C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar;D:\DevTool\DD_Parser\Parser\ANTLR\antlr\antlr-4.0-complete.jar;

9.然后可以继续去加上后面的值了。

最后是,用:

# =================================================
# You probably don't need to change anything below
# unless you choose to add a validation step.
# ================================================
INDEXER_JAR         := $(TOOLS_XSL_NS_EXTENSIONS)/webhelpindexer.jar
TAGSOUP_JAR         := $(TOOLS_XSL_NS_EXTENSIONS)/tagsoup-1.2.1.jar
LUCENE_ANALYZER_JAR := $(TOOLS_XSL_NS_EXTENSIONS)/lucene-analyzers-3.0.0.jar
LUCENE_CORE_JAR     := $(TOOLS_XSL_NS_EXTENSIONS)/lucene-core-3.0.0.jar

#manually set value for test in linux
OS_NAME_LOWCASE=linux
CLASSPATH=.:/usr/bin/java

CLASSPATH_FROM_ENV = $(CLASSPATH)
#CLASSPATH_FROM_ENV := $(CLASSPATH)
#CLASSPATH_FROM_ENV ?= $(CLASSPATH)

#WEBHELP_CLASSPATH := $(INDEXER_JAR):$(TAGSOUP_JAR):$(LUCENE_ANALYZER_JAR):$(LUCENE_CORE_JAR)
#under Windows(Cygwin), (java classpath)
#(1)path seperator is semicolon ';' (not Linux's colon ':')
#(2) command contain semicolon means multile command, so need quote
# so become -> "path1;path2;path3"
#detail can refer:
#【已解决】docbook中去make webhelp编译webhelp结果出错:Error: Could not find or load main class com.nexwave.nquindexer.IndexerMain
#https://www.crifan.com/docbook_make_webhelp_error__could_not_find_or_load_main_class_com_nexwave_nquindexer_indexermain/
ifeq ($(OS_NAME_LOWCASE), cygwin)
PATH_DELIMITER = ;
else
PATH_DELIMITER = :
endif

#WEBHELP_CLASSPATH := "$(INDEXER_JAR);$(TAGSOUP_JAR);$(LUCENE_ANALYZER_JAR);$(LUCENE_CORE_JAR)"
#WEBHELP_CLASSPATH := $(INDEXER_JAR):$(TAGSOUP_JAR):$(LUCENE_ANALYZER_JAR):$(LUCENE_CORE_JAR)
#WEBHELP_CLASSPATH := "$(CLASSPATH_FROM_ENV)$(PATH_DELIMITER)$(INDEXER_JAR)$(PATH_DELIMITER)$(TAGSOUP_JAR)$(PATH_DELIMITER)$(LUCENE_ANALYZER_JAR)$(PATH_DELIMITER)$(LUCENE_CORE_JAR)"
#WEBHELP_CLASSPATH = "$(INDEXER_JAR)$(PATH_DELIMITER)$(TAGSOUP_JAR)$(PATH_DELIMITER)$(LUCENE_ANALYZER_JAR)$(PATH_DELIMITER)$(LUCENE_CORE_JAR)$(PATH_DELIMITER)$(CLASSPATH_FROM_ENV)"
WEBHELP_CLASSPATH := "$(INDEXER_JAR)$(PATH_DELIMITER)$(TAGSOUP_JAR)$(PATH_DELIMITER)$(LUCENE_ANALYZER_JAR)$(PATH_DELIMITER)$(LUCENE_CORE_JAR)$(PATH_DELIMITER)$(CLASSPATH_FROM_ENV)"

test_classpath:
	@echo "CLASSPATH_FROM_ENV=$(CLASSPATH_FROM_ENV)"
	@echo "OS_NAME_LOWCASE=$(OS_NAME_LOWCASE)"
	@echo "PATH_DELIMITER=$(PATH_DELIMITER)"
	@echo $(WEBHELP_CLASSPATH)

可以得到要的输出:

CLi@PC-CLI-1 ~/develop/docbook/books/crifanlib_python/src
$ make test_classpath
CLASSPATH_FROM_ENV=.:/usr/bin/java
OS_NAME_LOWCASE=linux
PATH_DELIMITER=:
D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/tools/docbook-xsl-ns-1.78.1/extensions/webhelpindexer.jar:D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/tools/docbook-xsl-ns-1.78.1/extensions/tagsoup-1.2.1.jar:D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/tools/docbook-xsl-ns-1.78.1/extensions/lucene-analyzers-3.0.0.jar:D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/tools/docbook-xsl-ns-1.78.1/extensions/lucene-core-3.0.0.jar:.:/usr/bin/java

不加针对linux的测试的赋值,回到正常的此处的cygwin时:

# =================================================
# You probably don't need to change anything below
# unless you choose to add a validation step.
# ================================================
INDEXER_JAR         := $(TOOLS_XSL_NS_EXTENSIONS)/webhelpindexer.jar
TAGSOUP_JAR         := $(TOOLS_XSL_NS_EXTENSIONS)/tagsoup-1.2.1.jar
LUCENE_ANALYZER_JAR := $(TOOLS_XSL_NS_EXTENSIONS)/lucene-analyzers-3.0.0.jar
LUCENE_CORE_JAR     := $(TOOLS_XSL_NS_EXTENSIONS)/lucene-core-3.0.0.jar

#manually set value for test in linux
#OS_NAME_LOWCASE=linux
#CLASSPATH=.:/usr/bin/java

CLASSPATH_FROM_ENV = $(CLASSPATH)
#CLASSPATH_FROM_ENV := $(CLASSPATH)
#CLASSPATH_FROM_ENV ?= $(CLASSPATH)

#WEBHELP_CLASSPATH := $(INDEXER_JAR):$(TAGSOUP_JAR):$(LUCENE_ANALYZER_JAR):$(LUCENE_CORE_JAR)
#under Windows(Cygwin), (java classpath)
#(1)path seperator is semicolon ';' (not Linux's colon ':')
#(2) command contain semicolon means multile command, so need quote
# so become -> "path1;path2;path3"
#detail can refer:
#【已解决】docbook中去make webhelp编译webhelp结果出错:Error: Could not find or load main class com.nexwave.nquindexer.IndexerMain
#https://www.crifan.com/docbook_make_webhelp_error__could_not_find_or_load_main_class_com_nexwave_nquindexer_indexermain/
ifeq ($(OS_NAME_LOWCASE), cygwin)
PATH_DELIMITER = ;
else
PATH_DELIMITER = :
endif

#WEBHELP_CLASSPATH := "$(INDEXER_JAR);$(TAGSOUP_JAR);$(LUCENE_ANALYZER_JAR);$(LUCENE_CORE_JAR)"
#WEBHELP_CLASSPATH := $(INDEXER_JAR):$(TAGSOUP_JAR):$(LUCENE_ANALYZER_JAR):$(LUCENE_CORE_JAR)
#WEBHELP_CLASSPATH := "$(CLASSPATH_FROM_ENV)$(PATH_DELIMITER)$(INDEXER_JAR)$(PATH_DELIMITER)$(TAGSOUP_JAR)$(PATH_DELIMITER)$(LUCENE_ANALYZER_JAR)$(PATH_DELIMITER)$(LUCENE_CORE_JAR)"
#WEBHELP_CLASSPATH = "$(INDEXER_JAR)$(PATH_DELIMITER)$(TAGSOUP_JAR)$(PATH_DELIMITER)$(LUCENE_ANALYZER_JAR)$(PATH_DELIMITER)$(LUCENE_CORE_JAR)$(PATH_DELIMITER)$(CLASSPATH_FROM_ENV)"
WEBHELP_CLASSPATH := "$(INDEXER_JAR)$(PATH_DELIMITER)$(TAGSOUP_JAR)$(PATH_DELIMITER)$(LUCENE_ANALYZER_JAR)$(PATH_DELIMITER)$(LUCENE_CORE_JAR)$(PATH_DELIMITER)$(CLASSPATH_FROM_ENV)"

test_classpath:
	@echo "CLASSPATH_FROM_ENV=$(CLASSPATH_FROM_ENV)"
	@echo "OS_NAME_LOWCASE=$(OS_NAME_LOWCASE)"
	@echo "PATH_DELIMITER=$(PATH_DELIMITER)"
	@echo $(WEBHELP_CLASSPATH)

结果是:

CLi@PC-CLI-1 ~/develop/docbook/books/crifanlib_python/src
$ make test_classpath
CLASSPATH_FROM_ENV=.;C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar;D:\DevTool\DD_Parser\Parser\ANTLR\antlr\antlr-4.0-complete.jar;
OS_NAME_LOWCASE=cygwin
PATH_DELIMITER=;
D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/tools/docbook-xsl-ns-1.78.1/extensions/webhelpindexer.jar;D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/tools/docbook-xsl-ns-1.78.1/extensions/tagsoup-1.2.1.jar;D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/tools/docbook-xsl-ns-1.78.1/extensions/lucene-analyzers-3.0.0.jar;D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/tools/docbook-xsl-ns-1.78.1/extensions/lucene-core-3.0.0.jar;.;C:\Program Files\Java\jdk1.7.0_11\jre\lib\rt.jar;D:\DevTool\DD_Parser\Parser\ANTLR\antlr\antlr-4.0-complete.jar;

 

【总结】

1.此处,从cygwin中,makefile中,从环境变量中获得对应的,windows的Java的CLASSPATH 的值,直接使用:

CLASSPATH_FROM_ENV = $(CLASSPATH)

即可。

写成:

CLASSPATH_FROM_ENV := $(CLASSPATH)

或:

CLASSPATH_FROM_ENV ?= $(CLASSPATH)

都可以。

2.然后此处,要先获得Java的CLASSPATH

然后判断当前os类型是cygwin还是linux,

决定路径的分隔符是分号还是冒号

然后再加上当前docbook的webhelp的classpath的路径

最终是使用:

# =================================================
# You probably don't need to change anything below
# unless you choose to add a validation step.
# ================================================
INDEXER_JAR         := $(TOOLS_XSL_NS_EXTENSIONS)/webhelpindexer.jar
TAGSOUP_JAR         := $(TOOLS_XSL_NS_EXTENSIONS)/tagsoup-1.2.1.jar
LUCENE_ANALYZER_JAR := $(TOOLS_XSL_NS_EXTENSIONS)/lucene-analyzers-3.0.0.jar
LUCENE_CORE_JAR     := $(TOOLS_XSL_NS_EXTENSIONS)/lucene-core-3.0.0.jar

#manually set value for test in linux
#OS_NAME_LOWCASE=linux
#CLASSPATH=.:/usr/bin/java

CLASSPATH_FROM_ENV = $(CLASSPATH)
#CLASSPATH_FROM_ENV := $(CLASSPATH)
#CLASSPATH_FROM_ENV ?= $(CLASSPATH)

#WEBHELP_CLASSPATH := $(INDEXER_JAR):$(TAGSOUP_JAR):$(LUCENE_ANALYZER_JAR):$(LUCENE_CORE_JAR)
#under Windows(Cygwin), (java classpath)
#(1)path seperator is semicolon ';' (not Linux's colon ':')
#(2) command contain semicolon means multile command, so need quote
# so become -> "path1;path2;path3"
#detail can refer:
#【已解决】docbook中去make webhelp编译webhelp结果出错:Error: Could not find or load main class com.nexwave.nquindexer.IndexerMain
#https://www.crifan.com/docbook_make_webhelp_error__could_not_find_or_load_main_class_com_nexwave_nquindexer_indexermain/
ifeq ($(OS_NAME_LOWCASE), cygwin)
PATH_DELIMITER = ;
else
PATH_DELIMITER = :
endif

#WEBHELP_CLASSPATH := "$(INDEXER_JAR);$(TAGSOUP_JAR);$(LUCENE_ANALYZER_JAR);$(LUCENE_CORE_JAR)"
#WEBHELP_CLASSPATH := $(INDEXER_JAR):$(TAGSOUP_JAR):$(LUCENE_ANALYZER_JAR):$(LUCENE_CORE_JAR)
#WEBHELP_CLASSPATH := "$(CLASSPATH_FROM_ENV)$(PATH_DELIMITER)$(INDEXER_JAR)$(PATH_DELIMITER)$(TAGSOUP_JAR)$(PATH_DELIMITER)$(LUCENE_ANALYZER_JAR)$(PATH_DELIMITER)$(LUCENE_CORE_JAR)"
#WEBHELP_CLASSPATH = "$(INDEXER_JAR)$(PATH_DELIMITER)$(TAGSOUP_JAR)$(PATH_DELIMITER)$(LUCENE_ANALYZER_JAR)$(PATH_DELIMITER)$(LUCENE_CORE_JAR)$(PATH_DELIMITER)$(CLASSPATH_FROM_ENV)"
WEBHELP_CLASSPATH := "$(INDEXER_JAR)$(PATH_DELIMITER)$(TAGSOUP_JAR)$(PATH_DELIMITER)$(LUCENE_ANALYZER_JAR)$(PATH_DELIMITER)$(LUCENE_CORE_JAR)$(PATH_DELIMITER)$(CLASSPATH_FROM_ENV)"

test_classpath:
	@echo "CLASSPATH_FROM_ENV=$(CLASSPATH_FROM_ENV)"
	@echo "OS_NAME_LOWCASE=$(OS_NAME_LOWCASE)"
	@echo "PATH_DELIMITER=$(PATH_DELIMITER)"
	@echo $(WEBHELP_CLASSPATH)

的配置,而使得后面的,docbook在makefile中去处理webhelp:

webhelp_index:
	java \
        -DhtmlDir=$(OUTPUT_DIR_WEBHELP) \
        -DindexerLanguage=$(WEBHELP_INDEX_LANGUAGE) \
        -DhtmlExtension=html \
        -DdoStem=true \
        -DindexerExcludedFiles=$(INDEXER_EXCLUDED_FILES) \
        -Dorg.xml.sax.driver=org.ccil.cowan.tagsoup.Parser \
        -Djavax.xml.parsers.SAXParserFactory=org.ccil.cowan.tagsoup.jaxp.SAXFactoryImpl \
        -classpath $(WEBHELP_CLASSPATH) \
        com.nexwave.nquindexer.IndexerMain
	mkdir -p ${OUTPUT_DIR_WEBHELP}/search
	cp -r $(TOOLS_XSL_NS_WEBHELP)/template/search/* ${OUTPUT_DIR_WEBHELP}/search

就是正常的了。

转载请注明:在路上 » 【记录】cygwin中给docbook的webhelp中的classpath的值加上环境变量中已有的java的CLASSPATH

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.203 seconds, using 22.46MB memory