??xml version="1.0" encoding="utf-8" standalone="yes"?> 对应不同的版本把KeyGeneratorcLCQ意工E下Q执行程序,在控制台输入注册名称Q回车后?x)生成序列号?br />
import java.io.*;
/**
* MyEclipse6.0 Register Code
* @author lanjh
*
*/
public class KeyGeneratorForMyEclipse6 {
private static final String LL = "Decompiling this copyrighted software is a violation of both your license agreement and the Digital Millenium Copyright Act of 1998 (http://www.loc.gov/copyright/legislation/dmca.pdf). Under section 1204 of the DMCA, penalties range up to a $500,000 fine or up to five years imprisonment for a first offense. Think about it; pay for a license, avoid prosecution, and feel better about yourself.";
public String getSerial(String userId, String licenseNum) {
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.add(1, 3);
cal.add(6, -1);
java.text.NumberFormat nf = new java.text.DecimalFormat("000");
licenseNum = nf.format(Integer.valueOf(licenseNum));
String verTime = new StringBuilder("-").append(new java.text.
SimpleDateFormat("yyMMdd").format(cal.getTime())).append("0").
toString();
String type = "YE3MP-";
String need = new StringBuilder(userId.substring(0, 1)).append(type).
append("300").append(licenseNum).append(verTime).toString();
String dx = new StringBuilder(need).append(LL).append(userId).toString();
int suf = this.decode(dx);
String code = new StringBuilder(need).append(String.valueOf(suf)).
toString();
return this.change(code);
}
private int decode(String s) {
int i;
char[] ac;
int j;
int k;
i = 0;
ac = s.toCharArray();
j = 0;
k = ac.length;
while (j < k) {
i = (31 * i) + ac[j];
j++;
}
return Math.abs(i);
}
private String change(String s) {
byte[] abyte0;
char[] ac;
int i;
int k;
int j;
abyte0 = s.getBytes();
ac = new char[s.length()];
i = 0;
k = abyte0.length;
while (i < k) {
j = abyte0[i];
if ((j >= 48) && (j <= 57)) {
j = (((j - 48) + 5) % 10) + 48;
} else if ((j >= 65) && (j <= 90)) {
j = (((j - 65) + 13) % 26) + 65;
} else if ((j >= 97) && (j <= 122)) {
j = (((j - 97) + 13) % 26) + 97;
}
ac[i] = (char) j;
i++;
}
return String.valueOf(ac);
}
public KeyGeneratorForMyEclipse6() {
super();
}
public static void main(String[] args) {
try {
System.out.println("please input register name:");
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
String userId = null;
userId = reader.readLine();
KeyGeneratorForMyEclipse6 myeclipsegen = new KeyGeneratorForMyEclipse6();
String res = myeclipsegen.getSerial(userId, "20");
System.out.println("Serial:" + res);
reader.readLine();
} catch (IOException ex) {
}
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* MyEclipse7.0 Register Code
* @author lanjh
*
*/
public class KeyGeneratorForMyEclipse7 {
private static final String LL = "Decompiling this copyrighted software is a violation of both your license agreement and the Digital Millenium Copyright Act of 1998 (http://www.loc.gov/copyright/legislation/dmca.pdf). Under section 1204 of the DMCA, penalties range up to a $500,000 fine or up to five years imprisonment for a first offense. Think about it; pay for a license, avoid prosecution, and feel better about yourself.";
public String getSerial(String userId, String licenseNum) {
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.add(1, 3);
cal.add(6, -1);
java.text.NumberFormat nf = new java.text.DecimalFormat("000");
licenseNum = nf.format(Integer.valueOf(licenseNum));
String verTime = new StringBuilder("-").append(
new java.text.SimpleDateFormat("yyMMdd").format(cal.getTime()))
.append("0").toString();
String type = "YE3MP-";
String need = new StringBuilder(userId.substring(0, 1)).append(type)
.append("300").append(licenseNum).append(verTime).toString();
String dx = new StringBuilder(need).append(LL).append(userId)
.toString();
int suf = this.decode(dx);
String code = new StringBuilder(need).append(String.valueOf(suf))
.toString();
return this.change(code);
}
private int decode(String s) {
int i;
char[] ac;
int j;
int k;
i = 0;
ac = s.toCharArray();
j = 0;
k = ac.length;
while (j < k) {
i = (31 * i) + ac[j];
j++;
}
return Math.abs(i);
}
private String change(String s) {
byte[] abyte0;
char[] ac;
int i;
int k;
int j;
abyte0 = s.getBytes();
ac = new char[s.length()];
i = 0;
k = abyte0.length;
while (i < k) {
j = abyte0[i];
if ((j >= 48) && (j <= 57)) {
j = (((j - 48) + 5) % 10) + 48;
} else if ((j >= 65) && (j <= 90)) {
j = (((j - 65) + 13) % 26) + 65;
} else if ((j >= 97) && (j <= 122)) {
j = (((j - 97) + 13) % 26) + 97;
}
ac[i] = (char) j;
i++;
}
return String.valueOf(ac);
}
public KeyGeneratorForMyEclipse7() {
super();
}
public static void main(String[] args) {
try {
System.out.println("please input register name:");
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
String userId = null;
userId = reader.readLine();
KeyGeneratorForMyEclipse7 myeclipsegen = new KeyGeneratorForMyEclipse7();
String res = myeclipsegen.getSerial(userId, "5");
System.out.println("Serial:" + res);
reader.readLine();
} catch (IOException ex) {
}
}
}
]]>
extends Exception
{
private static final long serialVersionUID = -4817386460334501672L;
public AccountEmailException( String message )
{
super( message );
}
public AccountEmailException( String message, Throwable throwable )
{
super( message, throwable );
}
}
2、发邮g的接口类
{
/**
* 发送邮?br /> * to为接收地址Qsubject为邮件主题,htmlText为邮件内?br /> * @author lanjh 上午10:51:45
* @return void
* @throws 抛出异常说明
*/
void sendMail( String to, String subject, String htmlText )
throws AccountEmailException;
}
3、接口实现类
implements AccountEmailService
{
//spring framework中帮助邮件发送工L(fng)
private JavaMailSender javaMailSender;
private String systemEmail;
public void sendMail( String to, String subject, String htmlText )
throws AccountEmailException
{
try
{
//msg对应着要发送的邮g
MimeMessage msg = javaMailSender.createMimeMessage();
//帮助讄邮gmsg相关信息
MimeMessageHelper msgHelper = new MimeMessageHelper( msg );
//systemEmail pȝ邮箱讄
msgHelper.setFrom( systemEmail );
msgHelper.setTo( to );
msgHelper.setSubject( subject );
//true表示邮g内容为html格式
msgHelper.setText( htmlText, true );
javaMailSender.send( msg );
}
catch ( MessagingException e )
{
throw new AccountEmailException( "Faild to send mail.", e );
}
}
public JavaMailSender getJavaMailSender()
{
return javaMailSender;
}
public void setJavaMailSender( JavaMailSender javaMailSender )
{
this.javaMailSender = javaMailSender;
}
public String getSystemEmail()
{
return systemEmail;
}
public void setSystemEmail( String systemEmail )
{
this.systemEmail = systemEmail;
}
}
4、测试类
{
private GreenMail greenMail;
@Before
public void startMailServer()
throws Exception
{
greenMail = new GreenMail( ServerSetup.SMTP );
greenMail.setUser( "lanjh", "******" );
greenMail.start();
}
@Test
public void testSendMail()
throws Exception
{
ApplicationContext ctx = new ClassPathXmlApplicationContext( "account-email.xml" );
AccountEmailService accountEmailService = (AccountEmailService) ctx.getBean( "accountEmailService" );
String subject = "Test Subject";
String htmlText = "<h3>Test</h3>";
accountEmailService.sendMail( "275581963@qq.com", subject, htmlText );
greenMail.waitForIncomingEmail( 2000, 1 );
Message[] msgs = greenMail.getReceivedMessages();
assertEquals( 1, msgs.length );
assertEquals( "lanjh@chinalmtc.com", msgs[0].getFrom()[0].toString() );
assertEquals( subject, msgs[0].getSubject() );
assertEquals( htmlText, GreenMailUtil.getBody( msgs[0] ).trim() );
}
@After
public void stopMailServer()
throws Exception
{
greenMail.stop();
}
}
5、相关配|文?br />
account-mail.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:account-service.properties" />
</bean>
<bean id="javaMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="protocol" value="${email.protocol}" />
<property name="host" value="${email.host}" />
<property name="port" value="${email.port}" />
<property name="username" value="${email.username}" />
<property name="password" value="${email.password}" />
<property name="javaMailProperties">
<props>
<prop key="mail.${email.protocol}.auth">${email.auth}</prop>
</props>
</property>
</bean>
<bean id="accountEmailService"
class="com.juvenxu.mvnbook.account.email.AccountEmailServiceImpl">
<property name="javaMailSender" ref="javaMailSender" />
<property name="systemEmail" value="${email.systemEmail}" />
</bean>
</beans>
account-service.properties
email.protocol=smtp
email.host=localhost
email.port=25
email.username=lanjh
email.password=*****
email.auth=true
email.systemEmail=lanjh@chinalmtc.com
greenmail api参?br />http://www.icegreen.com/greenmail/javadocs/overview-summary.html
]]>
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
//TODO doc
public class NetUtil {
public static boolean telnetStringPort(String ip, String port, int timeout) {
if (port == null || !isValidPort(port)) {
return NetUtil.ping(ip, timeout);
}
return NetUtil.telnet(ip, Integer.valueOf(port.trim()).intValue(),
timeout);
}
public static boolean ping(String ip, int timeout) {
AssertUtil.assertNull("IP is null.", ip);
try {
return InetAddress.getByName(ip.trim()).isReachable(timeout);
} catch (UnknownHostException e) {
System.err.println("UnknownHostException:" + e.getMessage());
return false;
} catch (IOException e) {
System.err.println("IOException:" + e.getMessage());
return false;
}
}
public static boolean telnet(String ip, int port, int timeout) {
AssertUtil.assertNull("IP is null.", ip);
Socket server = null;
try {
server = new Socket();
server.connect(new InetSocketAddress(ip.trim(), port), timeout);
return true;
} catch (UnknownHostException e) {
System.err.println("UnknownHostException:" + e.getMessage());
return false;
} catch (IOException e) {
System.err.println("IOException:" + e.getMessage());
return false;
} finally {
if (server != null)
try {
server.close();
} catch (IOException e) {
}
}
}
public static boolean isValidPort(String port) {
if (port != null && port.trim().matches("^[1-9][0-9]{0,3}$|^[1-5][0-9]{0,4}$|^6[0-5]{2}[0-3][0-5]$")) {
int portInt = Integer.valueOf(port.trim()).intValue();
if(portInt > 0 && portInt <= 0xFFFF) return true;
}
return false;
}
public static void main(String arg[]){
boolean b = telnetStringPort("192.168.50.181","10242",1);
System.out.println(b);
}
}
]]>
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class EmailSpider {
public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new FileReader("D:\\share\\courseware\\1043633.html"));
String line = "";
while((line=br.readLine()) != null) {
parse(line);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void parse(String line) {
Pattern p = Pattern.compile("[\\w[.-]]+@[\\w[.-]]+\\.[\\w]+");
Matcher m = p.matcher(line);
while(m.find()) {
System.out.println(m.group());
}
}
}
]]>
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class CodeCounter {
static long normalLines = 0;
static long commentLines = 0;
static long whiteLines = 0;
public static void main(String[] args) {
File f = new File("D:\\share\\JavaProjects\\TankWar1.9.11\\src");
File[] codeFiles = f.listFiles();
for(File child : codeFiles){
if(child.getName().matches(".*\\.java$")) {
parse(child);
}
}
System.out.println("normalLines:" + normalLines);
System.out.println("commentLines:" + commentLines);
System.out.println("whiteLines:" + whiteLines);
}
private static void parse(File f) {
BufferedReader br = null;
boolean comment = false;
try {
br = new BufferedReader(new FileReader(f));
String line = "";
while((line = br.readLine()) != null) {
line = line.trim();
if(line.matches("^[\\s&&[^\\n]]*$")) {
whiteLines ++;
} else if (line.startsWith("/*") && !line.endsWith("*/")) {
commentLines ++;
comment = true;
} else if (line.startsWith("/*") && line.endsWith("*/")) {
commentLines ++;
} else if (true == comment) {
commentLines ++;
if(line.endsWith("*/")) {
comment = false;
}
} else if (line.startsWith("//")) {
commentLines ++;
} else {
normalLines ++;
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if(br != null) {
try {
br.close();
br = null;
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
]]>
http://sourceforge.net/project/showfiles.php?group_id=39428
下面单介l一下具体的使用步骤Q?/span>
1. 下载的Java Service Wrapper包解压到本地Q目录ؓ(f){WRAPPER_HOME}Q?/span>
2. 服务应用E序名ؓ(f)MyServAppQ在目录d:"MyServApp下徏?/span>bin?/span>conf?/span>logs?/span>lib目录Qƈ把你的已有应用程序如NioBlockingServer.class拯到该目录下;
3. ?/span>{WRAPPER_HOME}"src"bin"下的遗以下文件拷贝到MyServApp目录下,q命名?/span>
{WRAPPER_HOME}"bin"Wrapper.exe C:" MyServApp "bin"Wrapper.exeà
C:"à{WRAPPER_HOME}"src"bin"App.bat.in MyServApp"bin"MyApp.bat
C:"à{WRAPPER_HOME}"src"bin"InstallApp-NT.bat.in MyServApp"bin"InstallMyApp-NT.bat
{WRAPPER_HOME}"src"bin"UninstallApp-NT.bat.in C:" MyServApp"bin"UninstallMyApp-NT.batà
4. ?/span>{WRAPPER_HOME}"lib下的以下文g拯?/span>C:" MyServApp "lib目录?/span>
{WRAPPER_HOME}"lib"Wrapper.DLL
{WRAPPER_HOME}"lib"wrapper.jar
5. ?/span>{WRAPPER_HOME}"src"conf"wrapper.conf.in拯?/span>C:" MyServApp "conf目录下ƈ命名?/span>wrapper.confQƈ修改wrapper.conf文gQ在其中配置(zhn)的应用服务?/span>
主要修改以下几项卛_Q?/span>
#你的JVM位置Q?/span>
wrapper.java.command=D:"Sun"j2sdk1.4.0_03"bin"java
#q行参数Q如Q?/span>
wrapper.java.additional.1=-Dprogram.name=run.bat
#classpathQ?/span>
wrapper.java.classpath.1=../lib/wrapper.jar
wrapper.java.classpath.2=../bin/.
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=../lib
#MAIN CLASS 此处军_了?/span>Java Service Wrapper的方?/span>
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
#你的Java应用c?/span>
wrapper.app.parameter.1= NonBlockingServer
# 服务?/span>
wrapper.ntservice.name=NB
# Display name of the service
wrapper.ntservice.displayname=Nio Nonblocking Server
# 服务描述
wrapper.ntservice.description=Nio Nonblocking Server
其他的配|根据你的需要改变即?/span>
6. 对以上配|的MyApp.batq行试Q运?/span>MyApp.batQ就像在ConsoleH口下运?/span>Tomcat一P
7. 对以上配|的服务q行试Q运?/span>C:" MyServApp"bin"InstallMyApp-NT.bat把你的应用Q此处ؓ(f)NioBlockingServerQ安装到Win32pȝ服务中了?/span>
8. 打开控制面板Q管理程序-服务Q看?/span>Nio Nonblocking Server已经在系l服务中了,其他用法׃我们熟?zhn)?/span>Windows服务一样了?/span>
?/span>JAVAE序部v?/span>Windows Service需要修改的操作
1.?/span>JAVAE序所用到?/span>Class拷到bin目录?/span>;所?/span>jar考到lib目录
2.修改config/wrapper.conf 文g
1)修改JDK安装路径 :wrapper.java.command=C:"jdk1.5.0"bin"java
2)修改classpath:wrapper.java.classpath.2=../bin/.
3)修改要启动的JAVAc?/span>:wrapper.app.parameter.1= HelloWorld
4)修改服务名称:wrapper.ntservice.name=MyJavaService
5)修改"服务"里显C的名称:wrapper.ntservice.displayname=MyJavaService
6)服务说明:wrapper.ntservice.description=MyJavaService Test
bin/StartApp.bat 为控制台方式q行E序
bin/InstallApp-NT.bat 安装服务
bin/UninstallApp-NT.bat 删除服务
把项目中的接收程序提升ؓ(f)pȝ服务
config/wrapper.conf 文g
#********************************************************************
# Wrapper Properties
#********************************************************************
# Java Application
wrapper.java.command=java
# Java Main class. This class must implement the WrapperListener interface
# or guarantee that the WrapperManager class is initialized. Helper
# classes are provided to do this for you. See the Integration section
# of the documentation for details.
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
# Java Classpath (include wrapper.jar) Add class path elements as
# needed starting from 1
wrapper.java.classpath.1=../lib/wrapper.jar
wrapper.java.classpath.2=../lib/wrappertest.jar
wrapper.java.classpath.3=../bin/.
wrapper.java.classpath.4=../lib/jaxen-1.1-beta-7.jar
wrapper.java.classpath.5=../lib/tlclient.jar
wrapper.java.classpath.6=../lib/tlqadapter.jar
wrapper.java.classpath.7=../lib/tlqconf.jar
wrapper.java.classpath.8=../lib/TlqMng.jar
wrapper.java.classpath.9=../lib/weblogic.jar
wrapper.java.classpath.10=../lib/jms.jar
wrapper.java.classpath.11=../lib/log4j-1.2.8.jar
wrapper.java.classpath.12=../lib/swt.jar
wrapper.java.classpath.13=../lib/javax.jms.jar
wrapper.java.classpath.14=../lib/jaxrpc.jar
wrapper.java.classpath.15=../lib/commons-discovery-0.2.jar
wrapper.java.classpath.16=../lib/commons-logging-1.0.4.jar
wrapper.java.classpath.17=../lib/dom4j-1.6.1.jar
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=../lib
# Java Additional Parameters
#wrapper.java.additional.1= -Dprogram.name=StartApp.bat
# Initial Java Heap Size (in MB)
#wrapper.java.initmemory=3
# Maximum Java Heap Size (in MB)
#wrapper.java.maxmemory=64
# Application parameters. Add parameters as needed starting from 1
wrapper.app.parameter.1= MainTest
#********************************************************************
# Wrapper Logging Properties
#********************************************************************
# Format of output for the console. (See docs for formats)
wrapper.console.format=PM
# Log Level for console output. (See docs for log levels)
wrapper.console.loglevel=INFO
# Log file to use for wrapper output logging.
wrapper.logfile=../logs/log.log
# Format of output for the log file. (See docs for formats)
wrapper.logfile.format=LPTM
# Log Level for log file output. (See docs for log levels)
wrapper.logfile.loglevel=INFO
# Maximum size that the log file will be allowed to grow to before
# the log is rolled. Size is specified in bytes. The default value
# of 0, disables log rolling. May abbreviate with the 'k' (kb) or
# 'm' (mb) suffix. For example: 10m = 10 megabytes.
wrapper.logfile.maxsize=0
# Maximum number of rolled log files which will be allowed before old
# files are deleted. The default value of 0 implies no limit.
wrapper.logfile.maxfiles=0
# Log Level for sys/event log output. (See docs for log levels)
wrapper.syslog.loglevel=NONE
#********************************************************************
# Wrapper Windows Properties
#********************************************************************
# Title to use when running as a console
wrapper.console.title=MyJavaService
#********************************************************************
# Wrapper Windows NT/2000/XP Service Properties
#********************************************************************
# WARNING - Do not modify any of these properties when an application
# using this configuration file has been installed as a service.
# Please uninstall the service before modifying this section. The
# service can then be reinstalled.
# Name of the service
wrapper.ntservice.name=MyJavaService
# Display name of the service
wrapper.ntservice.displayname=MyJavaService
# Description of the service
wrapper.ntservice.description=MyJavaService Test
# Service dependencies. Add dependencies as needed starting from 1
wrapper.ntservice.dependency.1=
# Mode in which the service is installed. AUTO_START or DEMAND_START
wrapper.ntservice.starttype=AUTO_START
# Allow the service to interact with the desktop.
wrapper.ntservice.interactive=false
采用q种方式Q即可简单有效的把我们的服务E序包装成ؓ(f)pȝ服务E序Qƈ增强了日志功能,我们可以把MyServApp的几个文件做成模板,每次修改文g名,配置文g可以了Q还可以做成Eclipse的pluginQ鼠标点点就把应用配成服务了?nbsp;
Jxcell is a high performance spreadsheet component for java development environments that allows you to create, manipulate, and print excel worksheets.
Jxcell contains the tools needed to store, analyze, manipulate, and present your data in excel.
Jxcell directly using excel document format, support formulae, images, lines, chart.
Download Jxcell. (1950kb) ,containing examples of code
run Jxcell:
java -cp jxcell.jar com.jxcell.designer.Designer
run environmentQ?/p>
JDK1.3 and above version
screenshot