mvn自身也是一个bat脚本。
因此,如果调用需要使用使用call进行调用
call mvn clean call mvn
mvn自身也是一个bat脚本。
因此,如果调用需要使用使用call进行调用
call mvn clean call mvn
最近几天一直在实现java的热更新。
本来以为使用classloader很容易搞定,结果走过了好几个坑。
1、classloader中的类不允许重复加载。
如果已经加载过的类,需要先判断 findLoadedClass(name)中是否存在,如果已经存在,不要再次加载。
2、classloader最初放在contextLister中,服务启动时,自动启动,结果发现异常无法补获,只好在action中手动加载来进行调试。
3、classloaderA和classloaderB加载相同的类,也会判断为不相同,因为是由不同的classloader加载的。
4、看起来需要在tomcat中使用自己的类进行加载才可以实现热更新。测试下。现在需要在tomcat设置自己的classloader,同时在加载新类时,不能再重新new classloader.
5、先测试下如何从jar中加载类。
晕死,因为我加一个判断字符串是使用的apache common中的stringutils,结果导致classloader直接死掉,还不抛出异常。看来,如果是context class loader,只使用java jdk中的类库。
6、同一个类在不同的classloader中加载,也无法相互赋值。
这里有两种解决方案:
1)在tomcat中使用custom class loader来加载所需要的所有类。
2)需要加载的类的父类和接口交给context class loader加载。这样就可以共同相同classloader加载的接口,通过不同的classloader来加载具体的实现类及子类。
现在终于使用第二种解决方案解决问题。对 classloader及类加载和热更新了解的更深入了。
同时需要测试下,多次defines类是否能行的通。
1、如果使用spring, 可以使用以下方式获得spring context中的所有的类:
public class GameReflect implements ApplicationContextAware { public ApplicationContext applicationContext; @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; } public void getAllClass(){ applicationContext.getBeansOfType(GameBaseAction.class); } }
2、除此之外,也可以从classloader中使用一种hack方式获得所有的类:
package cn.joylab.service; import java.lang.reflect.Field; import java.util.Vector; public class ClassLoaderTest extends GameBaseManagerTestCase { @org.junit.Test public void test1() { try { Field f = ClassLoader.class.getDeclaredField("classes"); f.setAccessible(true); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Vector<Class> classes = (Vector<Class>) f.get(classLoader); for (Class c : classes) { System.out.println(c); } } catch (Exception e) { e.printStackTrace(); } } }
windows下:
@echo off
cd /d %~dp0
将工作目录转至bat脚本所在的目录。
linux下:
currentDir=`dirname $0`
currentDir好为脚本所在的目录
如果有其它shell设置了环境变量则使用以下方式调用
. $shellPath/../tools/db_load_init.sh
maven默认直接访问repo仓库,但国外的仓库太慢了。
这里可以在maven/conf/setting.xml中设置代理,设置一个连接国外网速比较快的代理:
<proxies>
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>127.0.0.1</host>
<port>8087</port>
<nonProxyHosts>local.net|some.host.com|192.168.17.12|10.234.10.12</nonProxyHosts>
</proxy>
</proxies>
我这里是使用的goagent,所以就设置为本机的goagent为代理,速度果然提高了好多。
一篇介绍jsr用法的文章:
https://today.java.net/pub/a/today/2008/04/10/source-code-analysis-using-java-6-compiler-apis.html#accessing-the-abstract-syntax-tree-the-compiler-tree-api
jsr可以将java source生成为一个TreePath,可以读取到该类中的所有信息。(除了备注 -.-!)。
可以了,现在转向eclipse adt看看能否获得带备注的ast。
mvn dependency:copy-dependencies -DoutputDirectory=lib -DincludeScope=compile
将所有的使用的第三方包导出于lib目录下。
游戏服务器端打为了一个war包。
这次做项目时,希望将游戏中的通用模块及通用业务模块拆分至一个公共项目中,然后每个游戏可以分别建立一个项目来引用公共项目,可以只需要写业务逻辑,而不再需要关心其它的方面。
2013.11.06 记:
其实前几天已经解决掉了最后一个遇到的问题:这里还要感谢run jetty插件的作者。
现在开始动手进行项目改造:
<plugin> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <configuration> <attachClasses>true</attachClasses> </configuration> </plugin
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <configuration> <useCache>false</useCache> <workDirectory>target/overlay-war-folder</workDirectory> <overlays> <overlay> </overlay> <overlay> <groupId>cn.XXXXX</groupId> <artifactId>xcore</artifactId> </overlay> </overlays> </configuration> </plugin>
[ERROR] Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.mybatis.spring.mapper.MapperScannerConfigurer#0' d efined in file [D:\workspace\xcore-game\target\tmp\webapp\WEB-INF\classes\applic ationContext-mybatis.xml]: Initialization of bean failed; nested exception is ja va.lang.NoSuchFieldError: NULL: java.lang.NoSuchFieldError: NULL at org.springframework.expression.TypedValue.<clinit>(TypedValue.java:31 )
打开生成的war包,发现里面spring-expression引入了两个不同的版本,修改pom.xml将旧版本排除掉。OK,顺利解决问题。
<dependency>
<groupId>cn.kingsoft</groupId>
<artifactId>game-server</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/game-server-1.0.jar</systemPath>
</dependency>
近期评论