posts - 88, comments - 3, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

maven项目中有很多本地三方依赖,但是一个一个加入dependency + system scope又很麻烦,又貌似没有搜索到通配符的成功案例,但是从stackoverflow上看到一个插件addjars-maven-plugin, 可以很好解决这类需求:
    <build>
        
<plugins>
            
<plugin>
                
<groupId>com.googlecode.addjars-maven-plugin</groupId>
                
<artifactId>addjars-maven-plugin</artifactId>
                
<version>1.0.2</version>
                
<executions>
                    
<execution>
                        
<goals>
                            
<goal>add-jars</goal>
                        
</goals>
                        
<configuration>
                            
<resources>
                                
<resource>
                                    
<directory>${basedir}/../lib</directory>
                                
</resource>
                            
</resources>
                        
</configuration>
                    
</execution>
                
</executions>
            
</plugin>
            
<plugin>
                
<groupId>org.apache.maven.plugins</groupId>
                
<artifactId>maven-assembly-plugin</artifactId>
                
<version>${maven.assembly.version}</version>
                
<configuration>
                    
<descriptorRefs>
                        
<descriptorRef>jar-with-dependencies</descriptorRef>
                    
</descriptorRefs>
                    
<appendAssemblyId>false</appendAssemblyId>
                
</configuration>
                
<executions>
                    
<execution>
                        
<phase>package</phase>
                        
<goals>
                            
<goal>single</goal>
                        
</goals>
                    
</execution>
                
</executions>
            
</plugin>
        
</plugins>
    
</build>

把项目中依赖的三方jars全放到lib目录里,就全部会打包到release jar里了

posted @ 2013-10-30 14:03 Milo的海域 阅读(1861) | 评论 (0)编辑 收藏

#include <stdio.h>
#include 
<stdlib.h>
#include 
<string.h>
#include 
<arpa/inet.h>
#include 
<inttypes.h>

uint64_t htonll(uint64_t val) {
    
return (((uint64_t) htonl(val)) << 32+ htonl(val >> 32);
}

uint64_t ntohll(uint64_t val) {
    
return (((uint64_t) ntohl(val)) << 32+ ntohl(val >> 32);
}
int main() {
    uint64_t hll 
= 0x1122334455667788;
    printf(
"uint64: %"PRIu64"\n", hll);
    printf(
"0x%"PRIX64"\n", hll);
    printf(
"htonll(hll) = 0x%"PRIX64"\n", htonll(hll));
    printf(
"ntohll(htonll(hll)) = 0x%"PRIX64"\n", ntohll(htonll(hll)));
    printf(
"ntohll(hll) = 0x%"PRIX64"\n", ntohll(hll)); // no change
    return 1;
}

big endian(network byte order), little endian (host byte order in intel arch)

posted @ 2013-07-23 16:42 Milo的海域 阅读(3281) | 评论 (0)编辑 收藏

用jd-eclipse 插件来反编译java class文件的输出还是挺nice的,虽然阅读方便了 但是对debug确造成一定的困扰,主要问题是line number的不match.
Google了下遇到类似问题的真不少。最终找到了解决方案:
http://sourceforge.net/projects/realignmentjd/files/
-----------------

1. Download JD-Eclipse and JD-GUI - http://java.decompiler.free.fr/ and install.
2. Put a file realignment.jd.ide.eclipse_1.0.2.jar in eclipse/plugins directory.
    To use Realignment feature it is necessary to open the menu Preferences/General/Editors/File Associations and to select "*.class" file type and to choose "Realignment for JD Class File Editor" for Associated editors.
    Another possibility is the batch realignment after processing JD-GUI. To work properly you must to switch on the property "Display line numbers" in Help/Preferences of JD-GUI.
    To use this feature it is necessary to open the menu Preferences/Java/Decompiler/Batch Realignment and click button "Open dialog". Existing limitation: the realignment is performed only for the methods.
    To work properly it is necessary that the property "Display line numbers" in menu "Preferences/Java/Decompiler" was active.


JD-Eclipse插件 + realignment 补丁让优雅的debug class 文件成为可能。

如果只是为了阅读class代码,建议不要用realignment 补丁,这样会降低代码的可读性(会多出大量的空行)
 

posted @ 2013-02-22 15:01 Milo的海域 阅读(2031) | 评论 (0)编辑 收藏


sudo dpkg -l \*erlang\*
Desired
=Unknown/Install/Remove/Purge/Hold
| Status
=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?
=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                          Version                       Description
+++-
=============================-=============================-==========================================================================
ii  erlang                        
1:14.b.4-dfsg-1ubuntu1        Concurrent, real-time, distributed functional language
un  erlang-abi-
13.a               <none>                        (no description available)
ii  erlang-appmon                 
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP application monitor
ii  erlang-asn1                   
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP modules for ASN.1 support
rc  erlang-base                   
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP virtual machine and base applications
ii  erlang-base-hipe              
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP HiPE enabled virtual machine and base applications
ii  erlang-common-test            
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP application for automated testing
ii  erlang-corba                  
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP applications for CORBA support
ii  erlang-crypto                 
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP cryptographic modules
ii  erlang-debugger               
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP application for debugging and testing
ii  erlang-dev                    
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP development libraries and headers
ii  erlang-dialyzer               
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP discrepancy analyzer application
ii  erlang-diameter               
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP implementation of RFC 3588 protocol
ii  erlang-doc                    
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP HTML/PDF documentation
un  erlang-doc-html               <none>                        (no description available)
ii  erlang-docbuilder             
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP application for building HTML documentation
ii  erlang-edoc                   
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP module for generating documentation
ii  erlang-erl-docgen             
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP documentation stylesheets
ii  erlang-et                     
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP event tracer application
ii  erlang-eunit                  
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP module for unit testing
ii  erlang-examples               
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP application examples
ii  erlang-gs                     
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP graphics system
ii  erlang-ic                     
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP IDL compiler
ii  erlang-ic-java                
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP IDL compiler (Java classes)
ii  erlang-inets                  
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP Internet clients and servers
ii  erlang-inviso                 
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP trace tool
ii  erlang-jinterface             
1:14.b.4-dfsg-1ubuntu1        Java communication tool to Erlang
ii  erlang-manpages               
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP manual pages
ii  erlang-megaco                 
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP implementation of Megaco/H.248 protocol
ii  erlang-mnesia                 
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP distributed relational/object hybrid database
ii  erlang-mode                   
1:14.b.4-dfsg-1ubuntu1        Erlang major editing mode for Emacs
ii  erlang-nox                    
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP applications that don't require X Window System
ii  erlang-observer               
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP application for investigating distributed systems
ii  erlang-odbc                   
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP interface to SQL databases
ii  erlang-os-mon                 
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP operating system monitor
ii  erlang-parsetools             
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP parsing tools
ii  erlang-percept                
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP concurrency profiling tool
ii  erlang-pman                   
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP process manager
ii  erlang-public-key             
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP public key infrastructure
ii  erlang-reltool                
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP release management tool
ii  erlang-runtime-tools          
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP runtime tracing/debugging tools
ii  erlang-snmp                   
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP SNMP applications
ii  erlang-src                    
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP applications sources
ii  erlang-ssh                    
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP implementation of SSH protocol
ii  erlang-ssl                    
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP implementation of SSL
ii  erlang-syntax-tools           
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP modules for handling abstract Erlang syntax trees
ii  erlang-test-server            
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP server for automated application testing
ii  erlang-toolbar                
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP graphical toolbar
ii  erlang-tools                  
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP various tools
ii  erlang-tv                     
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP table viewer
ii  erlang-typer                  
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP code type annotator
ii  erlang-webtool                
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP helper for web-based tools
ii  erlang-x11                    
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP applications that require X Window System
ii  erlang-xmerl                  
1:14.b.4-dfsg-1ubuntu1        Erlang/OTP XML tools

erlang-dev包含头文件,erlang-src包含源代码,erlang-debugger包含调试工具,erlang-base包含虚拟机

还可以根据package 名字的suffix察看erlang man doc,比如
man 3erl erlang
man 3erl mnesia
man 3erl io

posted @ 2013-01-15 11:34 Milo的海域 阅读(641) | 评论 (0)编辑 收藏

命令行调试erlang程序报错:
2> c(hello, [debug_info]).
{ok
,hello}
3> im().
Call to i:im/
0 in application debugger failed.
ok

google之原来是erlang-debugger没装
sudo apt-get install erlang-debugger

然后Monitor窗口就出来了。不过用eclipse 的erlide插件调试也可以。

posted @ 2013-01-11 17:06 Milo的海域 阅读(440) | 评论 (0)编辑 收藏

mvn 执行外部命令
命令行模式
mvn exec:exec -Dexec.executable=sh -Dexec.workingdir=./bin -Dexec.args=hello.sh

配置文件形式
                        <plugin>
                                <groupId>org.codehaus.mojo</groupId>
                                <artifactId>exec-maven-plugin</artifactId>
                                <executions>
                                        <execution>
                                                <id>test-exec</id>
                                                <phase>initialize</phase>
                                                <configuration>
                                                        <executable>sh</executable>
                                                        <workingDirectory>./bin</workingDirectory>
                                                        <arguments>
                                                                <argument>hello.sh</argument>
                                                        </arguments>
                                                </configuration>
                                                <goals>
                                                        <goal>exec</goal>
                                                </goals>
                                        </execution>
                                </executions>
                        </plugin>

mvn 生成java项目
生成骨架
mvn archetype:generate -DgroupId=com.abc.product -DartifactId=product -DpackageName=com.abc.product -DarchetypeArtifactId=maven-archetype-quickstart

转成eclipse能识别的java 项目
mvn eclipse:eclipse
导入eclipse 然后coding

mvn进行单元测试
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-surefire-plugin</artifactId>
                                <version>
2.12.4</version>
                                <configuration>
                                        <forkMode>pertest</forkMode>
                                        <excludes>
                                                <exclude>**/perftest/*.java</exclude>
                                        </excludes>
                                        <systemProperties>
                                                <property>
                                                        <name>log4j.configuration</name>
                                                        <value>target/test-classes/log4j.properties</value>
                                                </property>
                                        </systemProperties>
                                </configuration>
                        </plugin>

mvn进行code coverage统计
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>emma-maven-plugin</artifactId>
        <version>1.0-alpha-3</version>
        <inherited>true</inherited>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>surefire-report-maven-plugin</artifactId>
        <inherited>true</inherited>
      </plugin>
    </plugins>
  </reporting>

mvn生成javadoc
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-javadoc-plugin</artifactId>
                                <version>
2.9</version>
                                <configuration>
                                        <show>private</show>
                                </configuration>
                                <executions>
                                        <execution>
                                                <id>attach-javadocs</id>
                                                <goals>
                                                        <goal>javadoc</goal>
                                                        <goal>test-javadoc</goal>
                                                </goals>
                                                <phase>site</phase>
                                        </execution>
                                </executions>
                        </plugin>

posted @ 2013-01-10 13:33 Milo的海域 阅读(1277) | 评论 (0)编辑 收藏

最近项目要用JNI, 涉及到用java.library.path这个参数,开始以为只要ldconfig能识别到的so文件java 一定能找到,可惜并不是这样。。
要想java程序找到共享库还是要在执行java程序的时候指定java.library.path,用eclipse的话可以设置如下:
Properties->Run/Debug settings->Arguments->VM arguments
-----------------------------------------
-Djava.library.path=/home/miaoyachun/workspace/JNIC/Release
这个是传统的方式,google了下有个tricky的方式让程序动态修改java.library.path
    private static void loadJNILibDynamically() {
        
try {
            System.setProperty(
"java.library.path", System.getProperty("java.library.path")
                    
+ ":/home/miaoyachun/workspace/JNIC/Release/");
            Field fieldSysPath 
= ClassLoader.class.getDeclaredField("sys_paths");
            fieldSysPath.setAccessible(
true);
            fieldSysPath.set(
nullnull);

            System.loadLibrary(
"JNIC");
        } 
catch (Exception e) {
            
// do nothing for exception
        }
    }

事实上linux下还有个环境变量LD_LIBRARY_PATH,如果lib能在这个path里找到,java.library.path就不用配置了,而且不需要关心lib之间依赖的问题。java.library.path在这方面就弱很多,比如lib依赖其他目录的lib等。

posted @ 2012-12-06 11:05 Milo的海域 阅读(6818) | 评论 (0)编辑 收藏

今天有同事反应一个网络现象,一个多网卡环境,发给eth1的数据包都被eth0接收了。
第一印象是arp的问题。Google了下得到了确认,有个相关的kernal参数:
arp_ignore - INTEGER
Define different modes for sending replies in response to
received ARP requests that resolve local target IP addresses:
0 - (default): reply for any local target IP address, configured
on any interface
1 - reply only if the target IP address is local address
configured on the incoming interface
2 - reply only if the target IP address is local address
configured on the incoming interface and both with the
sender's IP address are part from same subnet on this interface
3 - do not reply for local addresses configured with scope host,
only resolutions for global and link addresses are replied
4-7 - reserved
8 - do not reply for all local addresses
默认是0,解决这个问题需要配置为1

临时配置下
sysctl -w net.ipv4.conf.all.arp_ignore=1

持久配置
sysctl -w net.ipv4.conf.all.arp_ignore=1
echo 'net.ipv4.conf.all.arp_ignore
=1' >> /etc/sysctl.conf

这个弄好可以重启network服务来确保其他机器更新arp cache,如果不方便重启network,自己手动敲arping命令,比如
arping -q -A -c 1 -I eth1 10.197.24.177
这个命令是在 /etc/sysconfig/network-scripts/ifup-eth里看到的

如果机器比较少,也可以直接用arp -d 来删除相关的cache,建议上面的那种发广播的方式。

posted @ 2012-11-27 17:16 Milo的海域 阅读(653) | 评论 (0)编辑 收藏

检测磁盘相关信息   
    smartctl -a /dev/sda
(smartctl工具来自smartmontools, 可以apt-get install smartmontools来安装)

检测所有raid设备
    mdadm -Ds

检测具体raid设备信息
    mdadm -D /dev/md0

创建raid设备
   mdadm --create --verbose /dev/md0 --level=raid0 --raid-devices=8 /dev/sdd /dev/sdc /dev/sdf /dev/sde /dev/sdg /dev/sdh /dev/sdi /dev/sdj

停止raid设备
    mdadm -S /dev/md0

格式化raid设备
    mkfs -t xfs -f /dev/md0

挂载raid设备
   mount -t xfs /dev/md0 /raid

切换raid模式的步骤
    1. umount if mounted : umount /raid
    2. stop raid device:  mdadm -S /dev/md0
    3. create raid: mdadm --create ...
    4. update /etc/mdadm.conf with output of 'mdadm -Ds', 用来开机自动组raid
    5. update /etc/fstab, 如果需要开机自动mount

Ref:
http://francs3.blog.163.com/blog/static/40576727201212145744783/
http://hi.baidu.com/powersaven/item/1da2dc147a8be2e25f53b19e

posted @ 2012-11-07 13:23 Milo的海域 阅读(252) | 评论 (0)编辑 收藏

关于alternatives的用法


alternatives --install /usr/bin/java java /opt/jdk1
.5.0_22/bin/java 15000
alternatives --install /usr/bin/javac javac /opt/jdk1
.5.0_22/bin/javac 15000
alternatives --config java
alternatives --config javac
最近切换桌面环境到ubuntu, 发现alternatives这个工具改名了:update-alternatives
用法还是一样的。。

posted @ 2012-10-26 13:31 Milo的海域 阅读(798) | 评论 (0)编辑 收藏

仅列出标题
共9页: 上一页 1 2 3 4 5 6 7 8 9 下一页