Java ME bundle Microlog jars with my midlet jar - java-me

I'm pretty new to Java ME and i'm trying to use Microlog to handle logging in my midlet.
In eclipse i can reference Microlog jars and it's all good in dev time,
but when i try to launch the application the jars aren't found on the device.
How can i bundle those referenced libs into my midlet?
Someone have any experience with using Microlog in a midlet?
Thanks.

The classes are not found, because they are not inside the final MIDlet suite you are trying to run run in the device. In fact, you can't add external jars directly inside your midlet jar file as J2ME class loader is much more simple than the one in desktop Java. It only loads the classes found inside the midlet jar.
So, you have to extract everything from the Microlog jar and put them into you midlet jar just like you put your own classes and other resources. Probably you can configure your build tool to do this automatically for you.
Eclipse is able to find the classes because you have added the jar into your project's classpath.

Just a little addition. If you are using Eclipse to export the midlet you are able to generate the jar-file including all the classes of the dependencies for you.
Select "Java Build Path" of your project and then "Order and Export". Make sure the microlog jar-files are checked in that list. This will bundle everything into one jar-file.
Hope this helps.

I would recommend to use ProGuard to reduce the size of the final jar. Please read this article to figure out how to do it with Microlog:
http://myossdevblog.blogspot.com/2009/06/using-proguard-to-shrink-microlog.html

Related

Can't find or load main class to make a Javafx jar in IntelliJ IDEA

I made my first Javafx Application in IntellIJ IDEA it runs perfectly but i have a problem.
I can't make an executable jar for this Application.
To be more explicit whenever i try to search for the main class i can't find it in the artifact tab.
I tried making a normal jar (in the artifacts menu they give you the choice between normal jar and javafx application jar) and the main is detected.
It's a known issue. You can type the fully qualified class name manually as the workaround (foo.bar.MyClass).

Packaging a Groovy application

I want to package a Groovy CLI application in a form that's easy to distribute, similar to what Java does with JARs. I haven't been able to find anything that seems to be able to do this. I've found a couple of things like this that are intended for one-off scripts, but nothing that can compile an entire Groovy application made up of a lot of separate Groovy files and resource data.
I don't necessarily need to have the Groovy standalone executable be a part of it (though that would be nice), and this is not a library intended to be used by other JVM languages. All I want is a simply packaged version of my application.
EDIT:
Based on the couple of responses I got, I don't think I was being clear enough on my goal. What I'm looking for is basically a archive format that Groovy can support. The goal here is to make this easier to distribute. Right now, the best way is to ZIP it up, have the user unzip it, and then modify a batch/shell file to start it. I was hoping to find a way to make this more like an executable JAR file, where the user just has to run a single file.
I know that Groovy compiles down to JVM-compatible byte-code, but I'm not trying to get this to run as Java code. I'm doing some dynamic addition of Groovy classes at runtime based on the user's configuration and Java won't be able to handle that. As I said in the original post, having the Groovy executable is included in the archive is kind of a nice-to-have. However, I do actually need Groovy to be executable that runs, not Java.
The Gradle Cookbook shows how to make a "fat jar" from a groovy project: http://wiki.gradle.org/display/GRADLE/Cookbook#Cookbook-Creatingafatjar
This bundles up all the dependencies, including groovy. The resulting jar file can be run on the command line like:
java -jar myapp.jar
I've had a lot of success using a combination of the eclipse Fat Jar plugin and Yet Another Java Service Wrapper.
Essentially this becomes a 'Java' problem not a groovy problem. Fat Jar is painless to use. It might take you a couple of tries to get your single jar right, but once all the dependencies are flattened into a single jar you are now off an running it at the command line with
java -jar application.jar
I then wrap these jars as a service. I often develop standalone groovy based services that perform some task. I set it up as a service on Windows server using Yet Another Java Service and schedule it using various techniques to interact with Windows services.

Liferay - Share Utils class between 2 different portlets

I'm developing a Liferay application, consisting on 2 different portlets, an both have to make certain operations in common, so I decided to put that operations in static methods in an external Utils class.
I have to externalize that class to avoid duplicating the same code in both portlets, and I want to have the portlets in different WAR files.
I know I can package the Utils class in a JAR file, but we are still developing and we don't want to regenerate the JAR and restart the Tomcat for every change.
Which is the best option and how can I perform it?
If you're using the Liferay SDK, you can use the clients (recently changed to shared) directory to put your common code.
A good example is how deploy-listener-shared is used in conjunction with deploy-listener-hook.
From what it looks like, all the configuration you need to do is to modify your build.xml files that will use the client\shared classes. If you look at build file of deploy-listener-hook you can see all you need to add is the.
For the new SDK:
<property name="import.shared" value="my-utils-shared" />
For the older SDK:
<property name="dependent.clients" value="my-utils-client" />
Hope this helps!
There is another method that involves building a JAR file but it doesn't require a server restart (on Tomcat at least).
Write a build script for your JAR file so it compiles, builds the JAR and finally copies it to the following location:
{tomcat}/webapps/ROOT/WEB-INF/lib
Then in your portlet open the "liferay-plugin-package.properties" (in Liferay Developer Studio / Liferay IDE this should open with a nice GUI).
Then add the name of your JAR to the "portal-dependency-jars" list in this file so in the source it would like (Or just hit the "Add" button in the GUI and select the JARs you want):
portal-dependency-jars=my-custom-lib.jar,my-other-custom-lib.jar
Save the file, and redeploy the portlet, and the JAR will be copied across when the portlet is deployed.
I've used this method for custom JARs, and 3rd party JARs that I've needed to use in my portlets.
For the development phase just package the jar file with both applications.
Unless one application depends on the other somehow it is completely ok.
Another solution is to use JRebel tool. It will allow you to redeploy jar in tomcat without restarting.
Also you may have several portlets in one .war. You may just define them both in portlet.xml.

How can I get external jars added to the classpath of a executable jar created by GroovyWrapper

I have a simple groovy script that executes some sql and plays with the results. It runs quite happily from Eclipse when I add the SQL Server jar to the classpath. However, I now wish to hand it over to a co-worker as an executable jar.
I found the (GroovyWrapper) script which works great, so long as the script doesn't have any extra dependencies.
I can put together all the jars manually and pass them via the -cp option, which works but you can't use -cp with -jar so I needed some other solution.
I tried adding an optional parameter to the GroovyWrapper script to embed SQL Server classes but that didn't work in the end as the SQL Server classes are signed and therefore can't be copied in.
I then tried to add a Class-Path manifest entry to point to the sqljdbc4.jar in the current directory. I have done similar things previously when creating standalone jars from java without issues but for some reason it still doesn't work.
I don't want to play around with fat jars, custom class loaders or the like if I can avoid it as the script is nice and simple at the moment.
Has anyone a solution? Have I missed something obvious.

Creating own groovy library

Do anyone have an idea whats the best way of creating an own library for groovy.
I have several methods which i just dont want copy and paste into all my groovy scripts.
The perfect solution would be to do it by an
import myownmethods
How to create the library myownmethods.jar?
Thanks for any answer and solution
Cheers
The simplest method is to compile your groovy files with groovyc and then package them into a jar file with jar. For example:
groovyc -d classes myclasses.groovy
jar cvf myclasses.jar -C classes .
I'd also consider looking at gradle. To get started, you can use a build.gradle containing just:
apply plugin: 'groovy'
Then put your source files in a subdirectory called src/main/groovy and run gradle jar. It will build your source files into a jar file in build/libs.
You should follow the same process that you would for a Java library, i.e.
Create a project for the code
Configure your favorite build tool (Ant, Maven, etc.) to build a JAR for that project
Put the JAR somewhere where other projects can find it. If you're using a tool like Ivy or Maven that does dependency management you'll likely want to deploy it to a repository. Otherwise, you can probably just put it somewhere in source control †
Projects that depend on this library should either load it from the repository (if using dependency management), or have it copied into their lib directory (if not) †
† I know this sucks, but I can't remember how I used to manage dependencies without using a dependency management tool

Resources