?
Solved

how to include packages in Java

Posted on 2011-03-22
16
Medium Priority
?
513 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 3
  • +1
16 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 35192797
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 800 total points
ID: 35192828
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35192857

For httpunit you need jar from here:
http://sourceforge.net/projects/httpunit/files/httpunit/1.7/
I guess, you already have it
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 800 total points
ID: 35192953
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
ID: 35193324
@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
ID: 35193528
Try
<dependency>
    <groupId>httpunit</groupId>
    <artifactId>httpunit</artifactId>
    <version>1.7</version>
</dependency>

Open in new window

0
 

Author Comment

by:Tolgar
ID: 35193820
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
ID: 35194006
Hmm. DataInputStream.readLine is not good to be using. What are you doing with that exactly - can you post the code?
0
 

Author Comment

by:Tolgar
ID: 35194186
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
ID: 35194231
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
ID: 35194483
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
ID: 35194634
Can you please post your adjusted code?
0
 

Author Comment

by:Tolgar
ID: 35194730
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
ID: 35194807
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
ID: 35194832
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 400 total points
ID: 35194864
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month9 days, 22 hours left to enroll

762 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