目录
实验概述
目的及要求
Ant的使用,熟练Eclipse项目中Ant文件的修改,并能运用Ant进行项目的自动编译和生成。
基本原理
利用Eclipse,GitHub网站等实验软件完成各个实验项目的要求。
实施环境
Eclipse
GitHub网站
云效
实验内容
1. Eclipse中建立能运行的项目,给出项目简述。
我使用的是小组大象基金项目代码。
项目简介:大象基金是一款多功能的一站式基金交易电商服务平台。旨在为各层次用户提供多方位的基金服务,提升用户群体的基金购买效率与购买体验,节约因选择基金、浏览数据等浪费的时间成本,提升用户对基金理财的自信,提升对基金理财的掌控感。
2. 利用Eclipse中的Ant功能,生成项目build.xml。
进入网址:
https://ant.apache.org/bindownload.cgi?Preferred=https%3A%2F%2Fdownloads.apache.org%2F
解压后复制ant下的bin文件夹地址:D:\Download\apache-ant-1.10.9-bin\apache-ant-1.10.9\bin
(当然要根据自己的环境更改)
打开环境变量。
在系统变量的Path中写入D:\Download\apache-ant-1.10.9-bin\apache-ant-1.10.9\bin
然后在系统变量中新建ANT_HOME
复制ant下的lib文件夹地址
在系统变量中的ClassPath中写入D:\Download\apache-ant-1.10.9-bin\apache-ant-1.10.9\lib
在cmd中输入ant -version
查看环境变量配置是否完成,完成出现版本,否则出现报错信息
选中项目,右键点击Export
选中General下的Ant Buildfiles
就生成了build.xml文件
3. 修改build.xml内容适合自选项目。
4.利用GitHub(或git.oschina.net或Gitee)网站的git仓库,提交项目文件。截图。
输入(因为之前提交过,所以这次提交剩了很多步骤)
git add .
git commit -m "add build.xml"
git push -u origin "ggznb"
git tag -a v2.1.1 -m "v2.1.1 add bulid.xml"
git push v2.1.1
git push origin v2.1.1
5.利用Maven管理eclipse中的项目
参考教程:https://lookme.blog.csdn.net/article/details/78916196
window中点击preference
左边栏Maven中点击Installation,可以在右边看到版本比较老需要下载新的
打开maven官网:https://downloads.apache.org/maven/maven-3/
选择需要的版本
点击binaries
点击.zip文件,这里单独下比较慢建议配合IDM使用。
解压压缩包后,打开文件夹D:\apache-maven-3.8.1-bin\apache-maven-3.8.1\conf
下的settings.xml
更改一下localRepository的地址,根据自己的maven文件所在文件夹地址修改,还有修改注释符号的位置(其实好像不改也没很大影响
然后修改环境变量,在系统变量中新建一个MAVEN_HOME,地址是D:\apache-maven-3.8.1-bin\apache-maven-3.8.1
然后在Path中新建一条,地址为D:\apache-maven-3.8.1-bin\apache-maven-3.8.1\bin
(根据自己的地址修改
在cmd中输入mvn -version
,出现版本为配置正确
安装m2eclipse
点击菜单栏里的help下的Install New Software
输入http://download.eclipse.org/technology/m2e/releases
勾选之后点击next
然后就开始下载了
在菜单栏window下的Preference中,选择左边栏Maven下的Installation,在右边点击Add,选择maven文件夹的地址
然后把maven勾上,点击Apply
然后点击左边栏Maven下的User Settings,选择maven的文件夹路径,再点击Apply
将Web项目转成Maven项目
项目右键选择Configure下的Convert To Maven Project
点击pom.xml,进入编辑模式
然后往里面添加依赖包。缺什么依赖包可以看import报错(建议只要导入报错的包就可以了,我多手把sql-connector加进去结果后面compile就失败了,删掉就成功
进入http://www.mvnrepository.com/
搜索dbutils,复制文字
在pom.xml中插入
修改后的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zufe</groupId>
<artifactId>eFund</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<!-- https://mvnrepository.com/artifact/commons-dbutils/commons-dbutils -->
<dependency>
<groupId>commons-dbutils</groupId>
<artifactId>commons-dbutils</artifactId>
<version>1.7</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
在项目上上右键点击Run As下的Maven build …
输入compile
出现build success证明编译成功。
然后输入package
war文件创建成功
再git到仓库里
git add .
git commit -m "maven+eclipse"
git push -u origin "ggznb"
git tag -a v2.1.3 -m "v2.1.3 transform maven edition"
git push origin v2.1.3
对了push分支的时候突然报错
! [rejected] ggznb -> ggznb (fetch first)
error: failed to push some refs to 'https://github.com/It-s-nameless/ElephantFund.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
这种情况输入git pull
然后会跳出一个可输入的小黑框,按esc键输入:wq
就可以了。
提交成功。
云效中进行maven测试
报错:
[13:55:20] [ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/root/workspace/It-s-nameless_ElephantFund_xJth). Please verify you invoked Maven from the correct directory. -> [Help 1]
[13:55:20] [ERROR]
[13:55:20] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[13:55:20] [ERROR] Re-run Maven using the -X switch to enable full debug logging.
[13:55:20] [ERROR]
[13:55:20] [ERROR] For more information about the errors and possible solutions, please read the following articles:
[13:55:20] [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException
[13:55:20] [ERROR] BUILD ERROR
[13:55:20] [ERROR] 10578930
[13:55:20] [ERROR] 步骤运行失败,返回码: 1
是因为文件下面不是直接就有pom.xml,我就重新建了一个分支,去掉最外面的文件夹,不用通过打开二级目录就可以看到pom.xml,相当于去掉了一层壳(给自己绕晕了,看图
第二次报错:
[14:08:57] [ERROR] /root/workspace/It-s-nameless_ElephantFund_YG1b/src/dispatcher/ContactUs.java:[23,20] 编码UTF8的不可映射字符
[14:08:57] [ERROR] /root/workspace/It-s-nameless_ElephantFund_YG1b/src/dispatcher/ContactUs.java:[23,21] 编码UTF8的不可映射字符
[14:08:57] [ERROR] /root/workspace/It-s-nameless_ElephantFund_YG1b/src/dispatcher/Index.java:[23,20] 编码UTF8的不可映射字符
[14:08:57] [ERROR] /root/workspace/It-s-nameless_ElephantFund_YG1b/src/dispatcher/Index.java:[23,21] 编码UTF8的不可映射字符
[14:08:57] [ERROR] /root/workspace/It-s-nameless_ElephantFund_YG1b/src/dispatcher/Register.java:[23,20] 编码UTF8的不可映射字符
[14:08:57] [ERROR] /root/workspace/It-s-nameless_ElephantFund_YG1b/src/dispatcher/Register.java:[23,21] 编码UTF8的不可映射字符
查了一下是编辑器字符集的问题,所以又把eclipse的字符集换成utf-8,重新编译项目,再上传,还是不行。(不想改了