编译调试过程花了好几天,要做好心理准备,编译一次可能要花几个小时,特别是加上-X参数输出debug会更慢,不带还快点,每次编译出问题,调完后都得再从头开始编译,不然可能也出其他与全部编译不同的错误。带-e参数也行,可以输出完整的错误信息,编译时长会短点。后面会快一些,但至少也得半个小时起步。
另外编译过程由于要下载很多文件,所以经常会卡在一个文件下载那,我是一般卡在一个文件下载的地方时,超过10分钟,我就crtl+c,然后重新开始了。然后整个过程下载文件问题中断再重新开始编译,我可能中断了至少几十次。
想看过程出错信息的可能直接看最后。
目录
1、maven安装
(1)从http://maven.apache.org/download.cgi下载最新的安装包apache-maven-3.5.4-bin.tar.gz。
安装之前需要确保机器上已经安装了JDK并已配置环境变量。
(2)在/opt目录下解压
$ tar -zxvf apache-maven-3.5.4-bin.tar.gz
$ vim /etc/profile
(3)修改环境变量,在/etc/profile中添加以下几行
export MAVEN_HOME=/opt/apache-maven-3.5.4-bin
export PATH=${PATH}:${MAVEN_HOME}/bin
(4)然后使环境变量生效
$ source /etc/profile
(5)最后运行mvn -version
验证maven是否安装成功,如果安装成功会打印如下内容
(6)建立maven仓库
参考:https://www.cnblogs.com/-mrl/p/8952558.html
a)建立一个文件夹,假设路径为: /usr/local/maven_repository。
b)打开 maven目录下/conf/setting.xml 文件,设置我们的仓库路径:
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<localRepository>/usr/local/maven_repository</localRepository>
c)在终端运行命令将常用的包从maven中央仓库下载文件到本地:
mvn help:system
d) 没有错误的话,打开 /usr/local/maven_repository 会发现多了很多文件。
2、安装git
(1) 安装依赖的包
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
(2) 下载git源码并解压
wget https://www.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz
解压 tar zxvf git-2.9.5.tar.gz
cd git-2.9.5
(3) 编译安装
make prefix=/usr/local/git all
make prefix=/usr/local/git install
(4) 查看git
whereis git
git --version
(5) 配置环境变量
vim /etc/profile
加入export PATH=$PATH:/usr/local/git/bin
生效配置文件 source /etc/profile
3、安装nodejs和npm
$ curl -sL https://rpm.nodesource.com/setup_6.x | bash -
$ yum install -y nodejs
命令:node -v 如果输出版本号就安装成功了。
然后更新 npm (此时的 npm 命令已经随 nodejs 的安装过程给安装了,更新一下最新版本)
$ npm install npm@latest -g
命令:npm -v 输出版本号就成功安装了。
如果这条命令有问题,可以用以下方式安装npm
$ wget http://npmjs.org/install.sh
$ chmod +x ./install.sh
$ ./install.sh
更新node版本是:
先清除npm缓存:npm cache clean -f
然后安装n模块:npm install –g n
升级node.js到最新稳定版:n stable
参见:https://blog.csdn.net/qq_33242126/article/details/78505281
这个是会要在eagle-server\src\main\webapp\app目录下执行如下命令,如果执行不成功,编译也会报错,参见eagle-server\ui-build.sh文件中的命令
$ npm install
$ npm run build
4、检查代码文件的行尾换行符
因为我是从windows拷贝过来的,换行符使用的是windows的\r\n,需要替换为\n。
(1)使用"cat -A [Filename]" 查看,如下图所示,看到的为一个Windows形式的换行符,\r对应符号^M,\n对应符号$.
(2)安装dos2unix
$ yum install -y dos2unix
(3)全目录文件替换
find /opt/code/eagle-master/ -name "*" | xargs dos2unix
参考:https://blog.csdn.net/leedaning/article/details/53024290
或者命令
find . -type f -exec dos2unix {} \;
参考https://blog.csdn.net/u011537073/article/details/50603316
5、编译eagle
(1)将eagle-master.zip拷贝到/opt目录下,并解压
$ unzip eagle-master.zip
(2)调整使用内存大小
$ export MAVEN_OPTS='-Xmx1536M -Xms512M -XX:MaxPermSize=256m'
我试过-Xmx1024M,还是会报错内存不够,1536M就可以了。参考:https://www.cnblogs.com/shengs/p/4655743.html
(3)进入/opt/eagle-master目录下,执行编译命令:
$ mvn -Dmaven.test.skip=true clean package -X
-X是用来打印debug日志信息的,如果不想看debug,可以改成-e,查看错误信息。
mvn命令可参考前一篇帖子。
6、编译过程报错
(1)Could not transfer artifact org.apache.maven.plugins:maven-remote-resources-plugin:pom:1.5 from/to central
[ERROR] Plugin org.apache.maven.plugins:maven-remote-resources-plugin:1.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-remote-resources-plugin:jar:1.5: Could not transfer artifact org.apache.maven.plugins:maven-remote-resources-plugin:pom:1.5 from/to central (https://repo.maven.apache.org/maven2): Received fatal alert: protocol_version -> [Help 1]
org.apache.maven.plugin.PluginResolutionException: Plugin org.apache.maven.plugins:maven-remote-resources-plugin:1.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-remote-resources-plugin:jar:1.5
解决方法:参照1、(6)c)下载中央仓库后就好了
(2)DEBUG信息输出checkstyle的exception
[DEBUG] Keep looking, ignoring exception
java.lang.ClassNotFoundException: com.puppycrawl.tools.checkstyle.checks.annotation.CommentsIndentationCheck
[DEBUG] Keep looking, ignoring exception
java.lang.ClassNotFoundException: com.puppycrawl.tools.checkstyle.checks.header.CommentsIndentationCheck
[DEBUG] Keep looking, ignoring exception
java.lang.ClassNotFoundException: com.puppycrawl.tools.checkstyle.checks.whitespace.CommentsIndentationCheck
每次编译加上-X时,都会出一堆checkstyle的错误,忽略就好。
(3)报错:java.lang.OutOfMemoryError:Java heap space
解决方法:执行编译命令前,先执行
$ export MAVEN_OPTS='-Xmx1536M -Xms512M -XX:MaxPermSize=256m'
https://cwiki.apache.org//confluence/display/MAVEN/OutOfMemoryError
https://www.cnblogs.com/shengs/p/4655743.html
1、原因
由于服务器的JVM不够用而抛出的错误,JVM在启动的时候会自动设置Heap size的值,初始空间(即-Xms)是物理内存的1/64,最大空间(-Xmx)是物理内存的1/4。所以可以根据自己的情况进行修改JVM的-Xmn -Xms -Xmx等选项。
2、内存大小设置
Heap Size最大不要超过可用物理内存的80%,一般的要将-Xms和-Xmx选项设置为相同,而-Xmn为1/4的-Xmx值。Heap size的 -Xms -Xmn 设置不要超出物理内存的大小。
(4)GET request of: ***.jar from apache.snapshots failed: Read timed out
[ERROR] Failed to execute goal on project eagle-server: Could not resolve dependencies for project org.apache.eagle:eagle-server:jar:0.5.0-SNAPSHOT: Could not transfer artifact org.apache.eagle:eagle-hadoop-queue:jar:0.5.0-20171123.001558-270 from/to apache.snapshots (http://repository.apache.org/snapshots): GET request of: org/apache/eagle/eagle-hadoop-queue/0.5.0-SNAPSHOT/eagle-hadoop-queue-0.5.0-20171123.001558-270.jar from apache.snapshots failed: Read timed out -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project eagle-server: Could not resolve dependencies for project org.apache.eagle:eagle-server:jar:0.5.0-SNAPSHOT: Could not transfer artifact org.apache.eagle:eagle-hadoop-queue:jar:0.5.0-20171123.001558-270 from/to apache.snapshots (http://repository.apache.org/snapshots): GET request of: org/apache/eagle/eagle-hadoop-queue/0.5.0-SNAPSHOT/eagle-hadoop-queue-0.5.0-20171123.001558-270.jar from apache.snapshots failed
解决方法:手动去http://repository.apache.org/snapshots/org/apache/eagle/eagle-hadoop-queue/0.5.0-SNAPSHOT/下载eagle-hadoop-queue-0.5.0-20171123.001558-270.jar及eagle-hadoop-queue-0.5.0-20171123.001558-270.jar.sha1拷贝至中央仓库对应org/apache/eagle/eagle-hadoop-queue/0.5.0-SNAPSHOT/目录下即可。
(5)exec (exec-ui-install) on project eagle-server: Command execution failed.: Process exited with an error
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.4.0:exec (exec-ui-install) on project eagle-server: Command execution failed.: Process exited with an error: 2 (Exit value: 2) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.4.0:exec (exec-ui-install) on project eagle-server: Command execution failed.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
……
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Command execution failed.
at org.codehaus.mojo.exec.ExecMojo.execute (ExecMojo.java:276)
……
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: org.apache.commons.exec.ExecuteException: Process exited with an error: 2 (Exit value: 2)
at org.apache.commons.exec.DefaultExecutor.executeInternal (DefaultExecutor.java:404)
……
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :eagle-server
解决方法:找到配置文件中关于exec (exec-ui-install)的内容,然后找到了ui-build.sh文件,发现里面有检查git、npm、nodejs的内容,安装完后自己把里面的命令都执行一行成功后,这个问题就解决了。
echo "Environment Check..."
# Pre-build check
if [ -z "$(command -v git)" ]
then
echo "git not installed!"
exit 1
fi
if [ -z "$(command -v npm)" ]
then
echo "npm not installed!"
exit 1
fi
echo "Environment Check...Pass"
# npm install
cd src/main/webapp/app
echo "npm install..."
npm install
echo "building..."
npm run build