Java -Ant Integration Problem - java

I have created a Greenhouse Monitoring system using SunSPOTS. The code modules are written in java.
The problem I face is that I need to run these programs using ant commands. Im able to do it through a terminal independently but Im unable to find a way to build a gui and execute these modules through that.
Any kind of help is welcome.
Thanks

Take a look at this links this might help
http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html
http://ant.apache.org/manual/Tasks/java.html

If i understand the problem correctly, then what you need is a way to call your ant script from java ui (may be some button or link). You can use Runtime.exec("cmd ant targetname") to call ant script.

you need to provide more details, f.e. what kind of GUI ? Web based, Java Swing, Applet ... ? Note that most IDE's (Eclipse, NetBeans,IntelliJ ..) have ant support, means write and start ant scripts. What platform ? If you need a platform independent mechanism maybe Groovy is for you; so f.e. build your swing gui with Groovy swingbuilder and start your ant logic with Groovy antbuilder

Related

How to debug plugins?

I'm working on a project for class that involves me developing a plugin for an existing application. However, I struggle with GUI programming and the inability to use a debugger or print statements has made the process very not fun. Is there any way I can debug this thing other than trial and error?
The plugin (as well as the main program) are written in Java, and I'm using NetBeans. I'd prefer to stick with NetBeans but would be willing to move to a different IDE if necessary.
You should be able to use remote debugging as described here http://wiki.netbeans.org/FaqDebuggingRemote
This involves running the original JAR from the command line with the following parameters `"-Xrunjdwp:transport=dt_socket,server=y,address=8888,suspend=n"
This would then allow you to attach the Netbeans debugger to the running process.

Launch Clojure REPL from java swing

How to Launch REPL using java Swing application. As shown in Image. This REPL should be able to run all functions provided by Clojure Build-in libraray and other developed libraries by user. (provied as jar in classpath).
Point is, how to run Java clojure.jar clojure.main from swing so that it will show user defined Namespace. like myRepl=>
I'm not sure I understand your question exactly. Do you want to write such REPL or to just use it?
In any case, googling for "clojure swing repl" seems to show interesting results, one of which is: https://github.com/alandipert/clj-swingrepl
N.B. I haven't tested this.

Can I extend Jenkins with Jython/Python

Is it possible to write Jenkins plugins using Python (via Jython), and if so, where would I get started? I don't know Java (and don't have a real interest in learning it at the moment) so being able to use Python would be nice for me.
There's no docs on that. Frankly your problem with be you must understand how the interfaces and extensions map from java to jython to write it.
Here are links on writing Jenkins plugins
Let's you embed either Jython or Python scripts and run them from a plugin If all you nee to do is run a simple script, that be what you need.
If your goal is to execute Jython code within Jenkins, you may want to have a look at the Jython Plugin.
Starting version 1.6, you can actually install Jython packages (say if you have your own library you'd like to use), and it'll automatically sync up the packages across all Jenkins slaves.
Since Jython can produce Java classes I see no reason why this should not work.
Note that you will need to learn at least some things about Java (mostly the platform, not necessarily the language) in order to be able to write plugins for Jenkins.

How to distribute Java-based software?

Now, don't get me wrong, I am a very competent programmer, but when I program, I typically develop things for the web using scripting languages like JavaScript, PHP, Python, SQL, etc. If I want to develop Java software (I am relatively experienced in Java), how do I distribute it?
Is there any good way to package up Java software in a nice little executable, send it out, and have it run? Alternatively, is there any good way to package up Java in some sort of installer, and send it out to be installed and run?
I'm using Launch4J http://launch4j.sourceforge.net/ it will generate an .exe executable for Windows, if the targeted system don't have JVM, it will tell user to download and get JVM.
You can package Java applications in so called jar-files using the jar tool or any competent Java IDE. These jar-files are self-contained and seldom need any installer.
These .jar files can easily be distributed and executed.
If you're used to web-development, you may also be interested in the Java Webstart technology.
Some links to get you started.
Export to a .jar-file in Eclipse
Lesson: Java Webstart
I have found two approaches to work well, depending on the needs of the end user.
1) Java WebStart - allows for central distribution and easy maintenance, but works best for online users. Require you to have a web site to locate the files - these days this is easy to do on the Google Application Engine.
2) Wrapping up the Java program in a single jar using one-jar, and then using jsmooth to generate an .EXE file which ensures Java is available, extracts the jar-file and invokes Java on it. This works well for users not always on the net, where you want the launch process to be transparent, but is less easy to upgrade than the webstart approach.
I use Maven to handle all the dependencies of my projects and that way when you utilise Maven to build your projects they will compile into one nice executable jar that contains everything so you dont need to worry about getting all your third-party jars in the right place etc.
There are a couple of ways: one is to create an installer that allows your user to install and run it. For this you can take a look at NSIS.... or you can just use Java Web Start where your user can just click the link and launch your application.
Here you will find a large set of options: Open Source Installers Generators in JavaIt is very useful for the "naive" customer or user of your application, to make the installation process as painless as possible. Let them install whatever is needed, DBMS, JVM, JMF and additional options via one installer.
You can also consider use one of the rich client platforms available for Java. The learning curve is probably a lot higher than just creating a jar file and ship it, but you will get a lot for free when it comes to distribution. (Think Eclipse with auto update through an update site).
Do a search for "Eclipse RCP" and "Netbeans RCP" and you'll find the two biggest contenders here. I also performed a serach for "eclipse RCP installer" and one of the hits seems interesting:
http://download.instantiations.com/RCPPackagerDoc/integration/latest/docs/html/gettingstarted/GenInstaller.html
I personally like izpack. It generates a jar file installer that you could wrap up in launch4j, supports things like windows specific shortcuts, is highly customisable through XML and hooks directly into ant.
OneJar is great for smaller stuff, but for larger programs or applications it's nowhere near as flexible and in my experience is rather slow.
Hello you can make an installer for your application.
In the link below you will find a nice help about izpack installer.
http://www.imrantariq.com/blog/?p=89
Link below contains a detailed pdf to make installer with izpack.
http://www.imrantariq.com/blog/?attachment_id=112
cheers

Replacing build.xml with Build.java - using Java and the Ant libraries as a build system

I've grown disillusioned with Groovy based alternatives to Ant. AntBuilder doesn't work from within Eclipse, the Groovy plugin for Eclipse is disappointing, and Gradle just isn't ready yet.
The Ant documentation has a section titled "Using Ant Tasks Outside of Ant" which gives a teaser for how to use the Ant libraries from Java code. There's another example here:
http://www.mail-archive.com/dev#ant.apache.org/msg16310.html
In theory it seems simple enough to replace build.xml with Build.java. The Ant documentation hints at some undocumented dependencies that I'll have to discover (undocumented from the point of view of using Ant from within Java).
Given the level of disappointment with Ant scripting, I wonder why this hasn't been done before. Perhaps it has and isn't a good build system.
Has anyone tried writing build files in Java using the Ant libraries?
Our build system is primarily based upon exactly what you describe, and it works very well indeed. We use the Ant tasks (especially the file-manipulation tasks) from custom java programs which assemble the application using auto-discovery of convention-based application module layout.
You may need some glue Ant XML, to do things like compile the build scripts themselves, and to actually invoke the java to perform the build, but it's minor.
Not only is java more readable than Ant, especially when it comes to conditional execution, but it's vastly quicker. Our Ant-based build used to take a minute or so to assemble an EAR, now the java based version takes about 5 seconds.
You had a fine idea. Cliff Click had a similar idea: http://blogs.azulsystems.com/cliff/2008/01/i-hate-makefile.html
If you go through with it I advise you to keep it as simple as possible so your build system doesn't need a [non-trivial] build system itself.
Given that Java is compiled, this is kind of a chicken and egg problem. You need to build your Build.java to build your project.
Ant currently supports inline scripting using BeanShell, Groovy and a bunch of others, that can really help reduce the need for that.
EDIT: In response to Dean's multiple comments, if your build consists strictly of a long proceedure, then indeed you don't need ant's build script. However, the power of the build script is that it ensures that dependencies are only executed once while allowing for mulitiple entry points, something that is far from trivial if you roll your own.
If you don't like the XML format, you are not alone, the author of ANT agrees with you. However, if your view of the build process is something that can be launched from your IDE as its only launch point, I would say that your build needs are quite simple.
EDIT2: I upvoted skaffman's answer because it speaks directly to the question. In the comments we seem to agree that the approach is fine for a procedural build, but would not work for a declarative one, and that you need at least a little ANT xml to get the ball rolling with your Build.java to avoid the chicken and egg problem. That seems to get to the crux of the matter.
An important point seems to have gotten lost here.
Ant is written in Java and what I'm looking for is a better way to use the Ant tasks (APIs in the Ant libraries) than through xml. For the life of me I can't see how using xml to invoke Java would ever be better or easier than using Java to invoke Java.
The one obstacle is that the xml approach is documented whereas the Java approach is not documented so I'll have to download and get familiar with the Ant code.
I held back from posting this question for a couple of weeks because I was sure that someone had done this before and that my google-foo just needed improving. It just seems so obvious to use Java to call the Ant APIs instead of xml that I'm still surprised that there wasn't a parallel Java-based approach developed for Ant as well as the xml approach.
Just because it is obvious doesn't mean that someone has done it before, though.
While I suppose its possible, you would probably be better off with shell scripts then writing a full on java program to simply automate builds.
You would be missing out on one of the key uses for ant, which are the easy-to-specify filesets and easy to read in properties.
I have stuck with ant as Groovy is too close to writing an entire application to just build your real application. Too complicated for the trouble.
While using Ant tasks inside Java programs is fairly easy, I probably would stick to Ant build files if I were you. If you're doing some groovy development, if Eclipse doesn't do what you need, maybe you need to look elsewhere(IntelliJ, NetBeans, etc.).

Categories