Results 1 to 7 of 7
  1. #1
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    2

    Default Jar cant recognize files in sub folders

    Java FX Code:
    package ask;
    import java.io.File;
    import javafx.application.Application;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.media.Media;
    import javafx.scene.media.MediaPlayer;
    import javafx.scene.media.MediaView;
    import javafx.stage.Stage;
    
    public class Sources extends Application {
    			
    	public static void main(String[] args) {
    		launch(args);
    	}
    	
    
    	@Override
    	public void start(Stage primaryStage) 
    	{
    		Group gameWorld = new Group ();	
    																			
    		Media media = new Media(new File("src/lietuv.mp4").toURI().toString());
    		
    		MediaPlayer mediaPlayer = new MediaPlayer(media);
    		mediaPlayer.setAutoPlay(true);
    		mediaPlayer.setCycleCount(100);
    		
    		MediaView mediaView = new MediaView(mediaPlayer);
    		mediaView.setTranslateX(300);
    		mediaView.setTranslateY(250);
    		mediaView.setFitHeight(150);
    		mediaPlayer.play();
    			
    
    		gameWorld.getChildren().add( mediaView);
    		
    		Scene scene = new Scene( gameWorld, 900, 700);
    		
    		primaryStage.setScene(scene);
    		primaryStage.show();	
    	}
    
    
    }
    I prefer to add mp4, text, png files in side 'src' folder or even deeper sub-folder.
    The thing is:
    Jar finds and run files, who is placed nearby jar ( same directory).
    Jar will not find files, who is placed inside jar ( exmaple src or other sub folder ).
    Why it is and how to solve?
    media.bmp

  2. #2
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    2

    Default Re: Jar cant recognize files in sub folders

    In short: I want "wrap" files inside project. So the files could not be moved/modified/access'ed by other users.

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,960
    Rep Power
    31

    Default Re: Jar cant recognize files in sub folders

    Look at using the Class class's getResource and getResourceAsStream methods for accessing files inside of a jar file.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    2

    Default Re: Jar cant recognize files in sub folders

    I dont get it to works.

    Java FX Code:
    InputStream in = getClass().getResourceAsStream("src/lietuv.mp4");         
    Media media = new Media( in );
    
    MediaPlayer mediaPlayer = new MediaPlayer(media);
    There is problem with Media parameter, it says 'The constructor Media(InputStream) is undefined'.

  5. #5
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    2

    Default Re: Jar cant recognize files in sub folders

    Actually found.
    Java FX Code:
    import java.net.URISyntaxException;
    import javafx.application.Application;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.media.Media;
    import javafx.scene.media.MediaPlayer;
    import javafx.scene.media.MediaView;
    import javafx.stage.Stage;
     
    public class Sources extends Application {
                 
        public static void main(String[] args) {
            launch(args);
        }
         
     
        @Override
        public void start(Stage primaryStage) throws URISyntaxException 
        {
            Group gameWorld = new Group (); 
                                                      
            Media media = new Media( Sources.class.getResource("lietuv.mp4").toURI().toString() );
             
            MediaPlayer mediaPlayer = new MediaPlayer(media);
            mediaPlayer.setAutoPlay(true);
            mediaPlayer.setCycleCount(100);
             
            MediaView mediaView = new MediaView(mediaPlayer);
            mediaView.setTranslateX(300);
            mediaView.setTranslateY(250);
            mediaView.setFitHeight(150);
            mediaPlayer.play();
                 
     
            gameWorld.getChildren().add( mediaView);
             
            Scene scene = new Scene( gameWorld, 900, 700);
             
            primaryStage.setScene(scene);
            primaryStage.show();    
        }
     
    
    }
    Jar cant recognize files in sub folders-exmaple.jpg

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,960
    Rep Power
    31

    Default Re: Jar cant recognize files in sub folders

    The constructor Media(InputStream) is undefined'.
    You need to read the API doc for the Media class to see what arguments the Media class's constructor can take. You can't make it up.


    Actually found.
    Does it work now?
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    asdfg is offline Senior Member
    Join Date
    Nov 2016
    Posts
    163
    Rep Power
    2

    Default Re: Jar cant recognize files in sub folders

    .mp4 file must be placed in the same directory as class ( same package ). if selected option in export panel I provided, - running jar runs fine standalone. No needed external files to keep adjestic.

Similar Threads

  1. Unzip files and folders
    By Asolpdrag in forum New To Java
    Replies: 16
    Last Post: 06-29-2012, 06:38 PM
  2. Help please, Playing with folders and files.
    By paulio2 in forum New To Java
    Replies: 38
    Last Post: 11-17-2011, 02:16 PM
  3. Access files in folders and sub-folders
    By kakinyim in forum CLDC and MIDP
    Replies: 0
    Last Post: 05-18-2011, 09:29 PM
  4. how to display computer folders and files in GUI
    By nashbender in forum AWT / Swing
    Replies: 12
    Last Post: 04-22-2011, 04:28 AM
  5. Searching directories for folders and .txt files
    By XDrew574X in forum New To Java
    Replies: 1
    Last Post: 03-29-2011, 09:41 PM

Posting Permissions

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