|
-
October 23rd, 2009, 09:43 AM
#1
Videos not playing when building .jar
Hi,
I'm self taught in Java and fairly new too it. I created my first big project during this year and it's basically a library system connected to a database of books and it shows you every books cover blahblah. I also have some videos and music.
Everything works while the program is in the Netbeans builder. All videos and music etc. I've imported the java media framework jars (fobs.jar and jmf.jar) into the program libraries and thereafter all videos work fine. Problem is when I build the project and go into the dist folder, the program .jar is there and a 'lib' folder with the jars i imported.
But when running the jar, videos will not work. I get a 'no media player found exception'. Is there something I'm missing? This is the first time i've ever built a project so not sure what I'm doing wrong.
I've tried placing the jars in the same folder as the main jar, tried importing them into the main project and I've run out of ideas. Can anyone help please?
-
October 23rd, 2009, 12:18 PM
#2
Re: Videos not playing when building .jar
Your program jar will contain a manifest file and that manifest file will need to contain a classpath entry specifying the other jar files. A basic manifest file looks something like
Code:
Manifest-Version: 1.0
Main-Class: mypackage.MyProgram
Class-Path: lib/RequiredJar1.jar lib/RequiredJar2.jar
There are a lot of optional lines that can be in the manifest but you will definitely need the Main-Class and Class-Path entries. I suggest you read a tutorial such as this one
-
October 23rd, 2009, 01:20 PM
#3
Re: Videos not playing when building .jar
Thanks alot and I know this is a stupid question but how do I actually go about 'running a command from inside a directory'? What do I actually type in CMD or is there another tool I should be using?
Say I have a .jar located in my C drive and I want to view the manifest for it. How do I do this with cmd?
-
October 23rd, 2009, 01:28 PM
#4
Re: Videos not playing when building .jar
Okay nevermind worked it out.
This is the manifest for the jar:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 14.0-b16 (Sun Microsystems Inc.)
Main-Class: BookSystem.GUI
Class-Path: lib/beansbinding-1.2.1.jar lib/jmf.jar lib/fobs4jmf.jar
X-COMMENT: Main-Class will be added automatically by build
As you can see jmf.jar and fobs4jmf.jar are located within the classpath, so what's the problem!?
-
October 23rd, 2009, 06:37 PM
#5
Re: Videos not playing when building .jar
have you tried to run the jar from its working directory; this is using the windows command prompt and java -jar command?
-
October 24th, 2009, 05:36 AM
#6
Re: Videos not playing when building .jar
I tried that and videos still do not work, also it does not find the textfiles which it users which are located in the same folder as the jar.
-
October 24th, 2009, 07:05 AM
#7
Re: Videos not playing when building .jar
From your manifest file it appears that your application is in the default package ie you haven't specified a package. I've never built a jar from files which aren't in a specified package and linked in other jars and I've no reason to believe this is the cause of your problem but it may be worth specifying a package for your files and seeing if that hepls. Even if putting your files in a package doesn't sort your problem you haven't totally wasted your time as it's good practice to use packages.
-
October 24th, 2009, 07:24 AM
#8
Re: Videos not playing when building .jar
I'm not sure I understand...I have a Netbeans project and all my classes are within a specified 'Source Package'. The jmf.jar and fobs4jmf.jar are located in the 'Libraries' folder of the project. Everything is in a single project. At the top of every class I have the code
"package BookSystem;"
That's the name of the source package for all my classes.
-
October 26th, 2009, 09:59 AM
#9
Re: Videos not playing when building .jar
Sorry, I misread the manifest file.
By convention package names start with a lower case letter and I read BookSystem.GUI as BookSystemGUI.
If the jar files aren't too big attach them here and I'll test it for you.
-
November 3rd, 2009, 12:14 PM
#10
Re: Videos not playing when building .jar
Sorry, I've been away for a while.
Perhaps it is worth nothing that if i 'Clean and Build' my project in netbeans, it will crash and not be able to run after that with an error in the constructor.
If I just 'build' it, it works fine but the resulting jar will not play music/videos.
I've tried to build it manually using CMD and it's a bit confusing for me because all my classes are in a package and I can't find a tutorial that tells you how to build a jar when everything is in a package....so far I've managed to create a jar that just says 'Cannot find the main class BookSystem.GUI' when it's run. All my classes are split up into smaller parts like 'GUI$1.class' all the way to 'GUI$245.class' so don't know if that's the problem.
My main class is actually really really big, IDE says that it may be too unstable to open... I shouldn't have coded like that.
-
November 3rd, 2009, 12:57 PM
#11
Re: Videos not playing when building .jar
The numbered class files are the inner classes defined within your main class. 245 inner classes is a lot and probably indicates a bad design but I don't know of any reason why this would not work.
Just how big is the main class file?
-
November 3rd, 2009, 01:37 PM
#12
Re: Videos not playing when building .jar
1000 kbs, pushing the limit of the class size. I was taught to program this way, with one main GUI class and I think I took it a bit too far :P Check your inbox.
-
November 3rd, 2009, 01:40 PM
#13
Re: Videos not playing when building .jar
I've just looked at the PM you sent and I'm sorry but you're going to have to do a lot more than just uploading a 14.1Mb zip file if you want help.
How is anyone supposed to wade through a project that size to find a problem especially when the code isn't well formatted, doesn't conform to the java naming standards and contains very few comments.
I suggest you extract the part of the code that handles the video and when you can reproduce your problem in a small piece of code I'll have a look at it.
While you're at it I suggest you break the GUI class into logical parts 1Mb of gui code in 1 file is just not readable or I suspect maintainable. Your GUI must consist of many different panels, consider having a separate file for each panel or each logical collection of panels.
-
November 3rd, 2009, 02:04 PM
#14
Re: Videos not playing when building .jar
My code is extremely well formatted and contains a huge number of comments. Every single method, global variable and complex looping structure is commented. It is structured into logical classes and every single variable conforms to java naming standards, except the project name. There's no need to be rude by making assumptions.
I suggest you reread this thread, there is no problem with the way my coding for videos works, but rather the way that the project is built. The .jar cannot 'find' the libraries it requires to create a media player to play videos. Inside the IDE, it works completely fine. I cannot 'extract and reproduce' some simple code for you to look through, I can only ask that you look through the way the source files are structured within the project folder - not the actual code.
My GUI class is broken down into different jFrames that link together in a logical fashion. Parts of the GUI that are 'addition' (eg a music player) are in their own separate class. The reason my project is so big is due to a large number of images, the code itself is relatively small.
-
November 3rd, 2009, 06:23 PM
#15
Re: Videos not playing when building .jar
Guys, there's no point discussing project code or structure here in terms of what someone has PM'd to someone else. Either post up the project/code under discussion or discuss it via PM.
Alternatively, Martin should be able to post a minimal project that demonstrates the problem, just by removing all the irrelevant stuff. It's far easier to hack around a simple test rig project than the monster that appears to be at fault.
And, whatever you were taught, common-sense should tell you that a 100kb class file with 245 inner classes is exceptionally poor design.
A complex system that works in invariably found to have evolved from a simple system that worked...
J. Gall
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|