How to build a project using libvirt java binding - java

it might be a stupid question but how do I set up an environment to develop a test application using libvirt?
do I have to set up ant or maven project or can I just copy java files to my src folder in eclipse ?
Thanks

If you use Eclipse, you can build your classes and run your program in Eclipse without using Ant or Maven. In fact, Eclipse is usually completely ignorant of your Ant build.xml or your Maven pom.xml file. Eclipse uses its own build technology (although you can ask it to run your pom.xml or build.xml). However, a pure Eclipse way of building a project means there is no way to build and run your project except with Eclipse. If you have a continuous integration system, or someone downloads your project and simply wants to build your jar or war file, there's no way they can do it.
Actually, not entirely true. You could write a shell script to compile your code via the javac commands and jar it up via the jar command. What Maven and Ant do is give you a framework to help build your application and remove system dependencies.
Ant has an advantage of flexibility. You can do things easily in Ant that are harder to do in Maven. The disadvantage is that Ant has the flexibility to do things in a really, really bad way. I almost always recommend for developers to use Maven for new projects. It forces them to write their project in a standard way, and eliminates the need to write Ant build scripts which most developers really can't do.
What if you don't know Maven, but know Ant? I still recommend that you use Maven and take this as an opportunity to learn Maven.

Related

How to automatically export project in eclipse?

I have a couple of projects in eclipse which I now manually export as plugins from eclipse with the following steps:
1) Right click on example_project_plugin_1 in the Project Explorer View
2) Select Export
3) Select Plugin Development > Deployable plug-ins and fragments
Then in the folder eclipse>plugins folder, I can see the archive/jar file of these plugins.
However I want to automate this system.
These plugins are required by another project (say project_to_test) which I'm trying to run and test and I am using Maven to automatically build test cases written using RCPTT running on a jenkins server.
So basically what I want is, without having to manually export as plugins from eclipse, it should be automatically exported as plugins when I call project_to_test from the jenkins server.
I found Tycho but it seems very complicated. (Maybe there's an easier way or tutorial somewhere of how to use Tycho for my particular use?) I tried Ant too but it's also manual work. Is there any easier way to do this? I am quite new to this so I need some direction.
Thanks in advance!
Tycho is probably the best way to do it, as you are already using Maven you should be well on your way. Tycho is simply an extension of Maven (plug-ins, but I am afraid to say plug-ins too many times with different meanings :-).
There is an excellent Tycho tutorial out there: http://codeandme.blogspot.co.at/p/tycho-articles.html so that is the place to start.
However, if you really really don't want to do that, then you probably want to use PDE Build. That is the traditional build system of Eclipse, but it has its weaknesses. You should know that Eclipse does not even use PDE Build to build itself anymore, it uses Tycho.
To use PDE Build from a command line you need to use Ant. The manual work that you refer to is (mostly) automated through a PDE feature that creates that Ant files for you. Right-click on a project, select Plug-in Tools -> Create Ant Build File
Once again, I feel compelled to encourage you to take the plunge into Tycho now, rather than invest more time in the PDE Build way. You are clearly ahead of the curve in other areas (you are doing GUI testing!) so now is the time for automating your builds too.

How do I compile and run Intelij IDEA java project without IDE?

Recently I was trying to run 2048 bot. I'm not a java programmer and installing IDE just for running one program would be overkill. So I tried compiling and running it from command line, but that was not a simple task for me, mainly because of the dependencies. Then I was told, that maven might come in handy. So I wonder if one can easily compile and run a program using maven or whatever tool they have without installing IDE?
The pom.xml file will have everything in it you need to compile it. In this particular case, it is only declaring a single dependency, the selenium-firefox-driver. With maven, all POM (Project Object Model) files inherit defaults from a "master" parent POM file. Maven uses a "convention over configuration" philosophy. Anything not explicitly configured, defaults to standard configurations from the parent pom that is part of maven. That is why you can build a project from such a seemingly simple POM file.
You will not be able to run the build from the IntelliJ IDEA module (.iml) file. In fact, IntelliJ IDEA generates that file from the POM.
First, make sure you have a Java JDK installed. Java 8 is the latest current. But a Java 7 JDK would be fine. After that, the Running Maven link #jeroen_de_schutter provided has all the information you need. Click on the top link in that document to Download and Install Maven. Once that is done, from a command line, navigate into the directory that contains the project (i.e. the directory with the pom.xml file in it) and issue the command: mvn compile to compile your code, mvn test to compile and test, or mvn package to compile, test and package the code. You can add clean to that any of those commands so maven will do a clean build. For example: mvn clean package. See the second Quick Start and third Use Maven links in the Running Maven document for more details and information.
Please note that the first time you run a build (any maven build) it will take quite a bit longer than normal. This is because maven has to download (and cache) a ton of plug-ins and dependencies. Once that is done, the builds go much much quicker. However, the first time you build a new project, the first build make take a little longer as it downloads and caches the dependencies and plug-ins needed by that project that have not already been retrieved.
Yes you can, make sure you have a Java Development Kit and Maven installed. Then by following the Maven user guides you should be able to build it and run.
But it might not be straightforward if you have never used maven, so I would recommend to ask the assitance of an experienced java developer, if you happen to know one.

How can I convert a maven project to a Dynamic Web Project in Eclipse that builds with Ant?

I've got a java project that's using Maven in Eclipse, and would like to completely remove the Maven aspect of the project, and set it up as a completely stand alone Dynamic Web Project that doesn't depend on Maven at all, but uses Ant instead.
I assume this will involve:
finding out the libs that are required
creating an ant "build.xml" file
more steps that I'm not sure of ;-)
What's the best way to do this?
You could switch it to use ant. Maven comes with ant plugin. Run mvn ant:ant and it will generate the build.xml for you. This would make you dependent on ant though.
Probably the easiest thing to do is install m2e and m2e-wtp in Eclipse.
Then make sure your Maven project is packaged as a .war. See here for building a web app in Maven:
http://www.mkyong.com/maven/how-to-create-a-web-application-project-with-maven/
Eclipse will see it as a Dynamic Web App with all the configuration and deployment capabilities.

Packaging and deploying a Jython program from Eclipse

So I've been pigeon-holed into writing some Jython code. I've been using the latest version of Eclipse IDE with the PyDev plugin for development. Up until now, things have been moderately tolerable. I've gotten all my Python scripts working and I'm successfully including a couple of JAR files and the class directory of another Java project as external dependencies. Everything seems to run fine through the Eclipse IDE.
Now I need to package everything up and deploy it. From what I can gather, the best way to do this would be to package everything up in a JAR file. The Jython documentation suggests starting out with the jython.jar file and adding to it. OK. So I modify my main python module and start adding all my python source to the JAR.
It executes but of course can't find all the external dependencies.
How is one supposed to add the external JAR files so that they are correctly seen by the Jython interpreter? How is one supposed to manage more complex dependencies in a setup like this?
Is there a plugin for Eclipse or maybe something like Ant or Maven that can handle all of these steps for me with the push of a button?
I can't be the first person that has needed to deploy Jython code with complex dependencies can I?
I've made some headway on getting this all working so I thought I would put some notes here in case they help anyone else out. I'd still like to hear from others on their experiences trying to put together something like this.
It turns out that Eclipse as of 3.5 has a project export option for Java -> Runnable JAR File. If you use this option, you can point to a Java main class in the export wizard. You also have the option to have it repackage all the JARs that you are dependent on in your new JAR file. Make sure to check the box to save the export as an ANT build so that you can repeat the process quickly. NOTE that the first time you do this through the interface, it may fail, but it will still have created a JAR file.
Now here's where it gets strange. To track all the dependencies, I am still using a mostly incomplete Maven build in my project. I create the Maven .POM file. And I told Maven what my external JAR dependency was. I then told Maven to do a dependency update for me. It pulled everything into my Maven repository as expected.
Now when I do my ANT build, it appears that it is getting its list of JARs to include in the final build from Maven. I'm not really sure if it is supposed to work that way. I'm also not 100% sure that it is working. I guess I'll find out when I have to add another external JAR to the project.
Anyways, if you follow this question you'll see that you can take the latest builds of Jython and pull the org.python.util.JarRunner.java file out and use it in your own project. This is you Java.main class that you will need to point your ANT build at. From there, convert your main Python/Jython script to be the run script that was talked about in that question.
Next, build up another copy of the Jython JAR file in your Jython directory. This one should have the /Lib directory pulled into the JAR. Save that off and then point your Eclipse IDE Jave Build option for your PyDev project at that JAR as an external dependency. Your JarRunner will now work and execute the run.py file under Jython.
If all that works, you should then be able to rerun the ANT exported build from earlier and you will end up with a single JAR file that you can execute on the command line as:
java -jar {yourjar} args
And distribute to your customers without any additional dependencies.
If that all seems a little bit convoluted, it is. If anyone has a better way of setting this all up using Eclipse, please let me know.
Make your life easier and just use Maven and the mavenjython compile plugin.
See my answer of this question: Using Jython with Maven
You get full automation of the build and deploy process, and the result is a jar that includes jython and all other dependencies.

Java, Eclipse, Ant, JUnit, Hudson, SVN, native libraries; can they all coexist?

What is the most proper way to accomplish all of the following:
Create a project in Eclipse
With an Apache Ant buildfile
That Hudson (or another more recommended CI system?) uses
And support for JUnit tests that are run by both Ant/Hudson and Eclipse
And check the proper folder structure into SVN so that future developers can replicate the build, and Hudson can automatically grab from SVN and run the Ant file to build/test/deploy the project
And the project has native libraries, if that makes any difference (I've already written an Ant task that can download and unzip the proper library files depending on the OS)
I already have my project with some source files and an Ant file, but I've been having trouble integrating it with Eclipse in an organized manner, so I would really love to start from a fresh Eclipse project, set it up correctly, and then copy my Ant file and my source files piece-by-piece into the project in the most Eclipse-compatible way.
I will be continuing to play around with everything in an attempt to get it working as I like it. But if you have experience with this sort of thing, perhaps at your workplace, please give as much information as you can.
My main goal here is to learn this once and use it in my future projects. For now, I am developing a client-server application consisting of a JOGL applet frontend (using JNLP files) and an unattended server app. Up until now I've been doing it all by hand: writing and building in Eclipse, dragging the applet jar into my FTP client, SSHing the server jar and restarting it by hand, and all with no testing process. I'm hoping that by the end, the build process will be something like this: test locally on my machine with a copy of the native libraries; commit code changes to SVN; Hudson svn updates, uses the Ant buildfile to compile and run all JUnit tests; if all the tests pass, it proceeds to copy the server jar to my dedicated server and restart the running server instance, and then copy the client jar to my web server.
When I start a new project, I generally take the following steps:
Create a new Java project in Eclipse, using the Java project wizard and opting to keep source and class files in separate directories ('src' and 'class')
Set up the project in Eclipse with the package structure you want
Create a new repository (or folder in your repository) for the project, with the normal /trunk/ /branches/ /tags/ set up
Using your SVN client, import the contents of the project folder Eclipse made for the project (at the level where the 'src' and 'class' directories are) into the trunk of the repository
Confirm everything is in Subversion correctly (check the trunk out to a new location)
Using Eclipse, delete the project (and the files on disk)
Create a new project using the 'Checkout projects from SVN' wizard, using the trunk of the repository
Create your Ant script, ensure the project builds correctly, and add the Ant script to the repository
Now, from Hudson:
Create a new job and set the Subversion URL to the root of the repository
Add a build set that will use Ant (I've always had to install my own version of Ant and ensure it's configured correctly to have this work) and will call the Ant script you
Use 'Build Now' to see if the job will build correctly
You can invoke your JUnit tests from Ant in the build script (first compile them with the javac task, then run them with the junit task). Hudson will track the test results if you ask it to.
You can use a shell script build step to copy your server jar to where it's needed, and restart the server instance. Like Mnementh said, it sounds like you've got the native libraries sorted...
If you are not tied to using ant, and are prepared to use Maven, then it is simply a matter of setting up Maven with the Eclipse plugin which generates the Eclipse projects for you.
Hudson already knows how to build Maven projects, so that is taken care of.
So long as you can pull your projects into eclipse, then it will be able to run the unit tests, and hudson can use the previously mentioned maven support to run the unit tests as well.
If you use Maven, then you will want to follow it's guidelines on how to create a project, here is a good starting point.
Hope this helps.
At our company we actually use Eclipse, Java, Ant, SVN, Junit and Hudson. That is all you mentioned except the native libraries. If you said your ant-buildscript already works with the native libraries that problem seems solved too. To integrate it well into eclipse you could do it in two ways: Use Ant also from Eclipse (has downsides) or the developer has to install the native library for his machine properly, so that Eclipse can compile without a problem and for continuous integration it will be downloaded by Ant.

Categories