在CentOS 5.6上编译java的问题

时间:2011-05-23 21:00:56

标签: java bash compiler-construction centos

对于Windows,我只使用批处理脚本来编译我的程序:

@echo off
title Building...
echo Building Server - please wait...
echo ---------------------------------------

set javac="C:\Program Files\java\jdk1.6.0_24\bin\javac.exe"

set libs=bin;

set dirs=src\server\*.java
set dirs=%dirs% src\server\commands\*.java
set dirs=%dirs% src\server\components\*.java
set dirs=%dirs% src\server\item\*.java
set dirs=%dirs% src\server\net\*.java
set dirs=%dirs% src\server\randomevent\*.java
set dirs=%dirs% src\server\minigames\*.java
set dirs=%dirs% src\server\minigames\trawler\*.java
set dirs=%dirs% src\server\minigames\trawler\game\*.java
set dirs=%dirs% src\server\quests\*.java
set dirs=%dirs% src\server\skills\runecrafting\*.java
set dirs=%dirs% src\server\skills\slayer\*.java
set dirs=%dirs% src\server\tasks\*.java
set dirs=%dirs% src\server\tasks\net\*.java
set dirs=%dirs% src\server\threading\*.java

%javac% -classpath %libs% %dirs% -d bin
echo ---------------------------------------
title Buld complete.
echo Build complete.
pause

一切都很好。 所以我将我的项目移动到我的CentOS VPS并尝试使用bash脚本进行编译

echo Building...
echo Building Server - please wait...
echo ---------------------------------------

libs=bin
dirs=src/server/*.java
dirs=$dirs src/server/commands/*.java
dirs=$dirs src/server/components/*.java
dirs=$dirs src/server/item/*.java
dirs=$dirs src/server/net/*.java
dirs=$dirs src/server/randomevent/*.java
dirs=$dirs src/server/minigames/*.java
dirs=$dirs src/server/minigames/trawler/*.java
dirs=$dirs src/server/minigames/trawler/game/*.java
dirs=$dirs src/server/quests/*.java
dirs=$dirs src/server/skills/runecrafting/*.java
dirs=$dirs src/server/skills/slayer/*.java
dirs=$dirs src/server/tasks/*.java
dirs=$dirs src/server/tasks/net/*.java
dirs=$dirs src/server/threading/*.java

javac -classpath $libs $dirs -d bin
echo ---------------------------------------
title Buld complete.
echo Build complete.

我必须做错事。我收到这些错误:

: command not founde 4:
: No such file or directory/server/commands/*.java
: No such file or directory/server/components/*.java
: No such file or directory/server/item/*.java
: No such file or directoryc/server/net/*.java
: No such file or directoryc/server/randomevent/*.java
: No such file or directoryc/server/minigames/*.java
: No such file or directoryc/server/minigames/trawler/*.java
: No such file or directoryc/server/minigames/trawler/game/*.java
: No such file or directoryc/server/quests/*.java
: No such file or directoryc/server/skills/runecrafting/*.java
: No such file or directoryc/server/skills/slayer/*.java
: No such file or directoryc/server/tasks/*.java
: No such file or directoryc/server/tasks/net/*.java
: No such file or directoryc/server/threading/*.java
: command not founde 21:
javac: invalid flag: src/server/*.java

有人可以帮我弄清楚我做错了什么吗?是否存在语法错误?

2 个答案:

答案 0 :(得分:2)

不知道为什么通配符没有被扩展,但dirs =行不是有效的语法;你需要引用右手边。鉴于奇怪的错误消息,我会质疑bash是否被用于执行脚本。你确定是吗?

无论如何,oy。这是编译代码的一种疯狂方式。使用Antmake,它们会让您的生活更轻松。

答案 1 :(得分:1)

您需要在所有作业的右侧附近使用引号,例如:

dirs="$dirs src/server/commands/*.java"