Optimizing classes exported to an applet - java

I am relatively newbie in Java. While I was developing an applet, I made as well a library containing a series of functions to be used in a server side application.
I realized that perhaps I could shrink the jar size, by exporting only the classes, from the library, i am using inside the applet.
Is there any way to do it semi-automatic?
Some app that could point me the used classes, or something likewise...
EDIT :
Perhaps I could not express it right.
What I want to do is get which classes from this library of mine I am using for the applet.
I can do it manually, as I am doing it right now, but I would rather use a tool that would help me to create a build out of it, telling which classes I am working with, instead of a guess which I am using.
I am using eclipse, but I am aware of ant.
I am aware on how to build an applet, or a jar.
My problem is to make it more efficiently.

This greatly depends on the tool you are using for building the jar-Files. But probably those tools already have a mechanism in place to exclude classes / files from the jar-File.
A classic tool would be ant. If you are using ant, this link should provide information to you: How to exclude a directory from ant fileset, based on directories contents
If you are using a different tool, please edit your question.
On a sidenote: Are you really sure you want to use a Java Applet for a Client/Server Application. If you prefer an applet because you can distribute it easily, consider using Java Web Start.

Related

how to use java based project in firebreath plugin framework

I am trying to develop a HTML5 plugin using NPAPI and firebreath framework. The code which needs to be used, is written in java but I need to convert it into C++. The only way i know is via JNI where i need to convert each .java file into .cpp file. However there are over 200 files in my project. Is there a better way to achieve this??
Any "simple" way would be more of a c++ question than a plugin or firebreath question. My guess is that you'd be far better off just making it an applet rather than a plugin if you want it mainly in java. There is nothing that I'm aware of that will make it easy for you to do what you want to do using FireBreath or NPAPI directly.
JNI doesn't convert Java to C++, it is a technology for calling native code (such as C or C++) from Java code. It doesn't seem relevant to your problem: Either you (manually or robotically) convert all your Java to C++ (which you can then call from Firebreath), or you keep your code in Java and run an applet (with no C/C++ code involved.)
If an applet as suggested by #taxilian isn't a good choice, why not turn your Java project into an application, and have your Firebreath plugin launch that and communicate with it? Your plugin could even download and install the Java app, for example in a temp folder. One limitation: The Java code won't have any direct access to internal browser API's, the Firebreath plugin would have to make any such calls on behalf of the Java app. How hard this all is would mainly depend on the complexity and bandwidth of communication needed between the web page and the Java code.

Packaging up a project for deployment - Java

I have a Java application (a quite large one with many external .jar dependencies as well as dependencies on images) and I need to package it up so that someone can double click to run, for example. Or something easy like that.
It uses Java Persistence, so it requires a sql connection which is specified in the Persistence.xml file in the Java Project.
How can I package this up? I was thinking:
the installation process should validate that the user has MySQL installed and if not, direct them to install it
the installation process could ask the user to enter credentials for any database and then I could update the Persistence.xml at run time
These were two ideas I had...but I wasn't sure if there was a known solution to this problem. Any help would be much appreciated!
I think you should take a look at embedded database solutions, like H2. Also, you can package your application using maven's shadowing or jar plugin, having the jar-with-dependencies profile activated.
This will nicely rid you of checking for database servers running on the client machine, and also will give you the proper means of bundling the application in one nice JAR, albeit a little large.
Maven is a build ecosystem and toolset especially designed for building Java applications and executing the code -- and generally doing whatever else you can imagine that's possible to do with and to your code.
It has a rich API for developing plugins and many developers have exploited this feature. There are numerous plugins for building -- and launching -- and packaging your application as well as helping you manage your applications dependencies.
Maven's shadowing comes in the form of maven-shade-plugin, available here. What it does is that it helps you create a single JAR file from all your dependencies. Also, there is the maven-jar-plugin which offers a profile jar-with-dependencies. It is also accessible from here.
H2, on the other hand is a full-fledged RDBMS. This is the website: http://www.h2database.com/html/main.html, and here is a tutorial.
You can find information on embedding the database here:
How to embed H2 database into jar file delivered to the client?
Embedding the Java h2 database programmatically
h2 (embedded mode ) database files problem
I would also suggest you use a combination of H2/Hibernate/Spring which is a very easy setup and provides you with really rich features and an easy-to-use API.
I hope this helps you :)
Building a sophisticated installer that checks lots of dependencies, and runs on lots of different platforms (which I assume you want) is complicated.
I suggest that you look at an installer generator; see What is the best installation tool for java?
Another alternative that I've seen in a few products is to write a (non-GUI) installer or configurer in a scripting language like Perl.
I wrote an installer using ANT, but has no GUI. Also, I used Iz Pack (good option), so I think that depends on how smart do you want it to be, if you are supposed to use it, or a non-technical person, etc.

Work on application and library simultaneously?

I'm new to java programming and I would like to work on some kind of game engine / lib. Just as a hobby project / experiment. I would like to make some sort of library with classes and utility functions to be able to re-use some generic game code and then a seperate application where I would build the actual game.
I am using intelliJ as an IDE. I was wondering if I could use, change and test a library with an application at the same time and how I would do this?
There are two aspects here. The technical: How does it work? The organisational: Is it a good idea?
The technical is quite easy. You just create different projects. The application project depends on the library project. Libraries are packaged as jars typically. Easiest would be to use a tool that supports you with dependencies and different versions of the library. I would recommend Maven for this.
The second question is harder and probably belongs to https://softwareengineering.stackexchange.com/ as it is more of a philosophical kind and no definitive answer exists. In my point of view it is a bad idea to develop a library and a product at the same time. Specificals of your product will slip into the library, you will get problems with priorities.
That is, when you are developing a library that should be used or published independently of your application. Modularisation of an application is another cup of tea, but could be done with the same tools. With Maven you would setup a multi module project then.
What do you mean by a library? A JAR right, a JAR contains a set of classes, what you would do is to "use, change and test" the classes you would like to make a library and when everything is done, you package it as a JAR and there you are done! If you want the JAR to be created everytime you "build" try using Maven or Ant that does these packaging tasks for you automatically. Maven is more powerful and you would love to see that it mainly does "dependency management" and your library is the dependency for your project.

Java libraries to manage CSS explosion and or reuse?

Java Q:
I like CSS for simple web pages but loathe it when it comes to real world sites because you get css explosion and lots of repeating.
I am tempted to use Sass and or Compass but they are Ruby programs which will most likely require some interesting Maven + JRuby love to get working for Java Web app dev. This also makes it difficult if you are using Eclipse or any IDE that supports synchronization with a running web app.
Is there a better alternative for the hell that is CSS in the hell that is Java?
I went down the same road recently using LessCss, a similar technology. At first I tried to embed JRuby in my build lifecycle. But unfortunately Maven + JRuby is a monster, it's slow, huge and buggy (half the time it wouldn't even start because it would complain about the file path it was running on).
Fortunately, there is now a JavaScript port of LessCss, which I now embed via Mozilla Rhino. I describe the process in this blog post.
Yesterday though I took it to the next level, making a Maven LessCss Plugin to minimize POM configuration and code duplication. Unfortunately I can't share it because it's proprietary code for my current client, but the solution is simple:
Use GMaven to create the Plugin, create an abstract base mojo that calls the LessCss compiler and several concrete implementations that configure the base mojo for different resource sets:
e.g.
lesscss:compile compiles from all
<resources> to
${project.build.outputDirectory}
lesscss:test-compile compiles from
all <testResources> to
${project.build.testOutputDirectory}
lesscss:war-compile(compiles from
all src/main/webapp to
${project.build.directory}/${project.build.finalName}
, the exploded war directory)
So while I can't help you with SASS (apart from you asking the auth
or to port it to Groovy, Java or JavaScript), I think I've shown you a feasible alternative.
Of course you can also implement a Maven Plugin in java without Groovy (also embedding the JavaScript via Rhino), but I think it's easier in Groovy.
I ended up using wro4j.
Highly recommend the library as it will handle many things like less css and coffee CoffeeScript.
A good solution for using sass with eclipse is answered in this question.
The Sass command-line interface is very thorough. If you call out to sass --update in your build rules, you can just use the standard Sass executable (either via Ruby or JRuby) without having to integrate it directly into your build.

Matlab in a Chrome extension (via Java compiler) possible?

Is it possible to integrate a Matlab program into a Chrome extension using the Matlab Builder JA?
Essentially, I have a computational tool in Matlab that I want to make more user-friendly and widely-available for other researchers with few or no programming skills. The best way to do this seems to be deploying it on the web--and, since I don't have access to a web server, in a Chrome extension. In order to deploy Matlab on the web via Java, it seems I need to upload the JRE or JDK and do a lot of other configurations on a server, like in http://www.mathworks.com/help/javabuilder/web-deployment.html (need a Matlab account to view).
Any workarounds for the extension that don't require a web server? Or other ideas to distribute my package to non-programmers so that they can use it?
Thanks!
I was in a similar situation, and I solved it in a slightly more elegant way than trying to play with web plugins:
In order to make the functions of my package accessible to non-programmers, I built a very simple GUI using guide in matlab, which allowed users to open data files, choose processing parameters, run the analysis, and export the results. Guide is very simple to use, and there are some good tutorials online. Then in terms of distributing it, I packaged all the necessary matlab files into a single folder, and then wrote a bash script (linux/mac) that would copy the files into a sensible directory, make a shortcut in /usr/bin/ (so that the GUI could be opened directly from the command line by running scatter_analysis without invoking any other display from matlab), and finally make a double-clickable shortcut on the desktop. The only prerequisite is that the user has matlab installed already.
I presume you're using windows, which I know nothing about, but I think it's likely that you can come up with a similar solution on the windows platform with far less effort than wrestling with web plugins? Unfortunately I cannot share my code - I'm in the process of selling it and any disclosure would violate the terms of the sale.

Categories

Resources