Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (581)
Games in Android Showcase (163)
games submitted by our members
Games in WIP (632)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How do you manage your resusable code and get it into jar files?  (Read 3054 times)
0 Members and 1 Guest are viewing this topic.
Offline Dream Of Sleeping
« Posted 2012-04-17 18:05:33 »

Hi again.

I just tried to create a jar file in netbeans, and it didn't work right. I extracted the jar and realized it only had the class files from that project and not the class files from the projects I imported.

I have a library called javaLibrary1 (which was the default name), and in it I have two packages, njc.usefulstuff, and The game package is like my game engine. It has my input class and and Stage and Scene classes (names stolen from pulpcore!)

So when I make an applet, I have to make another project and import these libraries. It seems that project and library are the same thing in netbeans. But as I said when I used the clean and build main project option, it built a jar file without these classes so it didn't work.

I have googled the problem, and most of the people who were taking about it new a lot more about paths and jar files then I do so I couldn't really follow it. But what am I supposd to do? It seems stange to me that Netbeans wouldn't just add all the class files that you were using.

Am I wrong to have these in different projects/libraries? Should I just have everything in the same library? How do you manage your resusable code and get it into jar files? Whether it be netbeans or eclipse?

Offline UprightPath
« Reply #1 - Posted 2012-04-17 18:52:53 »

If you click on the file navigator, then right click on the build.xml, it'll give you several different build options. If one of these does not work for you, look at Package-for-store. You'll learn a bit about ant at the same time.

Offline Dream Of Sleeping
« Reply #2 - Posted 2012-04-17 19:43:28 »

Thanks. I right clicked the file although I don't know what any of the options mean.

There is never just an easy way to do something is there? I don't understand the point of making a jar file if it can't run anywhere. I read through the netbeans documentation, and it says to package the jar file and the external libraries in a zip folder. I just want all my classes in one jar so I can upload it to a website as an applet (which i still have to learn how to do)

Seriously I would love to know what the users of this forum do with their resusable code. Do you just copy and paste it into the project? I'm thinking about copying all the files deleting the package import statements, and just doing it with with the command prompt.  

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline UprightPath
« Reply #3 - Posted 2012-04-17 20:00:49 »

What I do is really what I just told you.

I have a NetBeans project that contains all of my custom classes for handling multi-dimensional arrays, hex maps, and the like. I link it in Netbeans using the 'Add project' command. Then, I use the 'Package-for-Store' command to build my Jars.

The reason that it does not automatically package everything is that you technically have to have permission to include the other jars into your project, and ant (The thing that builds your .jar) doesn't know, unless you explicitly tell it, that you have permission to do so. Many .jars out there have license requirements that do not allow it to be repackaged into another .jar file, which is why there are a lot of distribution issues.

What you could do, is build your jar file, then in the same directory include a /lib/ file with all of the .jars of the libraries you need to run it.

Offline sproingie

JGO Kernel

Medals: 202

« Reply #4 - Posted 2012-04-17 20:02:36 »

I thought Eclipse had a "runnable jar" export thing that did make fat jars.  It doesn't look very flexible though, and I doubt it deals properly with natives, so I'd look at some other tool for serious deployments.

An applet doesn't need all its library dependencies packed into a single jar.  You just separate each jar with commas in the archive attribute of the applet tag.
Offline GustavXIII

Junior Devvie

Projects: 1

« Reply #5 - Posted 2012-04-18 09:57:10 »

Yes I need that too, I use Slick and it has natives so I have some problems making a jar -.-"
I did it some time ago took me 6-8 hours I had to use Manifest and a .bat -.-
Offline kappa
« League of Dukes »

JGO Kernel

Medals: 85
Projects: 15


« Reply #6 - Posted 2012-04-18 10:06:15 »

Yes I need that too, I use Slick and it has natives so I have some problems making a jar -.-"
I did it some time ago took me 6-8 hours I had to use Manifest and a .bat -.-
You could try JarSplice, there are instructions on how to use it here and on various places on the Slick2D forums, or if you prefer a video tutorial here and here.
Offline Dream Of Sleeping
« Reply #7 - Posted 2012-04-18 10:44:47 »

What you could do, is build your jar file, then in the same directory include a /lib/ file with all of the .jars of the libraries you need to run it.

I'm trying to get it working this way first.

I started a new project, and imported the libraries I needed and built it. It made a jar file and in the same place as the jar file there is a folder called lib which contains jar files of the two libraries I use.

Yet despite the lib folder being in the same place as the jar file it still doesn't work. Nothing happens at all. If I alter the code so it contains no mentions of the other libraries, and build again the jar file works. Although it's then just an empty JFrame and nothing more. Any idea of why that is? I think I followed the netbeans tutorial to the letter. It does work if I just run it in the IDE.

As for the way you do things. There is no package to store command that I can see. Did you have to alter your projects ant file to have that option? I googled package to store and found this tutorial which does alter the ant file. I think I need to at least get the simpler way working first though.

I'm really starting to get frustrated now. I've been at this all morning. I'm dying to show everyone my game. lol

Thanks for your help. I know it can be as frustrating trying to explain these things as it is to understand them.

Offline Dream Of Sleeping
« Reply #8 - Posted 2012-04-18 11:25:37 »

I realized I could copy and paste packages. So I just copied all the packages in my main project. It ran in the IDE but guess what? You will seriously never guess! IT DIDN'T WORK IN THE JAR FILE! Aghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh!


So there must be other reasons why it wouldnt work in the jar file rather than just imported libraries. I use images but I read them like this

 BufferedImage im = URL(imageUrl, fileName)); 

Which I believe should work inside a jar file.

I load sounds like this..

AudioInputStream stream = AudioSystem.getAudioInputStream(
                    getClass().getResource("/sounds/" + name + ".wav"));

Which I thought should be ok inside jar file.  I just don't know what could be wrong and I don't think I will ever figure it out.  You are all just going to have to come over to my house to play my game!

Offline Dream Of Sleeping
« Reply #9 - Posted 2012-04-18 13:38:46 »

Well I've narrowed it down to exactly what the problem is. But I still need help.

It is definitely loading images which is the problem. When the loadImages method is commented out and everything after it, the jar file runs. To make things simpler I am now just trying to load one image.

BufferedImage im ="/images//n0.png"));

This runs in netbeans. It does not run when in the jar. As far as I know that forward slash means search from the root, so why does it not find it in the jar? I have a src folder, inside that folder is my images folder along with the three packages I use. I extracted the jar and everything is inside it that needs to be.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online Stranger

Senior Devvie

Medals: 9

I'm going slightly mad. It finally happened.

« Reply #10 - Posted 2012-04-18 14:20:33 »

BufferedImage im ="/images//n0.png"));

I have a src folder, inside that folder is my images folder

Does it mean that you actually have path "/src/images//n0.png" in your jar?

Offline Dream Of Sleeping
« Reply #11 - Posted 2012-04-18 14:44:16 »

I'm getting crazy confused now. I don't have src/ part of the path name.

Here is a photo. I extracted the jar file and this is what came out.  The njc folder is a package, actually that folder contains two packages. The arithbequickgame is a package, and so is arithtest. Arithtest is what is calling the loadImage method. Althought what I actually want to do is use my imageLoader class that is in my njc.usefulstuff package, to load images. I'm not sure what path name to give it so it works in the jar file.

Offline sproingie

JGO Kernel

Medals: 202

« Reply #12 - Posted 2012-04-18 15:34:52 »

The double-slash in "/images//n0.png" could be a problem.  What happens if you replace it with a single slash?
Offline Dream Of Sleeping
« Reply #13 - Posted 2012-04-18 16:04:28 »

Thanks I was never sure if it was double or single. I will stick to single slashes from now on.

I now know what the problem was. It was my ImageLoader class.  For one thing I had copied one version to the package yet I was still importing the old one, so my changes were making no difference! Also it was the reading of the txt file with the image names which was the real problem. Now I just pass the names in varargs array. I'll look back into that later. At least the the thing works as a jar file. I did have to copy and paste the package so it was in the same project, but that's easy enough to do.

I find programming so relaxing, yet this kind of thing I find so stressfull, I was about ready to walk away from it all. lol

I think it might be worth me learning all about ANT.

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

MrMapcom (24 views)
2015-05-23 20:26:16

MrMapcom (31 views)
2015-05-23 20:23:34

Waterwolf (36 views)
2015-05-20 15:01:45

chrislo27 (44 views)
2015-05-20 03:42:21

BurntPizza (77 views)
2015-05-10 15:53:18

FrozenShade (61 views)
2015-05-07 09:11:21

TheLopais (226 views)
2015-05-06 13:36:48

TheLopais (207 views)
2015-05-06 13:35:14

TheLopais (213 views)
2015-05-06 13:33:39

TheLopais (234 views)
2015-05-06 13:32:48
List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!