Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (113)
games submitted by our members
Games in WIP (563)
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  
  easily deploy JWS and applets with Scar  (Read 4420 times)
0 Members and 1 Guest are viewing this topic.
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Posted 2011-12-20 02:49:40 »

I've posted about Scar before, so I'll just give a quick summary. I hate Ant, XML programming is an abomination. I hate Maven, though I like the idea of an artifact repo but only for large projects with many dependencies. I want to build my own stuff without any nonsense. If Java could be used to build Java projects, naturally every Java programmer wouldn't have any trouble. Scar is a collection of utilities that make it easier to do build related tasks using Java code.

http://code.google.com/p/scar/

That out of the way, I recently reorganized Scar. Here are the parts:

  • The Scar class has static utility methods. They usually take some strings that point to files or directories and do something useful, like zip, unzip, compile source files, etc.
  • The Paths class comes from my wildcard project. It uses globs (asterisks) or regex to collect file paths. The globs are very efficient, eg they don't traverse into directories that can't potentially match the glob pattern. This makes collecting paths to compile, zip, etc very easy.
  • The Project class is intended to be a project descriptor. It is loaded from a YAML document and has a project directory. It has utility methods to get paths relative to the project directory and get data out of the YAML in various formats, such as strings, floats, and Paths relative to the project directory. Nothing is assumed about how you'll use the Project class, it is only a data container with utility methods. You don't have to even use it at all.
  • The Build class takes a Project instance and does Java build tasks on it. It uses conventions for the data in the Project, eg it expects the YAML to have "name" for projcet name, "source" to list Java source files, "dependencies" to list paths to dependency projects, etc. It can compile and JAR a project and all dependent projects just by reading the Project file. You don't have to use this at all, you can just make use of Scar utility methods and go your own route to build your project.

Previously, the Scar class had a bunch of stuff that is now in the Build class. Now, the Scar class isn't cluttered with that optional stuff, and all the utilities like compiling, LZMAing, etc can be used by people who don't want to bother with the Build stuff.

So, what are some examples for common tasks already!? I'm getting there! First, it is easy enough to get a directory that contains your application as a bunch of JARs. In Eclipse you can right click, export, and click runnable JAR. Now that you have that, here is how you can run your app for JWS, just create a new class with a main method and this code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
String keystore = "keystore";
String alias = "alias";
String password = "password";
String company = "Company";
String title = "Title";
String inputDir = "C:/example/jars";
String outputDir = "C:/example/jws";
Scar.keystore(keystore, alias, password, company, title);
Scar.jws(inputDir, outputDir, true, keystore, alias, password);
Scar.jnlp(outputDir, "com.example.MainClass", "name-of-jar-with-mainclass.jar",
   "http://example.com/applet/run.jnlp", company, title, "splash.jpg");


This generates a keystore file (if it doesn't exist), generates a JNLP file, and signs all your JARs to work with JWS. Put your JARs and the JNLP file on the internet and you are done!

Specifically, for each JAR it removes any previous signing, does pack200 and unpack200 to normalize the JAR, signs it with your keystore, does pack200, and then GZIP. It skips the last two steps for JARs containing "native". When generating the JNLP, it puts JARs containing "native" in the appropriate native section, based on if they contain "win", "mac", "linux", or "solaris".

Here's another example, this time to package an LWJGL applet:

1  
2  
3  
Scar.keystore(keystore, alias, password, company, title);
Scar.lwjglApplet(inputDir, outputDir, keystore, alias, password);
Scar.lwjglAppletHtml(outputDir, "com.example.MainClass");


This generates a keystore file (if it doesn't exist), generates an HTML file, and signs all your JARs to work as an LWJGL applet. Put your JARs and the HTML file on the internet and you are done!

Specifically, for each JAR it removes any previous signing, does pack200 and unpack200 to normalize the JAR, signs it with your keystore, does pack200, and then LZMA. It skips the LZMA and packing for the LWJGL JARs "lwjgl_util_applet.jar" and "lzma.jar". It skips the pack200 for JARs containing "native". When generating the HTML, it puts JARs containing "native" in the appropriate native section, based on if they contain "win", "mac", "linux", or "solaris".

Scar can do other useful stuff, like "one JAR" or FTP your files, but I think the above is particularily relevant to JGO. If you give it a try, please run Scar from source as I just refactored some things tonight and haven't released an up to date JAR. If someone could do some testing that would be great. Smiley

Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2011-12-20 06:06:59 »

Where do we find it? The link in your signature gives me a 404 :S

Offline arielsan
« Reply #2 - Posted 2011-12-20 11:52:55 »

googlecode search: Scar -> http://code.google.com/p/scar/

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

JGO Kernel


Medals: 202



« Reply #3 - Posted 2011-12-20 15:44:37 »

This business of Paths, Projects, and Builds looks somewhat inspired by SBT.  It wouldn't be a bad idea to read SBT's docs and mine it for further ideas, such as the Setting/Task concept. 

https://github.com/harrah/xsbt/wiki

You might not want to duplicate SBT's complexity (the "Simple" in "Simple Build Tool" is increasingly ironic), but you can probably drop SBT's pure functional model of key updates and make it unabashedly stateful, which I imagine would simplify things quite a bit.
Offline AurelienRibon

Senior Newbie


Medals: 3


Toolmaker, yeah.


« Reply #4 - Posted 2011-12-20 15:57:20 »

I hate ANT so much, particularly for generating a classpath string, that I'll immediately try to switch to your library for all my projects. Thanks for making this, it looks very interesting.

Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #5 - Posted 2011-12-20 19:56:28 »

This business of Paths, Projects, and Builds looks somewhat inspired by SBT.  It wouldn't be a bad idea to read SBT's docs and mine it for further ideas, such as the Setting/Task concept.  

I had not looked at SBT before. I see it is a build system for Scala written in Scala. It unsurprisingly seems very Scala like, and by that I mean really freaking complicated. Tongue I read through Settings and it's hard for me to tell if the complexity is warranted. By the time I got to the .scala build definition I was completely lost. I do see the similarities though.

Scar (the class) is really a collection of utilities for common build tasks. Project is a generic project descriptor. Build imposes conventions on Project and uses Scar (the class) to do various tasks on the project. You could just use Scar methods on their own and ignore the other isht. If you do use the Build class and it doesn't do things quite how you like, presumably you would just copy and paste and make it yours. So, rather than a complicated tool that caters to all needs, it is a simple tool that lets you get done what you need in a simple, straightforward way.

I have mixed feelings about including Java code in the project descriptor. Scar supports this, but without an IDE it isn't very convenient. Then again, writing a main method in an IDE is inconvenient for running from the command line. Possibly a file separate from and referenced by the project descriptor would easily do both.

I hate ANT so much, particularly for generating a classpath string, that I'll immediately try to switch to your library for all my projects. Thanks for making this, it looks very interesting.
Sweet! Cheesy If your project setup matches the Scar Project defaults (source in src or src/main/java, dependency JARs in lib or libs, resources in assets or resources or src/main/resources, etc) then you can just do "java -jar scar.jar" and it will compile and JAR your stuff. I just posted a new scar.jar on the Google code site. If not, you can create a project.yaml file in the project root and override the defaults. You might want a project.yaml to set a main class. Quick example:

1  
2  
3  
4  
5  
6  
7  
8  
9  
dependencies:
- ../arcanetactics
- ../appletloader
resources:
- myresources
classpath:
- lib|**/*.jar
- ../../libgdx/target/dist|gdx-backend-lwjgl.jar
main: com.example.MainClass


Or of course you can ignore the Build crap and write a main method that does your build.

Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #6 - Posted 2011-12-20 21:51:02 »

I updated the Scar documentation on the homepage.
http://code.google.com/p/scar/
I think it is clearer and easier to see how the hell one might use the project. Feedback is welcome!

Offline gimbal

JGO Knight


Medals: 25



« Reply #7 - Posted 2011-12-21 15:50:29 »

Actually I follow your way of thinking. Why NOT do your build 'scripts' in Java? The alternative is usually horrendously verbose configuration files to make the "flexible" tool adhere to your specific needs. Just use the facilities of the JDK and some standardization. Heck, your build scripts can even be easily debugged.

I am actually introducing that way of thinking into the company I work for where everyone thinks in nothing else but Oracle databases (sigh). For example today a problem arose where a file was in UTF-16 format and the Oracle loader tool couldn't work with that, it had to be UTF-8. People were discussing for 10 minutes how to fix that until I had enough: in a mere five minutes I put together a simple command line thing in Java which can take a source encoding and a destination encoding and then converts the file using only a simple inputstreamreader and a printstream. The problem was solved.

When people asked me what magic tool I used, I answered: "Java". You should have seen the blank stares, it was glorious. And 15 minutes later I had transformed it into a full user friendly Swing GUI. More blank stares.

> I hate Maven, though I like the idea of an artifact repo but only for large projects with many dependencies.

Note that for example Play Framework actually utilizes the Maven repositories for its internal dependency management, but it doesn't actually use Maven. In stead it uses a simple text file format to define the dependency groupId, artifactId and version and it has simple scripts to actually manage the dependencies. Something to think about.
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #8 - Posted 2011-12-21 19:02:21 »

> I hate Maven, though I like the idea of an artifact repo but only for large projects with many dependencies.

Note that for example Play Framework actually utilizes the Maven repositories for its internal dependency management, but it doesn't actually use Maven. In stead it uses a simple text file format to define the dependency groupId, artifactId and version and it has simple scripts to actually manage the dependencies. Something to think about.
Yeah, something like that could easily be done in Java code. The Scar project descriptor is generic, so you could just add a "mavenRepos" and "mavenDependencies" section that are lists of URLs and group/artifactid/versions. Unfortunately it isn't as simple as just downloading JARs, to make it useful it would have to download and parse the POM so it could also download dependent maven JARs, recursively. And once you are parsing POMs you would need to parse any parent POMs they inherit from, recursively. It becomes too much of a PITA for me to want to bother really. If you are using Maven, you should be punished!  Tongue

Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #9 - Posted 2011-12-21 19:27:15 »

Actually I took a minute to look into it. Apparently this...
mvn -DrepoUrl=http://blah -DgroupId=commons-io -DartifactId=commons-io -Dversion=1.4 dependency:get
...can be used to download JARs into the local repo, and dependency:copy-dependencies could be used to copy them into a directory where Scar could find them. However, don't you need these JARs for your IDE to develop your app? In that case you are probably already using Maven start to finish and you don't need Scar, or you already have a directory full of JARs and you can use Scar as normal without any Maven crap.

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

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #10 - Posted 2011-12-21 20:06:39 »

Hey Nate your sig is still broken Pointing

Offline sproingie

JGO Kernel


Medals: 202



« Reply #11 - Posted 2011-12-21 20:27:04 »

Apache Ivy can fetch from maven repos and has an actual API for it -- it's what SBT uses.  So you don't need maven installed to use maven dependencies.  Then again Ivy is also the biggest source of grumbling from SBT devs, so maybe it's not the best idea to use it.  Might want to see what tools like grape and gradle are doing and see if that's easier to work with.

Some people would like to use managed dependencies without either using maven or going back to the stone age of doing it all by hand.  If you're against the concept of managed deps, probably best to be up front about it.

Offline gimbal

JGO Knight


Medals: 25



« Reply #12 - Posted 2011-12-21 20:29:13 »

You don't need to parse any poms. You manually manage transient dependencies when you're not using Maven, you just keep doing that. As you stated earlier, the (transient) dependency management features of Maven are only really useful for large multi-module projects such as JEE applications. The point is to have a centralized point to download them from, not to mimic what Maven does. But that would actually only matter if you want to take Scar beyond the scope of game development. When your focus is game projects you will hardly ever change the libraries you use except for maybe an update of LWJGL. Would be a shame to waste time on such a feature when nobody using the tool will actually ever need it. Plus in my opinion tools should stay small, simple and to the point Smiley Why did I bring this up again?

Grr, just you wait. I'll come up with an awesome idea some day Wink
Offline sproingie

JGO Kernel


Medals: 202



« Reply #13 - Posted 2011-12-21 20:34:14 »

I don't get this attitude of "games=simplistic".  Not just simple, but simplistic, as in dumb and incapable.  I want to distribute a demo as source, and I neither want to bundle a bunch of jars with it, nor force people to chase down every dependency by hand. 

But if I want to use something like TWL, I have no choice but to bundle it, because the idea of automatic, versioned dependencies is good enough for Perl with CPAN, or Python with PyPi, but not for Java, because it's a game?  Huh.

</rant>
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #14 - Posted 2011-12-21 20:45:15 »

I could add something that takes URLs from the project descriptor and downloads the JARs. You could point it at Maven repos if you want, or at your own hosting. Worth it? It would only be a couple lines of code to add.

Sig work now? Google does something fancy with links to a user's projects...

Offline BoBear2681

JGO Coder


Medals: 18



« Reply #15 - Posted 2011-12-22 04:13:10 »

So, judging from that signature, you're just like a lot of us - spend more time writing tools than you do actual games?   Grin
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #16 - Posted 2011-12-22 04:16:45 »

Yes, of course! I'm just trying to fit in! Emo I've shipped a couple games, but I also spend tons of time on libs. I dunno, it's just more fun sometimes, probably because of the smaller scope. I have a backlog filled with "real" work, products, games, and libs. I'm trying to get some closure by finishing my (soul robbing) RTS...  Cry

Offline gimbal

JGO Knight


Medals: 25



« Reply #17 - Posted 2011-12-22 09:58:22 »

I don't get this attitude of "games=simplistic".  Not just simple, but simplistic, as in dumb and incapable.  I want to distribute a demo as source, and I neither want to bundle a bunch of jars with it, nor force people to chase down every dependency by hand.  

But if I want to use something like TWL, I have no choice but to bundle it, because the idea of automatic, versioned dependencies is good enough for Perl with CPAN, or Python with PyPi, but not for Java, because it's a game?  Huh.

</rant>


I don't get what caused this rant, nor what it is about really. I can comment about the distributing of jars: you could use one-jar to wrap everything into one.

http://one-jar.sourceforge.net/

You could even package the LWJGL natives using it apparently.


EDIT:

oops, Scar already has that built in apparently Smiley Some day!
Offline AurelienRibon

Senior Newbie


Medals: 3


Toolmaker, yeah.


« Reply #18 - Posted 2011-12-22 16:20:10 »

Beware of one-jar and lgpl libraries...
Besides that, what is the problem with shipping jar libraries with the game executable ? Every AAA title comes with a load of dll files and resources, exposing all the stuff to the user.

Offline gimbal

JGO Knight


Medals: 25



« Reply #19 - Posted 2011-12-28 12:12:46 »

Beware of one-jar and lgpl libraries...
Besides that, what is the problem with shipping jar libraries with the game executable ? Every AAA title comes with a load of dll files and resources, exposing all the stuff to the user.

Agreed, I personally have no problems with dumping all dependency libraries in a /lib subdirectory (to separate from the main executable jar to prevent confusion) and just distribute like that. Heck, I tend to keep resources (graphics, sounds, music) out of the game jar as well, makes it easier to tinker with them during development without having to rebuild.
Offline sproingie

JGO Kernel


Medals: 202



« Reply #20 - Posted 2011-12-29 02:04:04 »

AAA games are not typically distributed as source.  I think we're talking about two completely different things here, namely build systems and packagers.  A fancy packager may kick off a build, but it's not the build system.
Offline gimbal

JGO Knight


Medals: 25



« Reply #21 - Posted 2011-12-29 16:50:12 »

AAA games are not typically distributed as source.  I think we're talking about two completely different things here, namely build systems and packagers.  A fancy packager may kick off a build, but it's not the build system.


I must have missed something. Who said anything about distributing source?
Offline gouessej
« Reply #22 - Posted 2012-05-27 21:54:44 »

I don't get what caused this rant, nor what it is about really. I can comment about the distributing of jars: you could use one-jar to wrap everything into one.

http://one-jar.sourceforge.net/
WinRAR or Arch may still open your JAR instead of Java which is not what you want. Using a single JAR is a very bad idea.

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

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (16 views)
2014-09-12 09:08:26

Norakomi (50 views)
2014-09-10 13:57:51

TehJavaDev (58 views)
2014-09-10 06:39:09

Tekkerue (27 views)
2014-09-09 02:24:56

mitcheeb (50 views)
2014-09-08 06:06:29

BurntPizza (34 views)
2014-09-07 01:13:42

Longarmx (20 views)
2014-09-07 01:12:14

Longarmx (23 views)
2014-09-07 01:11:22

Longarmx (22 views)
2014-09-07 01:10:19

mitcheeb (31 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!