Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 25 of 25

Thread: Extracting Eclipse project as runnable java isn't working

  1. #1
    Member
    Join Date
    Oct 2013
    Posts
    78
    Thanks
    55
    Thanked 0 Times in 0 Posts

    Default Extracting Eclipse project as runnable java isn't working

    Greetings!

    I've been working quite a bit with a login system the past couple of months and I now have a version that I would like to try "for real" by extracting it as a runnable .jar or .exe file. I've looked at a couple of guides that told me how to do this properly, but even after following every step precisely it didn't work.

    One of the guides I tried: 3 Ways to Create an Executable File from Eclipse - wikiHow

    Double clicking the file or selecting it and pressing enter does nothing, the computer loads for a second and then nothing happens. I don't receive any visible errors when extracting the program, either.

    However, when running the file from the command prompt I do receive an odd error:
    Microsoft Windows [Version 6.2.9200]
    (c) 2012 Microsoft Corporation. All rights reserved.

    C:\Users\UserName>java -jar Login.jar
    Exception in thread "main" java.lang.IllegalArgumentException: input == null!
    at javax.imageio.ImageIO.read(Unknown Source)
    at LoginSystem.Data.updateData(Data.java:347)
    at LoginSystem.Data.<init>(Data.java:309)
    at LoginSystem.MainFrame.<init>(MainFrame.java:42)
    at LoginSystem.MainFrame.main(MainFrame.java:457)

    C:\Users\UserName>

    I must say I don't quite understand the error, it seems to be unable to load an image which is odd considering the program works fine without any errors at all in Eclipse.

    Anyone that can shed some light on what exactly the problem is, and if so how to solve it? =/


  2. #2
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Quote Originally Posted by Lora_91 View Post
    C:\Users\UserName>java -jar Login.jar
    Exception in thread "main" java.lang.IllegalArgumentException: input == null!
    at javax.imageio.ImageIO.read(Unknown Source)
    at LoginSystem.Data.updateData(Data.java:347)
    at LoginSystem.Data.<init>(Data.java:309)
    at LoginSystem.MainFrame.<init>(MainFrame.java:42)
    at LoginSystem.MainFrame.main(MainFrame.java:457)

    I must say I don't quite understand the error, it seems to be unable to load an image which is odd considering the program works fine without any errors at all in Eclipse.
    I guess/imagine you have done a thing like:

    .... ImageIO.read(new File("someimage.png"))

    or similar concept.

    Well, "someimage.png" is a specification on the local file-system and, more important, is a "relative" specification. It's relative to the "current" directory. What is the current directory when you launch your app outside Eclipse?? I don't know ..... It may or may not be correct/appropriate for that image specification.

    And if you guess, this is not the appropriate way. Please see my answer: http://www.javaprogrammingforums.com...tml#post137932
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  3. The Following User Says Thank You to andbin For This Useful Post:

    Lora_91 (February 11th, 2014)

  4. #3
    Member
    Join Date
    Oct 2013
    Posts
    78
    Thanks
    55
    Thanked 0 Times in 0 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Hm, I suppose the end result I get in the way I'm using it is the same as the example you posted, as of currently all of the filepaths the images use is based on String array variables so that the user can change them with ease, or at least that's the idea. Therefor I also added a default String array path which they should refer to if they didn't have anything else specified:

        public String[] defaultPaths = new String[] {"/images/indasupport.png", 
        											"/images/exit.jpg", 
        											"/images/createuser.jpg", 
        											"/images/terminateuser.jpg",
        											"/images/admin.jpg",
        											"/images/login.jpg",
        											"/images/logout.jpg",
        											"/images/unlocked.jpg",
        											"/images/locked.jpg",
        											"/images/changePassword.jpg",
        											"/images/changeInterface.jpg",
        											"/images/checked.jpg",
        											"/images/unchecked.jpg",
        											"/images/confirm.jpg",
        											"/images/cancel.jpg",
        											"/images/miniconfirm.jpg",
        											"/images/minicancel.jpg",
        											"/images/print.jpg",
        											"/images/info.jpg",
        											"/images/default.jpg",
        											"/images/swedish.jpg",
        											"/images/english.jpg"
        											};

    Image oldImage = ImageIO.read(getClass().getResource(filepaths[i]));

    _________________________

    Edit:

    I added three URL array variables and read the filepath information into those in the way you suggested and referred to those, but I received a new similar error anyway. =/

    	        for(int i = 0; i < numberOfImagesUsed; i++)
        	    	{
        	        	if(imgURL[i] == null)
        				{
        	        		imgURL[i] = Data.class.getResource(defaultPaths[i]);

    Error:
    Microsoft Windows [Version 6.2.9200]
    (c) 2012 Microsoft Corporation. All rights reserved.

    C:\Users\UserName>java -jar Login.jar .jar
    Exception in thread "main" java.lang.IllegalArgumentException: input == null!
    at javax.imageio.ImageIO.read(Unknown Source)
    at LoginSystem.Data.updateData(Data.java:357)
    at LoginSystem.Data.<init>(Data.java:319)
    at LoginSystem.MainFrame.<init>(MainFrame.java:41)
    at LoginSystem.MainFrame.main(MainFrame.java:450)

    C:\Users\UserName>

    line 357:
    Image oldImage = ImageIO.read(imgURL[i]);

  5. #4
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Quote Originally Posted by Lora_91 View Post
        public String[] defaultPaths = new String[] {"/images/indasupport.png", 
        											"/images/exit.jpg", 
        											"/images/createuser.jpg",
        	        		imgURL[i] = Data.class.getResource(defaultPaths[i]);
    Image oldImage = ImageIO.read(imgURL[i]);
    Here you have used the concept of "resource". But a resource specification that starts with '/' means that the name is "absolute" starting from the classpath "root". So, do you have a top level package named "images"? If not, it's obviously not correct.

    If you had done: "images/indasupport.png" (no '/' at the start), then the "images" would be relative to the package of Data class. If Data is e.g. org.sample.Data, the indasupport.png would be found at org/sample/images/indasupport.png. And "org" is not relative to current directory but found on the classpath.
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  6. The Following User Says Thank You to andbin For This Useful Post:

    Lora_91 (February 11th, 2014)

  7. #5
    Member
    Join Date
    Oct 2013
    Location
    United Kingdom
    Posts
    62
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Hi Lora, Did you code executed successfully in eclipse when it was not compressed?

    Can we please have the code of Data.java and please highlight line no 357..
    Thanks and regards,
    Sambit Swain

  8. #6
    Member
    Join Date
    Oct 2013
    Posts
    78
    Thanks
    55
    Thanked 0 Times in 0 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    I tried removing all of the '/' at the start of every filepath line but still got the same result, same error. =/

    --- Update ---

    Quote Originally Posted by Sambit View Post
    Hi Lora, Did you code executed successfully in eclipse when it was not compressed?

    Can we please have the code of Data.java and please highlight line no 357..
    Yes, the program works perfectly within Eclipse, but not at all as a .exe o .jar.

    Highlighted the 357 line with: "//This is the 357 line".

    Data.java
    package LoginSystem;
    import java.awt.*;
    import java.io.*;
    import java.net.URL;
     
    import javax.imageio.ImageIO;
    import javax.swing.*;
     
    public class Data
    {
        private MainFrame mainFrame;
     
     
     
        public MainFrame getMain()
        {
            return mainFrame;
        }
     
       // public String[] imgURL = new String[500];
        public String[] defaultPaths = new String[] {"http://www.javaprogrammingforums.com/images/indasupport.png", 
        											"http://www.javaprogrammingforums.com/images/exit.jpg", 
        											"http://www.javaprogrammingforums.com/images/createuser.jpg", 
        											"http://www.javaprogrammingforums.com/images/terminateuser.jpg",
        											"http://www.javaprogrammingforums.com/images/admin.jpg",
        											"http://www.javaprogrammingforums.com/images/login.jpg",
        											"http://www.javaprogrammingforums.com/images/logout.jpg",
        											"http://www.javaprogrammingforums.com/images/unlocked.jpg",
        											"http://www.javaprogrammingforums.com/images/locked.jpg",
        											"http://www.javaprogrammingforums.com/images/changePassword.jpg",
        											"http://www.javaprogrammingforums.com/images/changeInterface.jpg",
        											"http://www.javaprogrammingforums.com/images/checked.jpg",
        											"http://www.javaprogrammingforums.com/images/unchecked.jpg",
        											"http://www.javaprogrammingforums.com/images/confirm.jpg",
        											"http://www.javaprogrammingforums.com/images/cancel.jpg",
        											"http://www.javaprogrammingforums.com/images/miniconfirm.jpg",
        											"http://www.javaprogrammingforums.com/images/minicancel.jpg",
        											"http://www.javaprogrammingforums.com/images/print.jpg",
        											"http://www.javaprogrammingforums.com/images/info.jpg",
        											"http://www.javaprogrammingforums.com/images/default.jpg",
        											"http://www.javaprogrammingforums.com/images/swedish.jpg",
        											"http://www.javaprogrammingforums.com/images/english.jpg"
        											};
     
     
     
        //public String[] imgURLRollover = new String[500];
        public String[] defaultPathsRollover = new String[] {"http://www.javaprogrammingforums.com/images/indasupport.png", 
    														"http://www.javaprogrammingforums.com/images/exitRollover.jpg", 
    														"http://www.javaprogrammingforums.com/images/createuserRollover.jpg", 
    														"http://www.javaprogrammingforums.com/images/terminateuserRollover.jpg",
    														"http://www.javaprogrammingforums.com/images/adminRollover.jpg",
    														"http://www.javaprogrammingforums.com/images/loginRollover.jpg",
    														"http://www.javaprogrammingforums.com/images/logoutRollover.jpg",
    														"http://www.javaprogrammingforums.com/images/unlockedRollover.jpg",
    														"http://www.javaprogrammingforums.com/images/lockedRollover.jpg",
    														"http://www.javaprogrammingforums.com/images/changePasswordRollover.jpg",
    														"http://www.javaprogrammingforums.com/images/changeInterfaceRollover.jpg",
    														"http://www.javaprogrammingforums.com/images/checked.jpg",
    														"http://www.javaprogrammingforums.com/images/unchecked.jpg",
    														"http://www.javaprogrammingforums.com/images/confirmRollover.jpg",
    														"http://www.javaprogrammingforums.com/images/cancelRollover.jpg",
    														"http://www.javaprogrammingforums.com/images/miniconfirmRollover.jpg",
    														"http://www.javaprogrammingforums.com/images/minicancelRollover.jpg",
    														"http://www.javaprogrammingforums.com/images/print.jpg",
    														"http://www.javaprogrammingforums.com/images/infoRollover.jpg",
    														"http://www.javaprogrammingforums.com/images/defaultRollover.jpg",
    														"http://www.javaprogrammingforums.com/images/swedish.jpg",
    														"http://www.javaprogrammingforums.com/images/english.jpg"
    														};
     
       //public String[] imgURLPressed = new String[500];
     
        public String[] defaultPathsPressed = new String[] {"http://www.javaprogrammingforums.com/images/indasupport.png", 
    														"http://www.javaprogrammingforums.com/images/exitPressed.jpg", 
    														"http://www.javaprogrammingforums.com/images/createuserPressed.jpg", 
    														"http://www.javaprogrammingforums.com/images/terminateuserPressed.jpg",
    														"http://www.javaprogrammingforums.com/images/adminPressed.jpg",
    														"http://www.javaprogrammingforums.com/images/loginPressed.jpg",
    														"http://www.javaprogrammingforums.com/images/logoutPressed.jpg",
    														"http://www.javaprogrammingforums.com/images/unlockedPressed.jpg",
    														"http://www.javaprogrammingforums.com/images/lockedPressed.jpg",
    														"http://www.javaprogrammingforums.com/images/changePasswordPressed.jpg",
    														"http://www.javaprogrammingforums.com/images/changeInterfacePressed.jpg",
    														"http://www.javaprogrammingforums.com/images/checked.jpg",
    														"http://www.javaprogrammingforums.com/images/unchecked.jpg",
    														"http://www.javaprogrammingforums.com/images/confirmPressed.jpg",
    														"http://www.javaprogrammingforums.com/images/cancelPressed.jpg",
    														"http://www.javaprogrammingforums.com/images/miniconfirmPressed.jpg",
    														"http://www.javaprogrammingforums.com/images/minicancelPressed.jpg",
    														"http://www.javaprogrammingforums.com/images/print.jpg",
    														"http://www.javaprogrammingforums.com/images/infoPressed.jpg",
    														"http://www.javaprogrammingforums.com/images/defaultPressed.jpg",
    														"http://www.javaprogrammingforums.com/images/swedish.jpg",
    														"http://www.javaprogrammingforums.com/images/english.jpg"
    														};
     
     // 00 Logo
     // 01 exit button
     // 02 create user button
     // 03 terminate user button
     // 04 admin button
     // 05 login button
     // 06 logout button
     // 07 logged in image
     // 08 logged out image
     // 09 change password button
     // 10 change interface button
     // 11 checkbox checked button
     // 12 checkbox unchecked button
     // 13 confirm button
     // 14 cancel button
     // 15 miniconfirm button
     // 16 minicancel button
     // 17 print button
     // 18 info button
     // 19 default button
     // 20 swedish button
     // 21 english button
     
        String textFrameSwedish = "Välkommen till Inda Support!" + "\n"
                + "I det här programmet så kan du skapa ditt nya användarkonto genom att " + "\n"
                + "trycka på 'create account' nedan. Där blir du ombedd att fylla i ditt" + "\n"
                + "förnamn, efternamn och det lösenord som du vill ha. När du är klar så" + "\n"
                + "är det bara att trycka på enter, så kommer ditt nya konto att vara skapat." + "\n"
                + "\n"
                + "För att sedan logga in på ditt konto så trycker du på den lilla rutan som" + "\n"
                + "är till vänster om ditt namn, du hittar ditt konto i rutan till vänster." + "\n"
                + "Om du inte kan hitta ditt namn bland alla andra konton så behöver du nog scrolla" + "\n"
                + "ner lite grann först." + "\n"
                + "\n"
                + "När du tryckt på knappen så kommer en ny ruta upp, du trycker då helt enkelt på" + "\n"
                + "'Log in' knappen och skriver in ditt lösenord, så märker du att rutan till vänster" + "\n"
                + "om ditt konto har blivit grön för att signalera att du loggat in." + "\n"
                + "Stäng sedan ditt kontofönster genom att trycka på exit." + "\n"
                + "\n"
                + "När du sedan behöver logga ut för dagen så gör du precis likadant, tryck" + "\n"
                + "på knappen till vänster om ditt konto, tryck på logga ut knappen och skriv" + "\n"
                + "återigen in ditt lösenord. Stäng sedan ditt kontofönster genom att trycka på exit." + "\n";
     
        String textFrameEnglish = "Welcome to Inda Support!" + "\n"
                + "In this program you will be able to create your new user account by" + "\n"
                + "pressing the 'create account' button below. There you will be asked to enter your" + "\n"
                + "first name, last name and the password that you want to use. When you are done" + "\n"
                + "all you need to do is press enter, and your new account will be created." + "\n"
                + "\n"
                + "To then log in  you press the small button to the left of your name, which you can" + "\n"
                + "find in the left frame next to this one." + "\n"
                + "If you can not find your name amongst all of the other names you will probably have to" + "\n"
                + "scroll down a bit first.." + "\n"
                + "\n"
                + "When you've pressed the button a new frame will appear, then all you need to do is press the" + "\n"
                + "'Log in' button and enter your password, you will notice that the frame to your left of your account" + "\n"
                + "name has turned green to show that you're online." + "\n"
                + "When you're done you can close down your account frame by pressing exit." + "\n"
                + "\n"
                + "When you wish to log out for the day you proceed the same way as before, press" + "\n"
                + "the button to the left of your account, press the logout button and enter your password again." + "\n"
                + "Close your account frame by pressing exit." + "\n";
     
     
     
     
        public String[] defaultEnglishTextMessages = new String[]{
    			textFrameEnglish,												//00
        		"Welcome to Inda Support Login!",								//01
    			"Users:",														//02
    			"Enter password",												//03
    			"Incorrect password",											//04
    			"First name:",													//05
    			"Last name:",													//06
    			"Password:",													//07
    			"Repeat password:",												//08
    			"Are you sure you wish to cancel?",								//09
    			"Admin password:",												//10
    			"Toggle setting:",												//11
    			"Admin functions:",												//12
    			"Only admins can create new accounts.",							//13
    			"Only admins can terminate accounts.",							//14
    			"Only admins can change language.",								//15
    			"Start date:",													//16
    			"End date:",													//17
    			"Please enter your current password as well as the new one:",	//18
    			"Current password:",											//19
    			"New password:",												//20
    			"Repeat new password:",											//21
    };
     
     
        public String[] defaultSwedishTextMessages = new String[]{
        		textFrameSwedish,
    			"Välkommen till Inda Support Login!",
    			"Användare:",
    			"Ange lösenord:",
    			"Inkorrekt lösenord!",
    			"Förnamn:",
    			"Efternamn:",
    			"Lösenrd:",
    			"Upprepa lösenord:",
    			"Är du säker på att du vill avbryta?",
    			"Admin lösenord:",
    			"Ändra inställningar:",
    			"Admin funktioner:",												//12
    			"Endast admins kan skapa nya konton.",
    			"Endast admins kan ta bort konton.",
    			"Endast admins kan ändra språk.",
    			"Start datum:",
    			"Slut datum:",
    			"Var god och skriv in ditt nuvarande lösenord samt ditt nya:",
    			"Nuvarande lösenord:",
    			"Nytt lösenord:",
    			"Upprepa nytt lösenord:",
    };
     
        public String[] defaultMixedTextMessages = new String[]{
    			textFrameSwedish,
        		"Welcome to Inda Support Login!",
    			"Users:",
    			"Enter password",
    			"Incorrect password",
    			"First name:",
    			"Last name:",
    			"Password:",
    			"Repeat password:",
    			"Are you sure you wish to cancel?",
    			"Admin password:",
    			"Toggle setting:",
    			"Admin functions:",												//12
    			"Only admins can create new accounts.",
    			"Only admins can terminate accounts.",
    			"Only admins can change language.",
    			"Start date:",
    			"End date:",
    			"Please enter your current password as well as the new one:",
    			"Current password:",
    			"New password:",
    			"Repeat new password:",
    };
     
        public String[] englishMessages = new String[500];
        public String[] swedishMessages = new String[500];
        public String[] mixedMessages = new String[500];
        public String[] shownMessages 	= new String[500];
     
        public int numberOfImagesUsed = defaultPaths.length;
        public int numberOfTextMessagesUsed = defaultEnglishTextMessages.length;
     
     
        URL imgURL[] = new URL[numberOfImagesUsed];
        URL imgURLPressed[] = new URL[numberOfImagesUsed];
        URL imgURLRollover[] = new URL[numberOfImagesUsed];
     
     
     
        public int[] imageSizeX = new int[5000];
        public int[] defaultImageSizeX = new int[]{ 225, // 00 Logo
    		    									188, // 01 Exit button
    		    									188, // 02 create user button
    		    									188, // 03 terminate user button
    		    									188, // 04 admin button
    		    									188, // 05 login button
    		    									188, // 06 logout button
    		    									30,  // 07 logged in button
    		    									30,  // 08 logged out button
    		    									112,  // 09 change password button
    		    									112,  // 10 change interface button
    		    									30,  // 11 checkbox checked button
    		    									30,  // 12 checkbox unckecked button
    		    									188, // 13 confirm button
    		    									188, // 14 cancel button
    		    									78,  // 15 miniconfirm button
    		    									78,  // 16 minicancel button
    		    									100, // 17 print button
    		    									30,  // 18 info button
    		    									78,  // 19 default button
    		    									30,  // 20 swedish button
    		    									30  // 21 english button
    		    									}; 
     
        public int[] imageSizeY = new int[5000];
        public int[] defaultImageSizeY = new int[]{ 78,  // 00 Logo
    		    									68,  // 01 Exit button
    		    									68,  // 02 create user button
    		    									68,  // 03 terminate user button
    		    									68,  // 04 admin button
    		    									68,  // 05 login button
    		    									68,  // 06 logout button
    		    									30,  // 07 logged in button
    		    									30,  // 08 logged out button
    		    									97,  // 09 change password button
    		    									97,  // 10 change interface button
    		    									30,  // 11 checkbox checked button
    		    									30,  // 12 checkbox unckecked button
    		    									68,  // 13 confirm button
    		    									68,  // 14 cancel button
    		    									48,  // 15 miniconfirm button
    		    									48,  // 16 minicancel button
    		    									80,  // 17 print button
    		    									30,  // 18 info button
    		    									48,  // 19 default button
    		    									30,  //20 swedish button
    		    									30  // 21 english button
    		    									}; 
     
     
     
     
     
     
        public ImageIcon[] imageIcons = new ImageIcon[500];
        public ImageIcon[] imageIconsRollover = new ImageIcon[500];
        public ImageIcon[] imageIconsPressed = new ImageIcon[500];
     
     
     
        public Data(MainFrame main)
        {
        	mainFrame = main;
        	updateData();
        }
     
        public void updateData()
    	{
     
        		String temp = "";
     
            	try {
        	        for(int i = 0; i < numberOfImagesUsed; i++)
        	    	{
        	        	if(imgURL[i] == null)
        				{
        	        		imgURL[i] = Data.class.getResource(defaultPaths[i]);
        				}
     
        	        	if(imgURLRollover[i] == null)
        				{
        	        		imgURLRollover[i] = Data.class.getResource(defaultPathsRollover[i]);
        				}
     
        	        	if(imgURLPressed[i] == null)
        				{
        	        		imgURLPressed[i] = Data.class.getResource(defaultPathsPressed[i]);
        	        		//JOptionPane.showMessageDialog(null,imgURLPressed[i]);
        				}
     
        	        	if(imageSizeX[i] == 0)
        	        	{
        	        		imageSizeX[i] = defaultImageSizeX[i];
        	        	}
     
        	        	if(imageSizeY[i] == 0)
        	        	{
        	        		imageSizeY[i] = defaultImageSizeY[i];
        	        	}
        	        	temp = temp + i + imgURL[i] + "\n";
     
        	        		Image oldImage = ImageIO.read(imgURL[i]);
        					Image newImage = oldImage.getScaledInstance(imageSizeX[i], imageSizeY[i],  java.awt.Image.SCALE_SMOOTH);  
     
        					imageIcons[i] = new ImageIcon();
        					imageIcons[i].setImage(newImage);
     
        		           	oldImage = ImageIO.read(imgURLRollover[i]);
        		           	newImage = oldImage.getScaledInstance(imageSizeX[i], imageSizeY[i],  java.awt.Image.SCALE_SMOOTH);  
     
        		           	imageIconsRollover[i] = new ImageIcon();
        					imageIconsRollover[i].setImage(newImage);
     
     
        		           	oldImage = ImageIO.read(imgURLPressed[i]);
        		           	newImage = oldImage.getScaledInstance(imageSizeX[i], imageSizeY[i],  java.awt.Image.SCALE_SMOOTH);  
     
        		           	imageIconsPressed[i] = new ImageIcon();
        					imageIconsPressed[i].setImage(newImage);
     
     
        			}
     
        	        for(int i = 0; i < numberOfTextMessagesUsed; i++)
        	        {
        	        	if(englishMessages[i] == "" || englishMessages[i] == null)
        	        	{
        	        		englishMessages[i] = defaultEnglishTextMessages[i];
        	        	}
     
        	        	if(swedishMessages[i] == "" || swedishMessages[i] == null)
        	        	{
        	        		swedishMessages[i] = defaultSwedishTextMessages[i];
        	        	}
     
        	        	if(mixedMessages[i] == "" || mixedMessages[i] == null)
        	        	{
        	        		mixedMessages[i] = defaultMixedTextMessages[i];
        	        	}
     
        	        	if(mainFrame.languageUsed == 0)
        	        	{
        	        		shownMessages[i] = englishMessages[i];
     
            	        }else if(mainFrame.languageUsed == 1)
        	        	{
        	        		shownMessages[i] = swedishMessages[i];
            	        }else if(mainFrame.languageUsed == 2)
            	        {
            	        	shownMessages[i] = mixedMessages[i];
            	        }
     
     
        	        }
        	        //JOptionPane.showMessageDialog(null,temp);
     
                } catch (IOException e) {
        			e.printStackTrace();
     
        	}
     
    	}
    }

    Edit: Ignore the "http://www.javaprogrammingforums.com/" in front of the image paths, no idea why that is added here, it's not in the code.

  9. #7
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Quote Originally Posted by Lora_91 View Post
    I tried removing all of the '/' at the start of every filepath line but still got the same result, same error. =/
    Did you understand the concept? I guess of no.
    Where are those images? In which package?
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  10. The Following User Says Thank You to andbin For This Useful Post:

    Lora_91 (February 11th, 2014)

  11. #8
    Member
    Join Date
    Oct 2013
    Posts
    78
    Thanks
    55
    Thanked 0 Times in 0 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Quote Originally Posted by andbin View Post
    Did you understand the concept? I guess of no.
    Where are those images? In which package?
    LoginSystem (Main package)
    LoginSystemSource (Source folder)
    images (Image folder)
    indaSupport.png

    Would it then perhaps be "LoginSystemSource/images/indaSupport.png"?

  12. #9
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Quote Originally Posted by Lora_91 View Post
    LoginSystem (Main package)
    LoginSystemSource (Source folder)
    images (Image folder)
    indaSupport.png
    Sorry, it's not clear. If you have used Eclipse, your project should have an "src" folder. Is your LoginSystemSource the Eclipse source folder? (it would be strange).

    If you had for example:

    ProjectName
       src
          org
             xyz
                images
                   indaSupport.png

    Then:

    URL url = AnyClass.class.getResource("/org/xyz/images/indaSupport.png");

    will work. (AnyClass in the sense that it's package is ignored since '/' is at the begin of resource specification).

    Again: did you understand the concept?
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  13. The Following User Says Thank You to andbin For This Useful Post:

    Lora_91 (February 11th, 2014)

  14. #10
    Member
    Join Date
    Oct 2013
    Posts
    78
    Thanks
    55
    Thanked 0 Times in 0 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Quote Originally Posted by andbin View Post
    Sorry, it's not clear. If you have used Eclipse, your project should have an "src" folder. Is your LoginSystemSource the Eclipse source folder? (it would be strange).
    Aye, the LoginSystemSource is the source folder.

    ProjectName
        LoginSystemSource
            images
                indaSupport.png

    The LoginSystemSource is the source folder which holds the images folder which holds the images. If we then start from the source folder it wouldn't it be "/images/indaSupport.png" which I had from the beginning? =/

  15. #11
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Quote Originally Posted by Lora_91 View Post
    If we then start from the source folder it wouldn't it be "/images/indaSupport.png" which I had from the beginning? =/
    Yes, conceptually it would be correct!

    Now .... I have a doubt: that Eclipse doesn't know how to handle those LoginSystemSource folder. May be that Eclipse doesn't copy all non-java files to the 'bin' folder and/or into the jar.

    Please, first of all verify that images are really, physically, into the jar in the appropriate location (folder).
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  16. The Following User Says Thank You to andbin For This Useful Post:

    Lora_91 (February 11th, 2014)

  17. #12
    Member
    Join Date
    Oct 2013
    Posts
    78
    Thanks
    55
    Thanked 0 Times in 0 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Aye, I opened the file in winrar and it contains the folders:
    images
        indaSupport.png
        etc
    LoginSystem
        (lots of class files)
    META-INF
        MANIFEST.MF
    Thumbs.db

  18. #13
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Quote Originally Posted by Lora_91 View Post
    images
    indaSupport.png
    etc
    [/code]
    For what I see here, a resource specification "/images/indaSupport.png" should work.
    Does it work? Or not?
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  19. The Following User Says Thank You to andbin For This Useful Post:

    Lora_91 (February 11th, 2014)

  20. #14
    Member
    Join Date
    Oct 2013
    Posts
    78
    Thanks
    55
    Thanked 0 Times in 0 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Quote Originally Posted by andbin View Post
    For what I see here, a resource specification "/images/indaSupport.png" should work.
    Does it work? Or not?
    It does not work, it's what I had from the beginning when I posted this thread. =/

    Edit:

    Odd, now it does work... both by opening it by console and double clicking it. I'm noticing some other problems with the program which is also related to filepaths, so I'm guessing I'll have to change those to URL as well. Hopefully I can do it on my own this time. ^^

    Thanks for all the help! =)

  21. #15
    Member
    Join Date
    Oct 2013
    Posts
    78
    Thanks
    55
    Thanked 0 Times in 0 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Unfortunetely I seem to be unable to solve the problem after all, it's as I said similar but not exactly the same.

    Error:
    Microsoft Windows [Version 6.2.9200]
    (c) 2012 Microsoft Corporation. All rights reserved.
     
    C:\Users\UserName>java -jar indaLogin.jar .jar
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
            at LoginSystem.MainFrame.saveUsers(MainFrame.java:1265)
            at LoginSystem.MainFrame.actionPerformed(MainFrame.java:517)
            at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
            at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
            at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
            at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
    ce)
            at java.awt.Component.processMouseEvent(Unknown Source)
            at javax.swing.JComponent.processMouseEvent(Unknown Source)
            at java.awt.Component.processEvent(Unknown Source)
            at java.awt.Container.processEvent(Unknown Source)
            at java.awt.Component.dispatchEventImpl(Unknown Source)
            at java.awt.Container.dispatchEventImpl(Unknown Source)
            at java.awt.Component.dispatchEvent(Unknown Source)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
            at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
            at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
            at java.awt.Container.dispatchEventImpl(Unknown Source)
            at java.awt.Window.dispatchEventImpl(Unknown Source)
            at java.awt.Component.dispatchEvent(Unknown Source)
            at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
            at java.awt.EventQueue.access$200(Unknown Source)
            at java.awt.EventQueue$3.run(Unknown Source)
            at java.awt.EventQueue$3.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour
    ce)
            at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour
    ce)
            at java.awt.EventQueue$4.run(Unknown Source)
            at java.awt.EventQueue$4.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour
    ce)
            at java.awt.EventQueue.dispatchEvent(Unknown Source)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
            at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
            at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
            at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
            at java.awt.EventDispatchThread.run(Unknown Source)

    It has to do with the saving and loading of data, using .txt files at the moment:

        public void saveUsers() throws IOException
        {
            int i = 0;
            boolean run = true;
            try {
                while(run == true)
                {
     
                    URL fileName = MainFrame.class.getResource("data\\members\\user_" + i + ".txt");
                    File file = new File(fileName.toString()); //Line 1265
                    if(file.exists())
                    {
                        deleteFile(fileName.toString());
                    }else
                    {
                        run = false;
                    }
                    i++;
                }
     
                i = 0;
     
                for(MemberData member : membersList)
                {
                    String fileName = "data\\members\\user_" + i + ".txt";
                    String fileData = member.firstname + System.getProperty("line.separator") + member.lastname + System.getProperty("line.separator") + String.valueOf(member.password);
     
                    FileWriter saveFile = new FileWriter(fileName);
     
                    if(member.online == true)
                    {
                        date = new Date();
                        member.logOutDates(date);
     
                    }
     
                    int dateLoop = 0;
                    boolean dateRunning = true;
                    while(dateRunning == true)
                    {
                        if(member.logindates[dateLoop] == null)
                        {
                            fileData = fileData + System.getProperty("line.separator") + "muffin";
                            dateRunning = false;
                        }else
                        {
                            fileData = fileData + System.getProperty("line.separator") + member.logindates[dateLoop];
                        }
                        dateLoop++;
                    } 
                    dateLoop = 0;
                    dateRunning = true;
                    while(dateRunning == true)
                    {
                        if(member.logoutdates[dateLoop] == null)
                        {
                            fileData = fileData + System.getProperty("line.separator") + "muffin";
                            dateRunning = false;
                        }else
                        {
                            fileData = fileData + System.getProperty("line.separator") + member.logoutdates[dateLoop];
                        }
                        dateLoop++;
                    }
                    saveFile.write("exists" + System.getProperty("line.separator") + fileData);        
                    saveFile.close();
                i++;
                }
     
            } catch (IOException e) {
     
                e.printStackTrace();
            }
        }
        public void loadUsers() throws IOException
        {
        	Data.updateData();
            int i = 0;
            boolean running = true;
            while(running == true)
            {
                String filePath = "data\\members\\user_" + i + ".txt";
                File f = new File(filePath);
     
                if(f.exists())
                {
                    BufferedReader loadFile = new BufferedReader(new FileReader(filePath));
                    String check = loadFile.readLine();
                    if(check.equals("exists"))
                    {
                        String firstName = loadFile.readLine();
                        String lastName = loadFile.readLine();
                        char[] passWord = loadFile.readLine().toCharArray();
     
                        createUser(firstName, lastName, passWord);
     
                        //***********************************************************************************************************
                        boolean dateRunning = true;
                        while(dateRunning == true)
                        {
                            check = "";
                            check = loadFile.readLine();
                            if(check == null)
                            {
                                dateRunning = false;
                            }else
                            {
                                if(check.equals("muffin"))
                                {
                                    dateRunning = false;
                                }else
                                {
                                    SimpleDateFormat formatter = new SimpleDateFormat("EEEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);
     
     
                                    try
                                    {
                                        //membersList.get(i).logindates[dateInt] = formatter.parse(check);
                                        membersList.get(i).logInDates(formatter.parse(check));
                                    } catch(ParseException e)
                                    {
                                        e.printStackTrace();
                                    }
     
                                }
                            }
                        }
     
                        dateRunning = true;
                        while(dateRunning == true)
                        {
                            check = "";
                            check = loadFile.readLine();
     
                            if(check == null)
                            {
                                dateRunning = false;
                            }else
                            {
                                if(check.equals("muffin"))
                                {
                                    dateRunning = false;
                                }else
                                {
                                    SimpleDateFormat formatter = new SimpleDateFormat("EEEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);
     
                                    try
                                    {
                                        //membersList.get(i).logoutdates[dateInt] = formatter.parse(check);
                                        membersList.get(i).logOutDates(formatter.parse(check));
                                    } catch(ParseException e)
                                    {
                                        e.printStackTrace();
                                    }
                                }
                            }
                        }   
                      //***********************************************************************************************************
                    }else
                    {
                        running = false;
                    }
                    loadFile.close();
                }else
                {
                    running = false;
                }
                i++;
            }
        }

    I marked the line 1265 with "Line 1265".

    I'm assuming that I'm not supposed to use the toString() but using the relative URL gives the error of: "the constructor File(URL) is undefined" and it asks me to change the fileName back into a String.

    The jar file currently looks like this when I open it in winrar:
    data
        members
            user_0.txt
            etc
        adminData.txt
    images
    LoginSystem
    META-INF
    Thumbs.db

    So the folder is where it should be, and it contains all of the information that is to be extracted as well.

    The current error is from trying to load the data, but I noticed when successfully running the program that it seems to be unable to save the data into the .txt file as well. All of this worked fine in Eclipse, so it must be as before, related to the URL referencing somehow.

  22. #16
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Quote Originally Posted by Lora_91 View Post
                    URL fileName = MainFrame.class.getResource("data\\members\\user_" + i + ".txt");
    First, you must use '/' as separator. That is not a "pathname" on file-system .... it's a resource specification! It's a different, more specific, thing. Javadoc documentation precisely states this.
    Second, since the specification doesn't start with '/', the "data" is relative to the package of MainFrame, and I suppose it's not what you want.

    Quote Originally Posted by Lora_91 View Post
                    File file = new File(fileName.toString()); //Line 1265
    Second, you must not try to get a File from that URL, it's a URL in a special format and it would be meaningless to treat a "resource" as a File.

    Quote Originally Posted by Lora_91 View Post
                        deleteFile(fileName.toString());
    Third, if you are trying/hoping to delete a resource into the jar .... it's not correct. You can't do this easily and you should not!


    Again (sorry): did you understand the concepts on "resources" using getResource/getResourceAsStream ?
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  23. The Following User Says Thank You to andbin For This Useful Post:

    Lora_91 (February 11th, 2014)

  24. #17
    Member
    Join Date
    Oct 2013
    Posts
    78
    Thanks
    55
    Thanked 0 Times in 0 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Quote Originally Posted by andbin View Post
    First, you must use '/' as separator. That is not a "pathname" on file-system .... it's a resource specification! It's a different, more specific, thing. Javadoc documentation precisely states this.
    Would this be more accurate?
    URL fileName = MainFrame.class.getResource("/data/members/user_" + i + ".txt");

    When used within Eclipse it wouldn't work unless I used "\\" between them for the creation of the .txt file. =/


    Quote Originally Posted by andbin View Post
    Second, since the specification doesn't start with '/', the "data" is relative to the package of MainFrame, and I suppose it's not what you want.
    I'm not quite sure I understand what you mean, will the path needed change depending on where the MainFrame is?

    Quote Originally Posted by andbin View Post
    Second, you must not try to get a File from that URL, it's a URL in a special format and it would be meaningless to treat a "resource" as a File.
    Then what should I use to point to the file if neither String as a filepath nor a URL works? =/


    Quote Originally Posted by andbin View Post
    Third, if you are trying/hoping to delete a resource into the jar .... it's not correct. You can't do this easily and you should not!
    I'm trying to delete the .txt files. Whenever the program saves all of the user information, it deletes all of the currently existing user.txt files and creates new ones in accordance to the local memory it currently has. It's to prevent the program from loading any previously existing users which has been supposedly deleted from the local memory. It works flawlessly within Eclipse. =/


    Quote Originally Posted by andbin View Post
    Again (sorry): did you understand the concepts on "resources" using getResource/getResourceAsStream ?
    I'm afraid not.

  25. #18
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Quote Originally Posted by Lora_91 View Post
    URL fileName = MainFrame.class.getResource("/data/members/user_" + i + ".txt");
    This is technically correct, for what I see here.

    Quote Originally Posted by Lora_91 View Post
    When used within Eclipse it wouldn't work unless I used "\\" between them for the creation of the .txt file. =/
    If you mean the creation/write of a file on the local file-system .... it's another thing. It has no (direct) relation to "resources".


    Quote Originally Posted by Lora_91 View Post
    I'm not quite sure I understand what you mean, will the path needed change depending on where the MainFrame is?
    You have a class, say, org.sample.MainFrame (this is the fully qualified name with packages)

    If you use MainFrame.class.getResource("/data/something.txt")
    then a resource data/something.txt is searched along the classpath (where "data" is at the root).
    (the package of MainFrame is ignored)

    If you use MainFrame.class.getResource("data/something.txt")
    then a resource org/sample/data/something.txt is searched along the classpath (where "org" is at the root).
    (the package of MainFrame is used)
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  26. The Following User Says Thank You to andbin For This Useful Post:

    Lora_91 (February 11th, 2014)

  27. #19
    Member
    Join Date
    Oct 2013
    Posts
    78
    Thanks
    55
    Thanked 0 Times in 0 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Quote Originally Posted by andbin View Post
    If you mean the creation/write of a file on the local file-system .... it's another thing. It has no (direct) relation to "resources".
    It confuses me as how to it can work so well in Eclipse but not outside of it, I have no idea how else to do it.

    With:

        public void saveAdminData() throws IOException
        {
            try
            {
                String fileName = "/data/adminData.txt";
     
                FileWriter saveFile = new FileWriter(fileName);

    I receive:
    java.io.FileNotFoundException: \data\adminData.txt (The system cannot find the path specified)



    Quote Originally Posted by andbin View Post
    You have a class, say, org.sample.MainFrame (this is the fully qualified name with packages)

    If you use MainFrame.class.getResource("/data/something.txt")
    then a resource data/something.txt is searched along the classpath (where "data" is at the root).
    (the package of MainFrame is ignored)

    If you use MainFrame.class.getResource("data/something.txt")
    then a resource org/sample/data/something.txt is searched along the classpath (where "org" is at the root).
    (the package of MainFrame is used)
    Alright, that seems to make sense.

  28. #20
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Quote Originally Posted by Lora_91 View Post
                String fileName = "/data/adminData.txt";
     
                FileWriter saveFile = new FileWriter(fileName);
    This is a pathname on the local file-system (and it has nothing to do with "resources" into the jar). And it's an absolute path. On Windows it is resolved to e.g. C:\data\adminData.txt (or what is the current drive, I don't know).

    And again, I guess it's not what you want.
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  29. The Following User Says Thank You to andbin For This Useful Post:

    Lora_91 (February 11th, 2014)

  30. #21
    Member
    Join Date
    Oct 2013
    Posts
    78
    Thanks
    55
    Thanked 0 Times in 0 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Quote Originally Posted by andbin View Post
    This is a pathname on the local file-system (and it has nothing to do with "resources" into the jar). And it's an absolute path. On Windows it is resolved to e.g. C:\data\adminData.txt (or what is the current drive, I don't know).

    And again, I guess it's not what you want.
    No, I want it to refer to within the .jar file, same place the .txt can currently be found when it was extracted together with the rest of the project.

    indaLogin.jar
        Data
            adminData.txt //(wish to refer the adminData.txt here)
            members
                user_0.txt //(and the users to here)
                etc
        images
        LoginSystem
        META-INF
        Thumbs.db

  31. #22
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Quote Originally Posted by Lora_91 View Post
    No, I want it to refer to within the .jar file, same place the .txt can currently be found when it was extracted together with the rest of the project.
    "Resources" (in the sense intended by getResource/getResourceAsStream) are read-only. There's no equivalent to write a resource!

    And, in general, you should not try to update the content of a jar. A Java Virtual Machine may put a lock on the jar, so in that situation it's not even possible to touch the jar.

    If you are thinking to update at runtime the content of the jar of your application ..... your approach is wrong. Point. That's all.
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  32. The Following User Says Thank You to andbin For This Useful Post:

    Lora_91 (February 11th, 2014)

  33. #23
    Member
    Join Date
    Oct 2013
    Posts
    78
    Thanks
    55
    Thanked 0 Times in 0 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Then how should I go about saving and storing information? Would it work if the .jar file is in a specific folder and the .txt files is in the same folder and use that folder as root?

    Something like:
    SomeFolder
        indaLogin.jar
        Data
            adminData.txt
            members
                user_0.txt

  34. #24
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Quote Originally Posted by Lora_91 View Post
    Then how should I go about saving and storing information?
    Everywhere you want, outside the jar. Obviously in a location that is appropriate/reasonable.
    You can use a "known" location, for example under the "home" directory of the user. It's easily obtainable from a system-property.

    Instead, if you use e.g.:

    ..... new FileWriter("data/something.txt")

    (note no '/' at the beginning) the "data" is relative to the "current" directory. What is the current directory in your case? It depends on how/from where you launch the application! If you can control/assure that the current directory is always that where there is the jar .... then it's ok.

    If you want to get programmatically the directory of the jar ..... there's no direct/easy way (but see the following).

    If YourClass is a class into your jar and the jar is on the local file-system, the following should technically work:

    URL jarUrl = YourClass.class.getProtectionDomain().getCodeSource().getLocation();
    File jarFile = new File(jarUrl.toURI());
    File jarDir = jarFile.getParentFile();   // Directory of the jar
    But I never used a similar approach in a "real" application.
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  35. The Following User Says Thank You to andbin For This Useful Post:

    Lora_91 (February 11th, 2014)

  36. #25
    Member
    Join Date
    Oct 2013
    Posts
    78
    Thanks
    55
    Thanked 0 Times in 0 Posts

    Default Re: Extracting Eclipse project as runnable java isn't working

    Sorry for the late reply, but it's finally working thanks to all of your help, so I believe you are worthy of a big thank you! =)

Similar Threads

  1. Eclipse - Extracting dependencies into jar
    By aussiemcgr in forum Java IDEs
    Replies: 6
    Last Post: September 11th, 2013, 03:45 PM
  2. Why isn't my collision working?
    By dan0194 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 5th, 2013, 01:57 AM
  3. [SOLVED] I can't figure out why this isn't working!
    By samjoyboy in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 16th, 2012, 04:04 PM
  4. Code is working in Eclipse but when exported to Runnable Jar doesn't work
    By jjain.jitendra@gmail.com in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 24th, 2011, 07:12 AM
  5. Why isn't this working?
    By javapenguin in forum What's Wrong With My Code?
    Replies: 14
    Last Post: January 21st, 2011, 04:08 PM