# Package Help

• 05-16-2011, 08:49 PM
DMarsh12
Package Help
For a final project due tomorrow I am having issues packaging the search and sort program I have created...I don't know how to package it at all...any help would be greatly appreciated.

Code:

```/*  * Daniel Marshall  * Exam 2-Searching and Sorting  * 04/08/2011  * CSCI 180 W02  * Prof. Jack Wu  */ package classwork; import classwork.classwork;         public class classwork {//creating class "classwork"                 public static void main(String[]args){//Main Method                         int list[]={123,157,162,217,345,612,718,913,319,412,123,159};//creating array int                         int i = binarySearch(list,2);System.out.println("The value of i is:" + i);//declaration of int i                         int j = binarySearch(list,11);System.out.println("The value of j is:" + j);//declaration of int j                         int k = binarySearch(list,12);System.out.println("The value of k is:" + k);//declaration of int j                         int l = binarySearch(list,1);System.out.println("The value of l:" + l);//declaration of int l                         int m = binarySearch(list,3);System.out.println("The value of m:" + m);//declaration of int m                         selectionsort(list);                 }                 public static int binarySearch (int[]list, int key){//                         int low = 0;int high = list.length - 1;//int low and high                         while(high > low){//while statement                                 int mid = (low + high)/2;//int mid                                 if (key < list[mid]) high = mid - 1;//if statement                                 else if (key==list[mid])return mid;//else statement                                 else low = mid + 1;//else statement                         }                         return - low -1;//return statement                 }                 public static void selectionsort(int[]list){                         for (int i = list.length - 1;i>=1;i--){//for statement                                 int currentmax = list[0];//int currentmax                                 int currentmaxinx = 0;                                 for (int j=1;j<=i;j++){//for loop                                         if        (currentmax == list[i])//if statement                                                 currentmax = list[j];                                                 currentmaxinx = j;                                                 System.out.println(currentmax+" "+currentmaxinx);//System printout                                                 if(currentmaxinx!=i){//if statement                                                         list [currentmaxinx] = list[i];                                                         list [i] = currentmax;                                                 }                                 }                         }                 }         } /*  *Output  *The value of i is:-1 The value of j is:-1 The value of k is:-1 The value of l:-1 The value of m:-1 123 1 162 2 217 3 345 4 612 5 718 6 913 7 319 8 412 9 123 10 Process completed. */```
• 05-16-2011, 08:55 PM
Norm
What do you mean by "packaging"?
Putting the class files in a jar file?
Using the package statement?
• 05-17-2011, 12:43 AM
DMarsh12
yes that is exactly what i mean
• 05-17-2011, 02:41 AM
sunde887
Try this link and others on similar topics at this site, it should help: Creating a JAR File (The Java™ Tutorials > Deployment > Packaging Programs in JAR Files)
• 05-17-2011, 02:49 AM
Norm
Which of the two possibilities I listed is exactly what i mean?
• 05-17-2011, 03:18 AM
DMarsh12
Quote:

Originally Posted by Norm
Which of the two possibilities I listed is exactly what i mean?

using the package type... i am close to doing it but when i do package them together it says it cannot find the list in the other file i dont get it
• 05-17-2011, 03:22 AM
Norm
Quote:

it says it cannot find
Please copy and paste the console showing the command entered and the error message.

If you use packages in your code, the class file in the jar file must be on the path set by the package statement. The jar command must get the files from the folder containing the classwork folder and include the classwork folder in the path to the class file that is added to the jar file.

Here's a batch file I use to create a jar file. The NormsTools folder is in the JavaDevelopment folder.
Quote:

REM Make CreateTN.jar file - for 1.6
%DEV_DRIVE%