Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 523
  • Last Modified:

how to include packages in Java

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
Tolgar
Asked:
Tolgar
  • 6
  • 6
  • 3
  • +1
3 Solutions
 
for_yanCommented:
You have to have mail.jar and activation.jar in your classpath
I guess meterware jar is also needed
0
 
for_yanCommented:

For httpunit you need jar from here:
http://sourceforge.net/projects/httpunit/files/httpunit/1.7/
I guess, you already have it
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
CEHJCommented:
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
 
TolgarAuthor Commented:
@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
 
CEHJCommented:
Try
<dependency>
    <groupId>httpunit</groupId>
    <artifactId>httpunit</artifactId>
    <version>1.7</version>
</dependency>

Open in new window

0
 
TolgarAuthor Commented:
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
 
CEHJCommented:
Hmm. DataInputStream.readLine is not good to be using. What are you doing with that exactly - can you post the code?
0
 
TolgarAuthor Commented:
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
 
CEHJCommented:
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
 
TolgarAuthor Commented:
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
 
CEHJCommented:
Can you please post your adjusted code?
0
 
TolgarAuthor Commented:
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
 
CEHJCommented:
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
 
TolgarAuthor Commented:
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
 
objectsCommented:
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 6
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now