打包示例

This commit is contained in:
jinyu 2016-04-14 15:32:10 +08:00
parent d005205627
commit 746c0f6961
4 changed files with 212 additions and 5 deletions

View File

@ -12,6 +12,29 @@
<name>weixin4j-example</name> <name>weixin4j-example</name>
<url>https://github.com/foxinmy/weixin4j/tree/master/weixin4j-example</url> <url>https://github.com/foxinmy/weixin4j/tree/master/weixin4j-example</url>
<description>weixin4j示例</description> <description>weixin4j示例</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/script/assembly.xml</descriptor>
</descriptors>
<finalName>weixin4j-server</finalName>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.foxinmy</groupId> <groupId>com.foxinmy</groupId>
@ -28,11 +51,17 @@
<artifactId>weixin4j-server</artifactId> <artifactId>weixin4j-server</artifactId>
<version>1.1.7</version> <version>1.1.7</version>
</dependency> </dependency>
<!-- 使用redis保存token时需要引用,针对weixin4j-mp|qy -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.6.0</version>
</dependency>
<!-- 使用spring容器管理Handler时需要引用,针对weixin4j-server -->
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId> <artifactId>spring-context</artifactId>
<version>4.2.1.RELEASE</version> <version>4.2.1.RELEASE</version>
<scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -18,8 +18,7 @@
</bean> </bean>
</constructor-arg> </constructor-arg>
<!-- token存储:不声明则默认使用文件方式(FileTokenStorager)保存 --> <!-- token存储:不声明则默认使用文件方式(FileTokenStorager)保存 -->
<property name="tokenStorager"> <!-- property name="tokenStorager">
<!-- redis保存token -->
<bean class="com.foxinmy.weixin4j.token.RedisTokenStorager"> <bean class="com.foxinmy.weixin4j.token.RedisTokenStorager">
<constructor-arg type="redis.clients.jedis.JedisPool"> <constructor-arg type="redis.clients.jedis.JedisPool">
<bean class="redis.clients.jedis.JedisPool"> <bean class="redis.clients.jedis.JedisPool">
@ -37,7 +36,7 @@
</bean> </bean>
</constructor-arg> </constructor-arg>
</bean> </bean>
</property> </property -->
<!-- http参数:http请求时的参数,比如代理、超时等配置信息,暂时还未实现 --> <!-- http参数:http请求时的参数,比如代理、超时等配置信息,暂时还未实现 -->
<property name="httpParams"> <property name="httpParams">
<bean class="com.foxinmy.weixin4j.http.HttpParams" /> <bean class="com.foxinmy.weixin4j.http.HttpParams" />
@ -79,7 +78,7 @@
class="com.foximy.weixin4j.example.server.Weixin4jServerStartupWithThread" class="com.foximy.weixin4j.example.server.Weixin4jServerStartupWithThread"
init-method="start" destroy-method="stop"> init-method="start" destroy-method="stop">
<!-- 端口号 微信暂时只支持80端口 所以需要自己把微信被动消息请求转发(nginx等)到这个端口上来 --> <!-- 端口号 微信暂时只支持80端口 所以需要自己把微信被动消息请求转发(nginx等)到这个端口上来 -->
<constructor-arg index="0" value="10000" /> <constructor-arg index="0" value="30000" />
<!-- token信息 --> <!-- token信息 -->
<constructor-arg index="1"> <constructor-arg index="1">
<!-- 明文模式 --> <!-- 明文模式 -->

View File

@ -0,0 +1,35 @@
<!-- zip可执行包 -->
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>bin</id>
<formats>
<format>zip</format>
</formats>
<dependencySets>
<dependencySet>
<useProjectArtifact>true</useProjectArtifact>
<outputDirectory>/lib</outputDirectory>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>src/main/script</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.sh</include>
<include>*.bat</include>
</includes>
</fileSet>
<fileSet>
<directory>target/classes</directory>
<includes>
<include>*.txt</include>
<include>*.properties</include>
<include>*.xml</include>
</includes>
<outputDirectory>/conf</outputDirectory>
</fileSet>
</fileSets>
</assembly>

View File

@ -0,0 +1,144 @@
# Jar执行脚本
ulimit -n 110000
#Jdk home
JAVA_HOME="/usr/local/java"
#Executing user
RUNNING_USER=root
#App home
APP_HOME="/usr/local/weixin4j"
#Main class
APP_MAINCLASS=com.foximy.weixin4j.example.server.Weixin4jServerStartupWithoutThread
#classpath
CLASSPATH=$APP_HOME/classes
for i in "$APP_HOME"/lib/*.jar; do
CLASSPATH="$CLASSPATH":"$i"
done
CLASSPATH="$CLASSPATH":"$APP_HOME"/conf
#jvm options
JAVA_OPTS="-Xms256m -Xmx512m -Djava.awt.headless=true -XX:MaxPermSize=128m -server -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=85 -XX:+DisableExplicitGC -Xnoclassgc -Xverify:none"
#psid
psid=0
checkpid() {
javaps=`$JAVA_HOME/bin/jps -l | grep $APP_MAINCLASS`
if [ -n "$javaps" ]; then
psid=`echo $javaps | awk '{print $1}'`
else
psid=0
fi
}
###################################
#startup
###################################
start() {
checkpid
if [ $psid -ne 0 ]; then
echo "================================"
echo "warn: $APP_MAINCLASS already started! (pid=$psid)"
echo "================================"
else
echo -n "Starting $APP_MAINCLASS ..."
# JAVA_CMD="nohup $JAVA_HOME/bin/java $JAVA_OPTS -classpath $CLASSPATH $APP_MAINCLASS >/dev/null 2>&1 &"
JAVA_CMD="$JAVA_HOME/bin/java $JAVA_OPTS -classpath $CLASSPATH $APP_MAINCLASS &"
su - $RUNNING_USER -c "$JAVA_CMD"
checkpid
if [ $psid -ne 0 ]; then
echo "(pid=$psid) [OK]"
else
echo "[Failed]"
fi
fi
}
###################################
#stop
###################################
stop() {
checkpid
if [ $psid -ne 0 ]; then
echo -n "Stopping $APP_MAINCLASS ...(pid=$psid) "
su - $RUNNING_USER -c "kill -9 $psid"
if [ $? -eq 0 ]; then
echo "[OK]"
else
echo "[Failed]"
fi
checkpid
if [ $psid -ne 0 ]; then
stop
fi
else
echo "================================"
echo "warn: $APP_MAINCLASS is not running"
echo "================================"
fi
}
###################################
#status
###################################
status() {
checkpid
if [ $psid -ne 0 ]; then
echo "$APP_MAINCLASS is running! (pid=$psid)"
else
echo "$APP_MAINCLASS is not running"
fi
}
###################################
#info
###################################
info() {
echo "System Information:"
echo "****************************"
echo `head -n 1 /etc/issue`
echo `uname -a`
echo
echo "JAVA_HOME=$JAVA_HOME"
echo `$JAVA_HOME/bin/java -version`
echo
echo "APP_HOME=$APP_HOME"
echo "APP_MAINCLASS=$APP_MAINCLASS"
echo "****************************"
}
###################################
#access only 1 argument:{start|stop|restart|status|info}
###################################
case "$1" in
'start')
start
;;
'stop')
stop
;;
'restart')
stop
start
;;
'status')
status
;;
'info')
info
;;
*)
echo "Usage: $0 {start|stop|restart|status|info}"
exit 1
esac
exit 0