CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Java and JSP (http://www.codingforums.com/forumdisplay.php?f=54)
-   -   .java to executable? (http://www.codingforums.com/showthread.php?t=92182)

ramenfiend 07-28-2006 04:28 AM

.java to executable?
 
Hello, I have 0 experience in the ways of java but recently had a script made for me in it.

Lets say for the sake of the thread that my computer cannot run java applications, rather requiring an executable of some sort.

Would anyone mind creating a simple .exe from this .java file?
Is such a thing even reasonable to expect? I have no idea of how complex this would be.

It obviously would not be the safest way, so I would greatly prefer the sourcecode of that executable to the actual .exe, but after waiting 6 months for this project to even get this far I can settle for less :thumbsup:

Much obliged,
rf

Edit: wow, I forgot to attach the javascript.
Edit2: it isnt javascript :O
Code:

import java.io.*;
import java.util.Scanner;
import java.util.regex.MatchResult;

public class Converter
{
        public static void main( String[] args )
        {
                BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
                System.out.println("Please make sure the file you wish to convert is in\nthe same directory as this program and enter the name:");

                try
                {
                        Converter.convert(new File(stdin.readLine()));
                        System.out.println("[Note: Any existing files may have been replaced.]");
                }
                catch (IOException ioex)
                {
                        System.out.println("Conversion Failed!");
                }

                System.exit(0);
        }
        public static File convert( File input ) throws IOException
        {
                return(Converter.convertCleanedInput(Converter.cleanInput(input)));
        }
        private static File cleanInput( File inputToClean ) throws IOException
        {
                //Description:        Cleans input file with the following format...
                //
                //                                pos#A" Saved: ( # # # ) #B #C ( # # # )        input (FLBR) : $VARIOUS server time : #D
                //                                #A #B #C $VARIOUS #D
                //
                //                                If $VARIOUS is null, then it is replaced by a hyphen as a place holder.

                File                        outFile = new File("CleanInput.rtf");
                BufferedWriter        out = new BufferedWriter(new FileWriter(outFile, false));
                Scanner                        in = new Scanner(inputToClean);

                //The following code obtains the pattern we wish to look for.
                //Please do not edit it, as even the smallest change will cause the program to stop functioning properly.
                in.findWithinHorizon("pos(\\S+)\"\\sSaved:\\s\\(\\s\\S*\\s\\S*\\s\\S*\\s\\)\\s(\\S*)\\s(\\S*)\\s\\(\\s\\S*\\s\\S*\\s\\S*\\s\\)\\sinput\\s\\(FLBR\\)\\s:\\s(\\S*\\s*\\S*\\s*\\S*\\s*\\S*)\\s*server\\stime\\s:\\s(\\S*)",0);
                MatchResult result = null;

                try
                {
                        result = in.match();
                }
                catch (IllegalStateException ise)
                {
                        return(outFile);
                }

                while (true)
                {
                        //The following loop goes through each line that matches the pattern and puts it into a strict format.
                        for (int i = 1; i <= result.groupCount(); i++)
                        {
                                switch (i)
                                {
                                        case 1://#A
                                        case 2://#B
                                        case 3://#C
                                                out.write(result.group(i) + " ");
                                                break;
                                        case 4://$VARIOUS
                                                out.write((result.group(i).length() == 0 ? "- " : result.group(i).replaceAll("\\s", "") + " "));
                                                break;
                                        case 5://#D
                                                out.write(result.group(i));
                                                break;
                                        default://This case should never occur.
                                                break;
                                }
                        }

                        out.newLine();
                        in.findWithinHorizon("pos(\\S+)\"\\sSaved:\\s\\(\\s\\S*\\s\\S*\\s\\S*\\s\\)\\s(\\S*)\\s(\\S*)\\s\\(\\s\\S*\\s\\S*\\s\\S*\\s\\)\\sinput\\s\\(FLBR\\)\\s:\\s(\\S*\\s*\\S*\\s*\\S*\\s*\\S*)\\s*server\\stime\\s:\\s(\\S*)",0);

                        try
                        {
                                result = in.match();
                        }
                        catch (IllegalStateException ise)
                        {
                                break;
                        }
                }

                out.close();
                in.close();

                System.out.println("Cleaned input file and saved as \"CleanInput.rtf\"");

                return(outFile);
        }
        private static File convertCleanedInput( File cleanInput ) throws IOException
        {
                //Description:        Converts cleaned line of input with the following format...
                //
                //                                #A #B #C $VARIOUS #D
                //                                //#A//#D//;cl_pitchspeed #Pitch;cl_yawspeed #Yaw;$FBJCLRA
                //
                //                                #Pitch        =        Current #B * 125 - Previous #B * 125
                //                                #Yaw        =        Current #C * 125 - Previous #C * 125
                //                                $FBJCLRA        is derived from {Various} based on which letters
                //                                                        it contains, or subsequently, does not contain:
                //                                                        F = +forward, no F = -forward
                //                                                        B = +back, no B = -back
                //                                                        J = +moveup, no J = -moveup
                //                                                        C = +movedown, no C = -movedown
                //                                                        L = +moveleft, no L = -moveleft
                //                                                        R = +moveright, no R = -moveright
                //                                                        A = +attack, no A = -attack



                File                        outFile = new File("ConvertedInput.rtf");
                BufferedWriter        out = new BufferedWriter(new FileWriter(outFile, false));
                Scanner                        in = new Scanner(cleanInput),
                                                traversal = null;
                double[][]                pitchAndYaw = new double[2][2];
                String[]                convertedLine = new String[5];

                while (in.hasNextLine())
                {
                        traversal = new Scanner(in.nextLine());
                        convertedLine[0] = "//" + traversal.nextInt();
                        pitchAndYaw[0][0] = pitchAndYaw[1][0];
                        pitchAndYaw[0][1] = pitchAndYaw[1][1];
                        pitchAndYaw[1][0] = traversal.nextDouble();
                        pitchAndYaw[1][1] = traversal.nextDouble();
                        convertedLine[2] = "//;cl_pitchspeed " + ((pitchAndYaw[1][0] * 125) - (pitchAndYaw[0][0] * 125));
                        convertedLine[3] = ";cl_yawspeed " + ((pitchAndYaw[1][1] * 125) - (pitchAndYaw[0][1] * 125));
                        String FBJCLRA = traversal.next().toUpperCase();
                        convertedLine[1] = "//" + traversal.next();
                        convertedLine[4] =        ";" + (FBJCLRA.contains("F") ? "+" : "-") + "forward;" +
                                                                (FBJCLRA.contains("B") ? "+" : "-") + "back;" +
                                                                (FBJCLRA.contains("J") ? "+" : "-") + "moveup;" +
                                                                (FBJCLRA.contains("C") ? "+" : "-") + "movedown;" +
                                                                (FBJCLRA.contains("L") ? "+" : "-") + "moveleft;" +
                                                                (FBJCLRA.contains("R") ? "+" : "-") + "moveright;" +
                                                                (FBJCLRA.contains("A") ? "+" : "-") + "attack;";


                        out.write(convertedLine[0] + convertedLine[1] + convertedLine[2] + convertedLine[3] + convertedLine[4]);
                        out.newLine();
                }

                out.close();
                in.close();

                System.out.println("Converted cleaned input file and saved as \"ConvertedInput.rtf\"");

                return(outFile);
        }
}


Philip M 07-28-2006 07:40 AM

You are in the wrong place. JavaScript is not the same language as Java in spite of the confusingly similar names. Perhaps a mod will transfer you to the right forum.

Ramen = Windows
Fiend = Enemy
Teutonic humour, Ja?

:rolleyes:

joh6nn 07-28-2006 02:09 PM

nope. he's a Ramen fiend, ie. he likes noodles. "Windows enemy" would be "Fensterfeind".

Spookster 07-28-2006 03:15 PM

Your machine has to able to run java applications in order to run a java application even if you create an executable .exe type application surrounding your java program. Java requires that a JVM java virtual machine be installed on the platform where it is going to run. See this thread for more information on creating java .exe type programs

http://codingforums.com/showthread.php?t=89685

ramenfiend 07-28-2006 03:19 PM

My bad, thanks for the explanation.

I get all kinds of problems trying to run the .class using a .bat, but thats a problem for another forum.

And yes, ramenfiend = one who craves a certian type of noodles. :)


All times are GMT +1. The time now is 07:36 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.