I have a project that's currently built with ant that pulls the latest trunk version of Solr in through git and then builds through ant. I'm pretty used to Maven and its system for dependencies at this point and find our old ant way of doing things pretty messy and hard to maintain. With that said, basically everywhere I seem to look online, people are building solr with Ant, and the few tutorials I found for doing things with Maven are all along the lines of this one, which doesn't seem to work.
So, to be clear, all I'm looking for here is a clean way to develop the project in Eclipse and to be able to deploy it. I'm sure someone must have done this before and must have a good answer. I'd be really interested in hearing it.
I just got it working by throwing all dependencies into Maven, making my own repo for a pegged version of Solr 4.0-SNAPSHOT, copying the web.xml from it into src/main/webapp/WEB-INF/, and running things through mvn jetty:run with salient variables passed in as arguments as:
mvn jetty:run -Dsolr.dataDir="./solr-data" -Dsolr.master-host="localhost" -Dsolr.solr.home="./solr-home"
This method is officially unsupported, but it means I no longer have to bother with ugly ant configs or holding all of Lucene and Solr in git repos attached to my project, so I could build from them. It also means changing/updating versions just requires a one line change in my pom.xml instead of digging through and switching a whole ton of extraneous configs. I'm pretty happy, and once I got a better feel for how Solr is supposed to work, reconfiguring the project really wasn't that bad.
This answer is probably more a comment, but a comment is too small to expose it all.
I know nothing about Solr, but from a neutral point of view, I would say you have two options:
Mavenize Solr (looks like what is suggested by your article). Maybe you could post another question on what problems you encounter using their solution.
Invoke the original ant tasks using the maven-antrun-plugin. This would also probably require to attach the built jars (or if it only contains classes/resources, jar them first). You could decide to install them locally using maven-install-plugin or attach them with maven-build-helper-plugin.
In eclipse, there are plenty of tricks to access the built files. You could simply add the project as a dependency.
This second option should work, but I don't find it very clean
You should be able to use Maven if you want, I know some of the Solr developers do. Have a look here: http://wiki.apache.org/solr/HowToContribute#Maven. This isn't the most supported way though, and I can't help you with this since I never tried it.
I actually work with Solr + Ant and there's basically a task for everything: ant test, ant dist and so on. I agree that's a bit old fashioned, but it works. Lately the build has been improved a lot introducing Ivy as dependency management tool, in order to remove all jars from the source tree.
Let me know if you have some specific problems with ant, maybe I can help you more.
Related
My friend and I are working on a Java project collaboratively. We are both very inexperienced with regards to Eclipse and Git alike.
The primary goal is:
For my friend and I to seamlessly contribute to the code via git, with minimal limitation.
To be able to develop the SWT interface without running into dependency errors that might arise due to absolute class paths and/or due to differences in OS (it would be beneficial if I could work on the project not only on my Windows machine at home, but my Macbook as well)
When I looked up the question, it seemed this question had the answer.
However, doesn't changing the build path affect the .classpath, and will thus be affected when you commit changes to git (see goal #2)? How do I ensure that virtually anyone can clone my repository, regardless of OS (see goal #1)? The other answers I have found involve setting the class path variables—however, as I have said, I am woefully inexperienced with Eclipse. I have also heard that Maven might be the answer, but I have no clue how to use the pom file and how to set it up for the 10 or so different jars in the "Referenced Libraries" part of my project.
Thank you in advance for the assistance
We are both very inexperienced with regards to Eclipse and Git alike.
And presumably SWT and Maven as well? Brace yourself for an exercise in patience and frustration - this sounds like a very ambitious (but not impossible) goal without much experience in these things.
develop the SWT interface [...] not only on my Windows machine at home, but my Macbook as well
SWT has different .jars for different OSes and architectures. If you truly want a single .jar that can be run on different platforms, it's not going to be trivial to handle which one is used at runtime. I would recommend building different assemblies depending on the target OS. If that is simply something you cannot do, then unfortunately I can't help much in regards to how to load different SWT .jars at runtime.
Maven might be the answer
Maven will definitely help, and you can use this repository in your pom.xml to get the corresponding SWT dependency: http://maven-eclipse.github.io/maven.
I have no clue how to use the pom file
A bit of Google-searching should bring up some very basic Maven examples. Take some time to understand the different parts of the pom.xml file (Maven in 5 Minutes).
how to set it up for the 10 or so different jars in the "Referenced Libraries"
You will need to find the corresponding Maven dependency for these. Eclipse will be very helpful with this, and you will not need to manually manage the .classpath file (How do I get my Eclipse-Maven project to automatically update its classpath when I change a dependency in my pom.xml file?).
Without throwing too much info at you, while still trying to provide a helpful answer, I would recommend (after getting a grasp on Maven basics) taking a look at using profiles in your pom to determine which SWT dependency will be used (Related: SWT on different systems). This will address your primary concern, as you will no longer be hard-coding a platform-specific dependency, so anyone on a different OS can now build your project.
For my friend and I to seamlessly contribute to the code via git, with minimal limitation.
IMO Git will be the least confusing part about what you're trying to achieve :) That said, just take some time to learn the basics of Git and you should be fine. It's not overly complicated once you understand the basics and stick to the basics.
In general, be aware that with SWT there are some nuances with how it will look/behave on different OSes. Just because something works for you Windows doesn't mean that it will look/behave exactly the same way on a Mac.
Side note: A "gotcha" that you will eventually run into on macOS is the need for the -XstartOnFirstThread JVM argument (Running SWT based, cross-platform jar properly on a Mac).
I'd like to make Gradle use Eclipse project dependencies. Unlike this question, I don't want to do any export as I don't want to hunt down problems due to forgetting to re-export after a change. And unlike this question, I don't want to integrate Gradle into Eclipse at all, as I'm satisfied with how my Eclipse works (it's much faster than a Gradle build) and I'm also afraid that my Eclipse 3.7.2 may be too old for such games.
Ideally, I'd like something like
dependencies {
compile allFilesFromEclipse()
}
Actually, getting the JARs would suffice.
What I've tried: Just some light googling. I could imagine parsing the .classpath file myself, but it's not done in 5 minutes, so I'm asking if there's an existing solution.
I am afraid you won't find much help. It is not obvious what problem you want to solve here. Most developers prefer to base their build on a build tools rather than expect that they will replicated an IDE setup everywhere.
As for Eclipse 3.7.2: I am not sure why you want to stick with that but gradle eclipse generates files that work with this version.
Does anyone know a tool to create the Maven dependencies from a lib directory? I have several web projects with quite a lot of JARs and would like to "mavenize" them. Looking for the proper dependency for each one is quite a pain and seems like something that may be solved with a program.
Well, since these jars (presumably) didn't come from Maven in the first place, they won't contain a manifest that tells your their GAV co-ords. So it's hard to see how a tool could infer what's needed from just a directory. Unless you're phenomenally lucky and every jar has the exact arteface ID and version in the filename, in which case you might be able to script something.
You probably don't want that anyway. A lot of those jars, I'm betting, are transitive dependencies, and you don't really want them littering your POM.
tl;dr bite the bullet and just Mavenise it by hand. You could always write a script that uses a bit of wget magic against the public repos or something, to help you along the way.
Ant2Ivy https://github.com/myspotontheweb/ant2ivy is a Groovy script that can do this.
Despite its name, it can also create pom files (https://github.com/myspotontheweb/ant2ivy/commit/9e3e8358f2b31507b13f5def69627da422e1656b).
It looks up the names/hash in Maven Central for you in order to create the pom.
You can write a plugin which adds all the dependencies (with <scope>system</scope> to the project's dependencies list. You can check how to do this by having a look at the build-helper-maven-plugin.
I would strongly object doing this. Look, if you're going to use Maven to do your Ant monkey-business, just use Ant for that. Will save you time and effort.
If on the other hand you would like to "Mavenize your build", you should really Mavenize it properly and not be lazy about it. Solutions are only as crappy as you make them. If you're lazy, they'll be a mess either way, so the effort would be pointless.
I suggest you add each of the dependencies using either of:
search.maven.org
www.jarvana.com
www.mvnrepository.com
www.versioneye.com
And do the job right. In addition, install an artifact repository manager as well. :)
Good luck.
I was working on a project with a seriously large amount of classes that I want to compile to a jar. I know about entry-points and the manifest.txt and all the needed items inside my jar, my classes are all compiled and have the .class file and everything, but the problem is I will have to add all the class files to the final jar in compilation through a single line in Command Prompt. I was wondering and stumbled upon literally nothing in the internet if it could be done in an easier way because I will be updating my work constantly and have to recompile and re-jarify my work. I have heard of third party programs that will do the trick, but somebody on some website said that they could potentially be causing problems and stuff, so I dropped the idea quite quickly. Now that I am in a seriously tight spot though, I wish to hear opinions and suggestions on this. So to sum up:
I want a way to compile a big bunch of .class files in a single jar without typing all of them over and over again between compilations allowing me to save time and frustration.
I would prefer native stuff if this is even possible to do - e.g. the jar compiler of the JDK instead of anything third-party. If there is a way to do this using manifest or any other file in compile-time arguments, let me hear it.
Anyone who cares to suggest, discuss or give me a good reason why to or not to use third party applications for this will be most welcome.
Keep in mind that I work on Windows but my aplication will be cross-platfrom, so don't suggest as a main option some compile solution that will make a final file with a .exe extension (although if anyone knows how to do this, I would like to hear it in a comment as I wonder about this as well).
Thanks in advance and if you feel the need to ask me anything to help you reply, shoot away!
Have a look at this ant tutorial which shows how to write a simple build.xml which can compile and jar.
http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html
You can then adapt it for your own needs.
Note: ant is only suited for smaller projects like yours.
The solution to this, and related, issues, is to stop typing at the command line and use a build tool. The common tools here for Java builds are:
Apache Ant http://ant.apache.org
Apache Maven http://maven.apache.org
There are other less common ones. Both of these tools will provide you with what you need.
Just want to add some information about Ant and Maven.
In your case, you need to automate the build of your application. The basic solution would be some kind of script but it's not used at all. Nicer solution exist :
If you come from the idea of a script to automate your build, you can use a tool like Ant, it's a bit like make and such tool in the C world where you define the needed tasks for your build in a configuration file. The problem with such solution is that it allow you to define your own structure for your build and a new comer to your project may have some difficulties to understand the logic of the build.
The other approach is to describe what kind of build you want to do, organize your sources and resources as it is done in most cases (by following a convention in fact). For example, java sources are in src/main/java, tests are in src/test/java, config files are in src/main/resources, and so on. In the description of your build you will just say : this is a java project and I want to build a War web application and execute my tests using jUnit 4. The dependencies of my project are apache xerces and hibernate 4. Then, the tool will know what to do without the need to say how to do. This is the way maven do.
In short, in the Ant approch, you will say how to do what you want and in the Maven approach you will define what you want to do and the tool will know how by default.
You may also be interested in some kind of hybrid approache like the one provided by tools like Gradle.
For more information :
http://ant.apache.org/
http://maven.apache.org/
http://www.gradle.org/
Hope it helps
I am looking for an lightweight Java build tool. As light as possible. Even at the expense of features. Any recommendations?
As light as possible? That must be javac running from within a batch file or shell script.
But why?
There are only really two choices: Ant or Maven.
Ant is essentially a scripting tool that you can do anything with but you have to write everything yourself.
Maven comes with a lot of predefined project types. It will dictate a directory structure to you (which some people don't like) but will also handle dependencies (which Ant can sorta do with Ivy).
Personally I prefer Maven. A few lines of XML will get you the tasks to run unit tests, stop and start a Web container (eg Jetty or Tomcat), etc.
As said elsewhere, your real choice is between maven or ant. To echo other sentiments, I find there is more configuration to do with ant, so I prefer maven. That said, a lot of people tend to criticise maven in that although you need less configuration, it downloads a lot of dependencies (and dependencies/ dependencies), so it all depends on what you mean by "light" - do you mean light in configuration or light in dependency jar downloads/installation size?
If you want something light in terms of config and downloads, you are better off with a shell script, but that will only be as feature-rich as you have time to make it!
I'd again recommend Maven2 - it is very feature rich through the use of plugins, but it can also be very "light" (depending on what that means):
it doesn't need hard installation (just unzip directory + add the path to it to the environment variables (depending on OS))
it doesn't require configuration - just copy-paste a simple POM file and your build is ready. You will just have to follow the directory structure conventions of maven
it has a plugin for every IDE, so using it with GUI makes it even easier.
Of course, an alternative is ant, but I find it less "light". And I find it less light, because ant scripts grow ugly and unpredictable, and become hard to manage, while maven scripts stay simple, because of the rich functionality provided with the tool.
It really depends on your definition of 'light'. Do you want a tool that requires very little work to use (light on code)? If so, Maven or Gradle might be a good option. Maven has been around for a while. If you are doing something that follows their conventions, then you will need to write very little in your pom.xml files. If you start deviating from the norm it can get difficult to make it do what you need (making things less light). Gradle is also an option. It hasn't be around as long as Maven, but allows you to deviate from the convention easier.
If you are looking for something that is light in terms of the tools itself being lightweight, Apache ant may be a better option. It doesn't have the conventions built in like Maven. If you have a non-standard build that is pretty simple it might be possible to create a very light ant script to do your build.
Maven is simplest if you follow its directory structure. If you are on linux or unix system, I would use shell script. Or you could consider IDEs eclipse or netbeans, they will do the job for you, and dependencies are very easy to configure.
Have you tried BlueJ (http://www.bluej.org/) ?. I used it a few years ago to teach students. It is simple in the sense you can just copy/paste code and run it. It was created to teach students, hence is very simple and good for java starters. Note that it is is a full IDE, not a command line tool like maven or ant.
If you are going to stick with standards, Maven is the best bet.
If you want flexibility consider Groovy AntBuilder. terse syntax, and full power of ant and groovy scripting.