开发环境配置(netbeans+ant迁移到eclipse+maven)

新公司入职,接手一个离职人员的项目,拿到的源码是以一个压缩包,用netbeans开发,ant管理;前端:jsp+extjs,后端:springmvc+hibernate+activiti+spring;

开搞;

直接导入项目,发现不能识别;

开发环境配置(netbeans+ant迁移到eclipse+maven)

看到源代码里边有build.xml,遂搜索;

按照《在Eclipse中通过build.xml导入工程》操作;

有些开源工程是用ant编译的,那么这时候有时可以通过导入工程中的build.xml来将工程导入到Eclipse中,步骤如下:

选择菜单File->New->Other…->Java->Java Project from Existing Ant Buildfile,如下图:

提示Specified buildfile does not contain a javac task

开发环境配置(netbeans+ant迁移到eclipse+maven)

解决方法为:

加入下面一行:

<javac srcdir="src" destdir="bin" />

完整的为:

<?xml version="1.0" encoding="UTF-8"?>

<project name="HW.makejar" default="makejar" basedir=".">

<target name ="makejar" description="Create a jar for the HW project">

<jar jarfile="HelloWorld.jar" includes="*.class" basedir="bin" />

</target>

<javac srcdir="src" destdir="bin" />

</project>

再次导入:

开发环境配置(netbeans+ant迁移到eclipse+maven)

打开jsp文件,乱码;

部署项目报错,看日志是配置有问题,引用了开发人员本地的文件夹路径;

2015/4/15

决定换eclipse+maven;

源码管理目前有tfs,svn,自己装个git;

配置pom.xml,将之前在lib目录下的jar包配置好,设置编译插件;

将lib拷贝到一个临时目录,然后一个一个从maven在线仓库获取配置,检查eclipse里边的maven依赖,和临时目录对比,有的就将临时目录里边删掉;

用Pom.xml的Dependency Hierarchy排除更好一些,带搜索功能;

下载jar包有时候好慢,httpclient下载好慢;

imgscalr-lib-3.1只有4.x版本以上的;目前版本是4.2;

jgraphx-1.10.4.2,目前版本是jgraphx-1.10.4.1;

mybatis-3.1.1,目前版本是mybatis-3.2.2

xstream-1.3.1,目前版本是xstream-1.4.2;

问题:

ArtifactTransferException: Failure to transfer org.springframework.security:spring-security-core:jar:3.1.3.RELEASE from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval

of central has elapsed or updates are forced. Original error: Could not transfer artifact org.springframework.security:spring-security-core:jar:3.1.3.RELEASE from/to central (http://repo.maven.apache.org/maven2): The operation was cancelled.

删除本地仓的对应文件夹,update maven project;

问题:有些包在WEB-INF/lib目录下,maven在线仓没有的;

修改pom.xml添加编译参数,项目build path里边添加依赖(Add Class Folder);

<plugins>

<plugin>

<artifactId>maven-compiler-plugin</artifactId>

<configuration>

<source>1.6</source>

<target>1.6</target>

<encoding>UTF-8</encoding>

<compilerArguments>

<extdirs>src\main\webapp\WEB-INF\lib</extdirs>

</compilerArguments>

</configuration>

</plugin>

</plugins>

启动项目报错:

org.springframework.beans.factory.BeanDefinitionStoreException: Line 17 in XML document from ServletContext resource [/WEB-INF/spring-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null".

org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null".

原因:XFire Core lib 中有Spring1.2.6 与Spring 2 冲突!

先注释掉pom.xml里边pdfservlet中的依赖;

修改数据库密码和本地开发环境一样;

grant all privileges on *.* to root@"%" identified by "root" with grant option;

flush privileges;

修改启动文件的脚本startup.sh

shell判断文件是否存在:

warFile="/var /log/httpd/access.log"

if [ -f "$warFile" ]; then

……

fi

修改hostname为localhost

root登陆执行,echo "127.0.0.1 `hostname` localhost localhost.localdomain" >/etc/hosts

修改mysql的登陆密码为root;

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root');

页面报错:

org.apache.jasper.JasperException: /WEB-INF/views/management/systemsettings.jsp(207,95) The function getUserName must be used with a prefix when a default namespace is not specified

linux下的mysql有个表大小写问题

为了消除linux环境下大小写敏感问题,设置如下:vi /etc/mysql/my.cnf

在[mysqld]中添加:

lower_case_table_names = 1

vi 修改的时候如果要上下移动鼠标,按esc退出编辑模式来移动;

修改好之后要重启tomcat;

/etc/init.d/mysql restart

2015/4/16

重新导入数据,重新启动项目;

Linux建立快捷方式到tomcatlog目录,就不用每次都敲命令cd了

ln -s /app/tomcat/logs/catalina.out tomcatlogs

开发环境配置(netbeans+ant迁移到eclipse+maven)

查看当前服务器ip;

Ifconfig

启动后访问后台报错:

At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.

这样的问题是你的页面中含有<!---->的注释 去掉就好了,tomcat7.0.20.

tomcat 7对EL表达式的语法要求比较严格,例如"${owner.new}"因包含关键字new就会导致解析出错。

问题是出来了,怎么解决呢?有三种,如下:

第一种:严格遵守java规范,修改对象的属性名称,要求不包含java关键字;

第二种:修改EL表达式,例如"${owner.new}"可以修改为"${owner['new']}";

第三种:修改tomcat属性,忽略对EL表达式的关键字检查。修改$CATALINA_BASE/conf/catalina.properties文件,添加org.apache.el.parser.SKIP_IDENTIFIER_CHECK=true选项。

注意linux下文件的换行符;

貌似这样改不行;

问题:

信息: validateJarFile(/app/tomcat/webapps/srpm/WEB-INF/lib/servlet-api-2.5-20081211.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

解决方法:

1)删除项目WEB-INF/lib下的 servlet-api.jar

2)删除之前的发布文件夹

重新发布运行即可解决问题。

我是删除了war包里边的servlet-api-2.5-20081211.jar才启动起来了;

tomcat启动时要优先加载其lib下的包,这样就会出现冲突.

Linux下上移一行;光标移动当当前行,然后按pp删除,移动到目标行,按p粘贴;

删除行首空格:;

Linux上的c:url变成://

开发环境配置(netbeans+ant迁移到eclipse+maven)

坑爹的ubuntu,获取的pageContext竟然是/;

server.xml配置:

开发环境配置(netbeans+ant迁移到eclipse+maven)

修改为:

开发环境配置(netbeans+ant迁移到eclipse+maven)

设置eclipse打开jsp文件都是utf-8,设置Content Types里边的Default encoding为UTF-8;

开发环境配置(netbeans+ant迁移到eclipse+maven)

访问某个页面报错:

org.apache.jasper.JasperException: /WEB-INF/views/home/welcome.jsp(32,197) The function DisplayName must be used with a prefix when a default namespace is not specified

linux下没有这个问题;

换个最新的tomcat版本:6.0.43,问题依旧;

换用原来默认的jstl.jar和standard.jar,也不行,问题依旧;

这个是调用了类里边的方法,

The problem with your code is that the code run locally is run on Tomcat 7 and the code run on the server is run on Tomcat 6.

As soon as invocation of methods with parameters (those ()) is the feature of EL 2.2 (and higher) and it is accompanied by Servlet 3.0 compatible containers (thus Tomcat 7) your code runs fine locally.

As soon as this code is run on a Servlet 2.5 container (thus Tomcat 6) you get the mentioned error.

Still, "property-like" access (without ()) is supported by both servlet containers.

换tomcat7试试;

换用maven插件启动:

Caused by: java.lang.LinkageError: loader constraint violation: loader (instance of org/apache/catalina/loader/WebappClassLoader) previously initiated loading for a different type with name "javax/servlet/ServletContext"

是因为activiti-mule引用了servlet-api,排除掉它;

开发环境配置(netbeans+ant迁移到eclipse+maven)

引入新的:

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>servlet-api</artifactId>

<version>2.5</version>

<scope>provided</scope>

</dependency>

tomcat6还是有问题,换tomcat7就没事了;

报错:

Caused by: org.hibernate.InstantiationException: could not instantiate test objectcom.sinotaiyo.srpm.datamodels.UserGroup

缺commons.collections包;

java.lang.Error: Unresolved compilation problems:

XStream cannot be resolved to a type

XStream cannot be resolved to a type

JettisonMappedXmlDriver cannot be resolved to a type

at com.sinotaiyo.zFileUtility.JsonHelp.javaBeanToJson(JsonHelp.java:67)

缺包;引入xstream包;

liunx终端backspace不能删除字符;

主要是由于安装的是vim.tiny版本,不是vim完整版。

两种方法:

1.直接在终端输入命令 sudo apt-get install vim ,按步操作安装好vim即可。

2. 修改/etc/vim/vimrc.tiny 文件,将set compatible 设置成set nocompatible ,添加 set backspace=2 这是因为有时候系统会默认vim兼容vi,所以使用vi的命令。

发牢骚:

1、 坑好多,jsp无爱啊,各种兼容性问题,好怀念模板引擎,好怀念读写分离,只想安静的做个后端;

2、 还是要用maven管理项目,全部配置放到pom.xml,包括包依赖,包括插件,包括jdk level,新人上手就快很多了;

3、 刚刚接触了互联网项目,都是新技术,现在又回到老一代的技术,怎么回事啊,很多事试了才知道,没人在前面指路;

总结:

1、时间紧的话还是用自己熟悉的开发环境,虽然要从零搭建,但省去了熟悉新开发环境的过程,这可能是个漫长的过程,前面很多很多的坑;

2、maven很强大,又一次体会,依赖包管理、丰富优秀的插件都很好用;

上一篇:Memcache+cookie实现模拟session


下一篇:GSON使用笔记(1) -- 序列化时排除字段的几种方式