Results 1 to 2 of 2
  1. #1
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default hi how can i convert this java class to runnable jar

    Hi please help me how can I convert this java class to runnable jar

    Java Code:
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    
    import junit.framework.TestCase;
    import jxl.Sheet;
    import jxl.Workbook;
    
    public class LoadEEClocks extends TestCase{
    	
    	private static final Exception breakException = new Exception();
    	private static String testClassPropertyFile = "C:\\clocks\\LoadEEClocks.properties";
    	private static String folderStr = "C:\\clocks";
    	private static String dstFolder = "C:\\clocks\\clk_dst";
    	
    	
    	private static StringBuffer start = null;
    	private static String body = null;
    	private static StringBuffer end = null;
    	
    	private static StringBuffer tzStartSB = null;
    	private static String tzBodyStartStr = null;
    	private static String tzBody1 = null;
    	private static String tzBody2 = null;
    	private static String tzBody3 = null;
    	private static String tzBodyEndStr = null;
    	private static StringBuffer tzEndSB = null;
    
    	private static String filePrefix = "";
    	
    	private static int type = 0;
    	private static int reader = 1;
    	private static int badge = 2;
    	private static int date = 3;
    	private static int time = 4;
    	private static int dst = 9;
    	private static int tz = 10;
    	
    	
    	public LoadEEClocks(String arg0) {
    		super(arg0);
    	}
    	
    	final public void test() throws Exception {
    
    		File propFile = new File(testClassPropertyFile);
        	BufferedReader mainReader = new BufferedReader(new FileReader(propFile));
    		String line = null;
    		start = new StringBuffer();
    		body = new String();
    		end = new StringBuffer();
    		
    		tzStartSB = new StringBuffer();
    		tzBodyStartStr = new String();
    		tzBody1 = new String();
    		tzBody2 = new String();
    		tzBody3 = new String();
    		tzBodyEndStr = new String();
    		tzEndSB = new StringBuffer();
    		int tempStart = 0;
    		int tzStart = 0;
    		while ((line = mainReader.readLine()) != null) {
    			if(tempStart > 0 && tempStart < 3){
    				start.append(line + "\r\n");
    				tempStart++;
    			}else if(tempStart == 3){
    				body = line;
    				tempStart++;
    			}else if(tempStart > 3 && tempStart < 6){
    				end.append(line + "\r\n");
    				tempStart++;
    			}
    			
    			if(tzStart > 0 && tzStart < 3){
    				tzStartSB.append(line + "\r\n");
    				tzStart++;
    			}else if(tzStart == 3){
    				tzBodyStartStr = line;
    				tzStart++;
    			}else if(tzStart == 4){
    				tzBody1 = line.trim();
    				tzStart++;
    			}else if(tzStart == 5){
    				tzBody2 = line.trim();
    				tzStart++;
    			}else if(tzStart == 6){
    				tzBody3 = line.trim();
    				tzStart++;
    			}else if(tzStart == 7){
    				tzBodyEndStr = line.trim();
    				tzStart++;
    			}else if(tzStart > 7 && tzStart < 10){
    				tzEndSB.append(line + "\r\n");
    				tzStart++;
    			}
    			
    			if(line.indexOf("xml.template =") > -1){
    				tempStart++;
    			}else if(line.indexOf("filename.prefix =") > -1){
    				filePrefix = line.substring(line.indexOf("=") + 1, line.length()).trim();
    			}else if(line.indexOf("type.column =") > -1){
    				type = new Integer(line.substring(line.indexOf("=") + 1, line.length()).trim()).intValue();
    			}else if(line.indexOf("reader.column =") > -1){
    				reader = new Integer(line.substring(line.indexOf("=") + 1, line.length()).trim()).intValue();
    			}else if(line.indexOf("badge.column =") > -1){
    				badge = new Integer(line.substring(line.indexOf("=") + 1, line.length()).trim()).intValue();
    			}else if(line.indexOf("date.column =") > -1){
    				date = new Integer(line.substring(line.indexOf("=") + 1, line.length()).trim()).intValue();
    			}else if(line.indexOf("time.column =") > -1){
    				time = new Integer(line.substring(line.indexOf("=") + 1, line.length()).trim()).intValue();
    			}else if(line.indexOf("time.dst =") > -1){
    				dst = new Integer(line.substring(line.indexOf("=") + 1, line.length()).trim()).intValue();
    			}else if(line.indexOf("time.tz =") > -1){
    				tz = new Integer(line.substring(line.indexOf("=") + 1, line.length()).trim()).intValue();
    			}else if(line.indexOf("xml.template.tz =") > -1){
    				tzStart++;
    			}
    		}
    		mainReader.close();
    		File folder = new File(folderStr);
    		if (folder.isDirectory()) {
    			File[] files = folder.listFiles();
    			for (int i = 0; i < files.length; i++) {
    				File file = files[i];
    				if (file.isFile() && file.getName().indexOf(".xls") > -1) {
    					readFile(file, false);
    				}
    			}
    		}
    		
    		File dstFolderFile = new File(dstFolder);
    		if (dstFolderFile.isDirectory()) {
    			File[] files = dstFolderFile.listFiles();
    			for (int i = 0; i < files.length; i++) {
    				File file = files[i];
    				if (file.isFile() && file.getName().indexOf(".xls") > -1) {
    					readFile(file, true);
    				}
    			}
    		}
    	}
    	
    	public void readFile(File file, boolean hasTZ) throws Exception {
    		// adjust console limit if necessary
    		String fileName = file.getName();
    		System.out.println("FILE: " + fileName);
    		Workbook xlsFile = Workbook.getWorkbook(file);
    		String[] sheetNms = xlsFile.getSheetNames();
    		StringBuffer strBuffer = null;
    		if (sheetNms.length > 2){
    			strBuffer = new StringBuffer();
    			strBuffer.append(start);
    			boolean isFirstLine = true;
    			for(int i = 2; i < sheetNms.length; i++){
    				Sheet sheet = xlsFile.getSheet(i);
    				System.out.println("\tTab: " + sheetNms[i] + " row : " + sheet.getRows());
    
    				for (int rowCount = 0; rowCount < sheet.getRows(); rowCount++){
    					
    					String typeStr = sheet.getCell(type, rowCount).getContents().trim();
    					if(typeStr.equals("07")){
    						System.out.println("MARLON");
    					}
    					if(typeStr.equals("01") || typeStr.equals("02") || typeStr.equals("07")){
    						String readerStr = sheet.getCell(reader, rowCount).getContents().trim();
    						String badgeStr = sheet.getCell(badge, rowCount).getContents().trim();
    						String dateStr = sheet.getCell(date, rowCount).getContents().trim();
    						String timeStr = sheet.getCell(time, rowCount).getContents().trim();
    						String dstStr = "";
    						String tzStr = "";
    						if (!timeStr.equals("") && timeStr.length() == 4){
    							timeStr = timeStr + "00";
    						}
    						if(hasTZ){
    							System.out.println("\t\trrr = " + rowCount);
    							dstStr = sheet.getCell(dst, rowCount).getContents().trim();
    							tzStr = sheet.getCell(tz, rowCount).getContents().trim();
    							
    							if(!readerStr.equals("") && !badgeStr.equals("") && !dateStr.equals("") && !timeStr.equals("") && !dstStr.equals("") && !tzStr.equals("")){
    								String bodyStr = tzBodyStartStr.replaceAll("type=\"\"", "type=\"" + typeStr +"\"");
    								if(isFirstLine){
    									isFirstLine = false;
    								}else{
    									bodyStr = bodyStr.trim();
    								}
    								bodyStr = bodyStr.replaceAll("rdrName=\"\"", "rdrName=\"" + readerStr +"\"");
    								bodyStr = bodyStr.replaceAll("badgeNo=\"\"", "badgeNo=\"" + badgeStr +"\"");
    								bodyStr = bodyStr.replaceAll("time=\"\"", "time=\"" + dateStr + timeStr +"\"");
    								String body1 = tzBody1.replaceAll("value=\"\"", "value=\"" + dstStr +"\"");
    								String body3 = tzBody3.replaceAll("value=\"\"", "value=\"" + tzStr +"\"");
    								strBuffer.append(bodyStr);
    								strBuffer.append(body1);
    								strBuffer.append(tzBody2);
    								strBuffer.append(body3);
    								strBuffer.append(tzBodyEndStr);
    							}else{
    								System.out.println("has blank column");
    								throw breakException;
    							}							
    						}else{
    							if(!readerStr.equals("") && !badgeStr.equals("") && !dateStr.equals("") && !timeStr.equals("")){
    								String bodyStr = body.replaceAll("type=\"\"", "type=\"" + typeStr +"\"");
    								if(isFirstLine){
    									isFirstLine = false;
    								}else{
    									bodyStr = bodyStr.trim();
    								}
    								bodyStr = bodyStr.replaceAll("rdrName=\"\"", "rdrName=\"" + readerStr +"\"");
    								//bodyStr = bodyStr.replaceAll("badgeNo=\"\"", "badgeNo=\"" + "00" + badgeStr +"\"");
    								bodyStr = bodyStr.replaceAll("badgeNo=\"\"", "badgeNo=\"" + badgeStr +"\"");
    								bodyStr = bodyStr.replaceAll("time=\"\"", "time=\"" + dateStr + timeStr +"\"");
    								strBuffer.append(bodyStr);
    							}else{
    								System.out.println("has blank column, row : " + rowCount);
    								//throw breakException;
    							}
    						}
    
    					}
    					if(rowCount%1000 == 0){
    						System.out.println("\t\trowCount = " + rowCount);
    					}
    				}
    			}
    			strBuffer.append("\r\n" + end);
    		}
    
    		xlsFile.close();
    		if(strBuffer != null){
    			String name = "";
    			if(hasTZ){
    				name = dstFolder + "\\" + filePrefix + fileName.substring(0, fileName.indexOf("."));
    			}else{
    				name = folderStr + "\\" + filePrefix + fileName.substring(0, fileName.indexOf("."));
    			}
    			
    			FileWriter writer = new FileWriter(new File(name + ".xml"));
    			writer.write(strBuffer.toString());
    			writer.close();
    			
    			writer = new FileWriter(new File(name + ".smf"));
    			writer.write(strBuffer.toString());
    			writer.close();
    		}
    	}
    
    }
    This java class is run as junit.

    Please help me I'm using eclipse, this class has no main method.

  2. #2
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default Re: hi how can i convert this java class to runnable jar

    I do believe that it must have a main method to be compiled to a jar file. Fix one

Similar Threads

  1. Question about a class implementing Runnable
    By d3n1s in forum Advanced Java
    Replies: 12
    Last Post: 06-18-2011, 06:16 PM
  2. Private inner & Runnable class instantiation failure
    By jvmakela in forum Advanced Java
    Replies: 1
    Last Post: 10-30-2010, 03:44 PM
  3. can i convert frome .class to .java ?
    By mr-pepo in forum Java Applets
    Replies: 2
    Last Post: 10-12-2009, 02:18 AM
  4. Java: Make runnable java-file
    By MrBambey in forum New To Java
    Replies: 4
    Last Post: 08-10-2009, 06:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •