Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    .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

    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);
    	}
    }
    Last edited by ramenfiend; 07-28-2006 at 03:29 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    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?


  • #3
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    nope. he's a Ramen fiend, ie. he likes noodles. "Windows enemy" would be "Fensterfeind".
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    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
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •