Solved

how to include packages in Java

Posted on 2011-03-22
16
494 Views
Last Modified: 2012-05-11
Hi,

I have the following lines in the beginning of my code:

package com.mywork.tools.GQual;

import com.mywork.tools.GQual.ws.*;
import java.util.*;
import java.lang.*;
import java.io.*;

import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebResponse;
import com.meterware.httpunit.WebTable;
import com.meterware.httpunit.HttpUnitOptions;


import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

Open in new window


When I compile my code I got errors related with these packages. But only for httpunit and javax.

The error messages are:

package com.meterware.httpunit does not exist

package javax.mail does not exist

package javax.mail.internet does not exist


I compile my code in maven. So how can I add these into my code?

Thanks,



0
Comment
Question by:Tolgar
  • 6
  • 6
  • 3
  • +1
16 Comments
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
You have to have mail.jar and activation.jar in your classpath
I guess meterware jar is also needed
0
 
LVL 47

Accepted Solution

by:
for_yan earned 200 total points
Comment Utility
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility

For httpunit you need jar from here:
http://sourceforge.net/projects/httpunit/files/httpunit/1.7/
I guess, you already have it
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 200 total points
Comment Utility
When working with httpunit i have the following in the classpath

Tidy.jar
js.jar
junit.jar
nekohtml.jar
rhino-patch.txt
servlet.jar
xercesImpl.jar
xmlParserAPIs.jar
httpunit.jar
0
 

Author Comment

by:Tolgar
Comment Utility
@CEHJ: I downloaded httpunit-1.7.zip file. But it does not have all these jars.

Where did you find them from?


@ for_yan: Yes I have httpunit.jar file already.


@ ALL : I put jar files under src\main\resources directory.

any idea?

0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Try
<dependency>
    <groupId>httpunit</groupId>
    <artifactId>httpunit</artifactId>
    <version>1.7</version>
</dependency>

Open in new window

0
 

Author Comment

by:Tolgar
Comment Utility
Ok. these are all set. But I am still getting this error message:

cannot find symbol symbol  : method readline() location: class java.io.DataInputStream


I import java .io.* in the begining of my code:

import java.io.*;

Why does it still complain?

Thanks,
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Hmm. DataInputStream.readLine is not good to be using. What are you doing with that exactly - can you post the code?
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:Tolgar
Comment Utility
Here is my code:

try
				{
				DataInputStream in = new DataInputStream(new FileInputStream(args[3]));
				java.lang.String buff = null;
				while((buff= in.readline()) != null){
					if(buff.indexOf( "<a href='http://") > -1 && buff.indexOf( "myruntests") > -1){
						java.lang.String SbPathInMyFile = buff;
					}
				}
				in.close();		
				}catch(Exception ex){
				ex.printStackTrace();
				}

Open in new window


0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Better to use a Scanner
Scanner in = null;

        try {
            in = new Scanner(new File(args[3]));

            String buff = null;

            while (in.hasNextLine()) {
                buff = in.nextLine();

                if ((buff.indexOf("<a href='http://") > -1) &&
                        (buff.indexOf("myruntests") > -1)) {
                    String SbPathInMyFile = buff;
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (Exception e) { /* ignore */
            }
        }

Open in new window

0
 

Author Comment

by:Tolgar
Comment Utility
For this line:

in = new Scanner(new File(args[3]));

Open in new window


After compilation it says:

 cannot find symbol symbol  : variable in



And for this line which comes after your code:

if((ix =SbPathInMyFile.indexOf("/mytest")) > -1) {

Open in new window


After compilation it says:

cannot find symbol symbol  : variable SbPathInMyFile


Why do you think this happens?

Thanks,


0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Can you please post your adjusted code?
0
 

Author Comment

by:Tolgar
Comment Utility
The failing lines are: 92-94-95-104-111-112-114-192-199

All errors are: cannot find symbol symbol  : variable   and the variable on that line

This is the entire code:

package com.mywork.tools.GPrequal;

import com.mywork.tools.GPrequal.ws.*;
import java.util.*;
import java.lang.*;
import java.io.*;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebResponse;
import com.meterware.httpunit.WebTable;
import com.meterware.httpunit.HttpUnitOptions;


import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;


//java -jar GPrequal-1.0.jar abcd "681416, 756455" "148050 at A" "/dev/A/"
public class bLogData2G
{  
	// SEND EMAIL
	public static void sendEmail(java.lang.String arg)
	{
	    // Recipient's email ID needs to be mentioned.
		java.lang.String to = arg + "@mywork.com";
	
	    // Sender's email ID needs to be mentioned
		java.lang.String from = "myserve@mywork.com";
	
	    // Assuming you are sending email from localhost
		java.lang.String host = "localhost";
	
	    // Get system properties
	    Properties properties = System.getProperties();
	
	    // Setup mail server
	    properties.setProperty("mail.smtp.host", host);
	
	    // Get the default Session object
	    Session session = Session.getDefaultInstance(properties);
	
	    try{
	       // Create a default MimeMessage object.
	       MimeMessage message = new MimeMessage(session);
	
	       // Set From: header field of the header.
	       message.setFrom(new InternetAddress(from));
	
	       // Set To: header field of the header.
	       message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
	
	       // Set Subject: header field
	       message.setSubject("Logging to G Failed");
	
	       // Now set the actual message
	       message.setText("Logging to G Failed due to the size limit in the text fields");
	
	       // Send message
	       Transport.send(message);
	    }
	    catch (MessagingException mex) {
	       mex.printStackTrace();
	    }
	}
	
// END OF SEND EMAIL
	
	// args[] = login, gecIDList, myID@cluster, pathToJobfile
        public static void main(java.lang.String args[])
        {
        	java.lang.String soapEndpointURL="http://Gwebtest-00-blr.mywork.com/main/services/gecWebService"; 
        	// Add g as a prefix to each gec to make them as a link in the solution field
		    // java.lang.String gecIDList = "g" + args[1] + args[1].replaceAll(",", ",g");
        	   java.lang.String gecIDList = args[1].replaceAll("(\\d+)", "g$1");
        	   
        	  // Find the location of the mycheck report using the path to myruntests report in submit file.       	  
        	  /*  try
				{
				DataInputStream in = new DataInputStream(new FileInputStream(args[3]));
				java.lang.String buff = null;
				while((buff= in.readline()) != null){
					if(buff.indexOf( "<a href='http://") > -1 && buff.indexOf( "myruntests") > -1){
						java.lang.String SbPathInSubmitFile = buff;
					}
				}
				in.close();		
				}catch(Exception ex){
				ex.printStackTrace();
				}
 */
        	   try {
                   in = new Scanner(new File(args[3]));
                   java.lang.String buff = null;
                   while (in.hasNextLine()) {
                       buff = in.nextLine();
                       if ((buff.indexOf("<a href='http://") > -1) && (buff.indexOf("myruntests") > -1)) {
                    	   java.lang.String SbPathInSubmitFile = buff;
                       }
                   }
               } catch (Exception ex) {
                   ex.printStackTrace();
               } finally {
                   try {
                       in.close();
                   } catch (Exception e) {
                	   e.printStackTrace();
                   }
               }
        	   
        	   int ix = 0;
        	   if((ix =SbPathInSubmitFile.indexOf("/sbtest")) > -1) {
        		   SbPathInSubmitFile = SbPathInSubmitFile.substring(0, ix);
        	   }
        	   java.lang.String mycheckReportPath = SbPathInSubmitFile + "mycheck/report.html";
        	   
        	                       	    
   				try {
        		    HttpUnitOptions.setScriptingEnabled(false);
        		    WebConversation wc = new WebConversation();
        		    WebResponse wr = wc.getResponse(mycheckReportPath);
        		    WebTable table = wr.getTables()[0];
        		    java.lang.String[][] cells = table.asText();
        		    java.lang.String mycheckActivity = "";
        		    for(java.lang.String[] row : cells) {
        				for(java.lang.String cell : row) {
        			    	mycheckActivity += cell;
        				}
        				mycheckActivity += System.getProperty("line.separator");
        			}	
        		}
        		catch(Exception e) {
        		    e.printStackTrace();	
        		}
             
        		
			   try {
					gecWebServiceSoapBindingStub stub = new gecWebServiceSoapBindingStub(new java.net.URL(soapEndpointURL), new org.apache.axis.client.Service());
					
					//find the submitted files in the job file 
					java.lang.String myFiles = "";
					try{
						DataInputStream in = new DataInputStream(new FileInputStream(args[3]));
						java.lang.String jobFile = null;
						while((jobFile=in.readLine() )!= null){
							if(jobFile.startsWith("s") || jobFile.startsWith("S") || jobFile.startsWith("D")){
							myFiles += jobFile + System.getProperty("line.separator");
							}
						}
						in.close();
					} 
					catch(Exception e){
						e.printStackTrace();
					}
					
					// Get the number of records (gecs) 
					java.lang.String[] gecs = args[1].split(",");
					int [] gecList = new int[gecs.length];
					
					for(int j=0; j<gecList.length; j++){
					
						java.lang.String myservemsg = "The information below is logged into this field by myserve";
						// Get the jth gecID
						java.lang.Integer gecID = java.lang.Integer.parseInt(gecs[j]);
											
					    // Lock the gec and get the gec object. Arguments: gecID, login
						gec g = stub.lockgec(gecID,args[0]);
						
						// Get the date and time of the G logging
						java.lang.String gecUpdateDate = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm zzz").format(new java.util.Date());
						
						// UNCOMMENT THIS PART ONCE NEW WSDL IS READY WITH Qualification Actitivities FIELD
						//Get the current Qualification Actitivities;
						////////////// java.lang.String qActivities = g.getQualificationActivities();
						java.lang.String qActivities = g.getSolution();
						
						// Stop logging files to qActivities field if qActivities field does not have enough space (KB).
						// Each char in a java string is *two* bytes - it uses UTF16 encoding
						  java.lang.String totalqActivitiesData= args[0] + " - " + gecUpdateDate + "\n\n" + myservemsg + "\n\n" + mycheckActivity + "\n\n\n" + qActivities + "\n";
						  java.lang.Double totalqActivitiesSize = totalqActivitiesData.length() * 2 / 1024.0;
						  
						  
			           // Qualification Actitivities field size is 64 kb. However I put a buffer in case someone needs to put a few more lines later on.
					   // That's why I use 60 instead of 64.
						  if (totalqActivitiesSize < 60){
							  qActivities = args[0] + " - " + gecUpdateDate + "\n\n" + myservemsg + "\n\n" + "mycheck	STATUS" + "\n\n" + mycheckActivity + "\n\n\n" + qActivities + "\n";
						  }
						  else{
							  //sendEmail(args[0]);
							  qActivities = args[0] + " - " + gecUpdateDate + "\n\n" + myservemsg + "\n\n" + "mycheck report cannot be logged in because text field size was exceeded." + "\n\n\n" + qActivities + "\n";
						  }
						
						//END OF UNCOMMENT */  
						 /* 
						//Get the current Solution;
						java.lang.String solution = g.getSolution();
												
						// Stop logging files to solution field if Solution field does not have enough space (KB).
						// Each char in a java string is *two* bytes - it uses UTF16 encoding
						  java.lang.String totalSolutionData= args[0] + " - " + gecUpdateDate + "\n\n" + myservemsg + "\n\n" + "myID: " + args[2] + "\n" + "Related Records: " + gecIDList + "\n\n" + myFiles + "\n\n\n" + solution + "\n";
						  java.lang.Double totalsolutionSize = totalSolutionData.length() * 2 / 1024.0;
						  
						  // Solution field size is 64 kb. However I put a buffer in case someone needs to put a few more lines later on.
						  // That's why I use 60 instead of 64.
						  if (totalsolutionSize < 60){
							  solution = args[0] + " - " + gecUpdateDate + "\n\n" + myservemsg + "\n\n" + "myID: " + args[2] + "\n" + "Related Records: " + gecIDList + "\n\n" + myFiles + "\n\n\n" + solution + "\n";
						 // }
						 // else{
						 // sendEmail(args[0]);
						 // solution = args[0] + " - " + gecUpdateDate + "\n\n" + myservemsg + "\n\n" + "myID: " + args[2] + "\n" + "Related Records: " + gecIDList + "\n\n" + "Submitted files cannot be logged in because text field size was exceeded." + "\n\n\n" + solution + "\n";
 						 // }
						  
						//set the solution   
						//g.setSolution(solution);
						  g.setSolution(qActitivities);
						
						//set the qualification activities
						// g.setQaulificationActivities(mycheckActivity);

						//save the gec
						stub.savegec(g,args[0]);
				  }
			   }
					catch(Exception e) {
					  e.printStackTrace();
				  }		   
        }
}

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
You haven't used the code as i posted it. Also, your methods are too long - you should break them up. The main method should have very little code in it
0
 

Author Comment

by:Tolgar
Comment Utility
I used your code between lines 91-108 but it still errors out there. So there should be something else going on.

You are right the main should have less. But I don't think it is the reason. Right?

thanks,
0
 
LVL 92

Assisted Solution

by:objects
objects earned 100 total points
Comment Utility
you had a few errors in there

try this
import com.mywork.tools.GPrequal.ws.*;
import java.util.*;
import java.io.*;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebResponse;
import com.meterware.httpunit.WebTable;
import com.meterware.httpunit.HttpUnitOptions;

import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

//java -jar GPrequal-1.0.jar abcd "681416, 756455" "148050 at A" "/dev/A/"
public class bLogData2G {
	// SEND EMAIL
	public static void sendEmail(java.lang.String arg) {
		// Recipient's email ID needs to be mentioned.
		java.lang.String to = arg + "@mywork.com";

		// Sender's email ID needs to be mentioned
		java.lang.String from = "myserve@mywork.com";

		// Assuming you are sending email from localhost
		java.lang.String host = "localhost";

		// Get system properties
		Properties properties = System.getProperties();

		// Setup mail server
		properties.setProperty("mail.smtp.host", host);

		// Get the default Session object
		Session session = Session.getDefaultInstance(properties);

		try {
			// Create a default MimeMessage object.
			MimeMessage message = new MimeMessage(session);

			// Set From: header field of the header.
			message.setFrom(new InternetAddress(from));

			// Set To: header field of the header.
			message.addRecipient(Message.RecipientType.TO, new InternetAddress(
					to));

			// Set Subject: header field
			message.setSubject("Logging to G Failed");

			// Now set the actual message
			message.setText("Logging to G Failed due to the size limit in the text fields");

			// Send message
			Transport.send(message);
		} catch (MessagingException mex) {
			mex.printStackTrace();
		}
	}

	// END OF SEND EMAIL

	// args[] = login, gecIDList, myID@cluster, pathToJobfile
	public static void main(java.lang.String args[]) {
		java.lang.String soapEndpointURL = "http://Gwebtest-00-blr.mywork.com/main/services/gecWebService";
		// Add g as a prefix to each gec to make them as a link in the solution
		// field
		// java.lang.String gecIDList = "g" + args[1] + args[1].replaceAll(",",
		// ",g");
		java.lang.String gecIDList = args[1].replaceAll("(\\d+)", "g$1");

		// Find the location of the mycheck report using the path to myruntests
		// report in submit file.
		/*
		 * try { DataInputStream in = new DataInputStream(new
		 * FileInputStream(args[3])); java.lang.String buff = null; while((buff=
		 * in.readline()) != null){ if(buff.indexOf( "<a href='http://") > -1 &&
		 * buff.indexOf( "myruntests") > -1){ java.lang.String
		 * SbPathInSubmitFile = buff; } } in.close(); }catch(Exception ex){
		 * ex.printStackTrace(); }
		 */
		java.lang.String SbPathInSubmitFile = null;
		try {
			Scanner in = new Scanner(new File(args[3]));
			java.lang.String buff = null;
			while (in.hasNextLine()) {
				buff = in.nextLine();
				if ((buff.indexOf("<a href='http://") > -1)
						&& (buff.indexOf("myruntests") > -1)) {
					SbPathInSubmitFile = buff;
				}
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			try {
				in.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		int ix = 0;
		if ((ix = SbPathInSubmitFile.indexOf("/sbtest")) > -1) {
			SbPathInSubmitFile = SbPathInSubmitFile.substring(0, ix);
		}
		java.lang.String mycheckReportPath = SbPathInSubmitFile
				+ "mycheck/report.html";

		java.lang.String mycheckActivity = "";
		try {
			HttpUnitOptions.setScriptingEnabled(false);
			WebConversation wc = new WebConversation();
			WebResponse wr = wc.getResponse(mycheckReportPath);
			WebTable table = wr.getTables()[0];
			java.lang.String[][] cells = table.asText();
			for (java.lang.String[] row : cells) {
				for (java.lang.String cell : row) {
					mycheckActivity += cell;
				}
				mycheckActivity += System.getProperty("line.separator");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		try {
			gecWebServiceSoapBindingStub stub = new gecWebServiceSoapBindingStub(
					new java.net.URL(soapEndpointURL),
					new org.apache.axis.client.Service());

			// find the submitted files in the job file
			java.lang.String myFiles = "";
			try {
				DataInputStream in = new DataInputStream(new FileInputStream(
						args[3]));
				java.lang.String jobFile = null;
				while ((jobFile = in.readLine()) != null) {
					if (jobFile.startsWith("s") || jobFile.startsWith("S")
							|| jobFile.startsWith("D")) {
						myFiles += jobFile
								+ System.getProperty("line.separator");
					}
				}
				in.close();
			} catch (Exception e) {
				e.printStackTrace();
			}

			// Get the number of records (gecs)
			java.lang.String[] gecs = args[1].split(",");
			int[] gecList = new int[gecs.length];

			for (int j = 0; j < gecList.length; j++) {

				java.lang.String myservemsg = "The information below is logged into this field by myserve";
				// Get the jth gecID
				java.lang.Integer gecID = java.lang.Integer.parseInt(gecs[j]);

				// Lock the gec and get the gec object. Arguments: gecID, login
				gec g = stub.lockgec(gecID, args[0]);

				// Get the date and time of the G logging
				java.lang.String gecUpdateDate = new java.text.SimpleDateFormat(
						"yyyy-MM-dd HH:mm zzz").format(new java.util.Date());

				// UNCOMMENT THIS PART ONCE NEW WSDL IS READY WITH Qualification
				// Actitivities FIELD
				// Get the current Qualification Actitivities;
				// //////////// java.lang.String qActivities =
				// g.getQualificationActivities();
				java.lang.String qActivities = g.getSolution();

				// Stop logging files to qActivities field if qActivities field
				// does not have enough space (KB).
				// Each char in a java string is *two* bytes - it uses UTF16
				// encoding
				java.lang.String totalqActivitiesData = args[0] + " - "
						+ gecUpdateDate + "\n\n" + myservemsg + "\n\n"
						+ mycheckActivity + "\n\n\n" + qActivities + "\n";
				java.lang.Double totalqActivitiesSize = totalqActivitiesData
						.length() * 2 / 1024.0;

				// Qualification Actitivities field size is 64 kb. However I put
				// a buffer in case someone needs to put a few more lines later
				// on.
				// That's why I use 60 instead of 64.
				if (totalqActivitiesSize < 60) {
					qActivities = args[0] + " - " + gecUpdateDate + "\n\n"
							+ myservemsg + "\n\n" + "mycheck	STATUS" + "\n\n"
							+ mycheckActivity + "\n\n\n" + qActivities + "\n";
				} else {
					// sendEmail(args[0]);
					qActivities = args[0]
							+ " - "
							+ gecUpdateDate
							+ "\n\n"
							+ myservemsg
							+ "\n\n"
							+ "mycheck report cannot be logged in because text field size was exceeded."
							+ "\n\n\n" + qActivities + "\n";
				}

				// END OF UNCOMMENT */
				// Get the current Solution;
				java.lang.String solution = g.getSolution();

				// Stop logging files to solution field if Solution field does
				// not have enough space (KB).
				// Each char in a java string is *two* bytes - it uses UTF16
				// encoding
				java.lang.String totalSolutionData = args[0] + " - "
						+ gecUpdateDate + "\n\n" + myservemsg + "\n\n"
						+ "myID: " + args[2] + "\n" + "Related Records: "
						+ gecIDList + "\n\n" + myFiles + "\n\n\n" + solution
						+ "\n";
				java.lang.Double totalsolutionSize = totalSolutionData.length() * 2 / 1024.0;

				// Solution field size is 64 kb. However I put a buffer in case
				// someone needs to put a few more lines later on.
				// That's why I use 60 instead of 64.
				if (totalsolutionSize < 60) {
					solution = args[0] + " - " + gecUpdateDate + "\n\n"
							+ myservemsg + "\n\n" + "myID: " + args[2] + "\n"
							+ "Related Records: " + gecIDList + "\n\n"
							+ myFiles + "\n\n\n" + solution + "\n";
					// }
					// else{
					// sendEmail(args[0]);
					// solution = args[0] + " - " + gecUpdateDate + "\n\n" +
					// myservemsg + "\n\n" + "myID: " + args[2] + "\n" +
					// "Related Records: " + gecIDList + "\n\n" +
					// "Submitted files cannot be logged in because text field size was exceeded."
					// + "\n\n\n" + solution + "\n";
					// }

					// set the solution
					// g.setSolution(solution);
					g.setSolution(qActivities);

					// set the qualification activities
					// g.setQaulificationActivities(mycheckActivity);

					// save the gec
					stub.savegec(g, args[0]);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Open in new window

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now