Java files needing to be hosted on SVN - java

I will be hosting a java project on SVN which will need to be downloaded by other developers with the ability of that project to be compiled / packaged on their local machine.
I would like to know what files are needing to be stored on SVN and which ones can be left out. I know the files that Netbeans creates can be left out and the build.xml will need to be included as it has code to package the libraries used in the project into the .jar file.
I am assuming that the following need to be stored on the SVN server:
/lib
/src
build.xml
Does any of the files in the
nbproject folder need to be added?
If not what svn commands (IE
svn-ignore) will I need to run to
ignore all the files except for those
in /lib, /src and the build.xml file?
What should my file structure on the
svn look like? Should I keep the
source files in the src directory on
svn or should I name the folder
something else so the developer can
then "Create a new project from
existing source"?

You shouldn't host you lib directory on your SVN, you can use Ivy or Maven as a dependencies manager which will download all your dependency from a repository.
Concerning the netbeans files it depends on the way your team work, I would say that you can let them on the SVN it will be useful for other developers using netbeans and shouldn't bother developers using another IDE.
For the svn:ignore part you have to do svn propset svn:ignore dirname . in command line.
A general file structure is :
/svn
|-projectName/
|-branches/
|-tags/
|-trunk/
|-projectName/ (Sometimes this directory doesn't exists and its content is put right into trunk)
|-pom.xml (Maven !)
|-module1Name/
|-src/
|-main/
|-java/
|-resources/
|-test/
|-java/
|-resources/
|-pom.xml (Maven !)
|-module2Name/
|-module3Name/
Resources :
Apache Ivy
Apache Maven
Subversion - svn:ignore
On the same topic :
Which files should be imported in a subversion repository for a web services project?
-How to ignore a directory with SVN?

I decided to take another route. While I had read your original post about using Maven, we are wanting to stay away from Maven as we are basically just writing a command line interface for an existing library.
Another reason I decided to do what I did was during adding my svn:ignore's I realized that some of the developers here keep their netbeans project settings in different directories which would basically not do any good since it wouldn't be an svn working copy in that dir.
So what I did was just add the /src and /lib directory to the repo.
The end user then checksout the repo with svn co svn+ssh://path/to/repo/trunk . and then will open netbeans and select "Create project from existing source". At which point they will go in and add the library from the /lib directory.
I have Up Voted your answer as it would have been very helpful should I of gone through with using Maven.

Related

Can files outside of the Maven folder structure get compiled?

We have a Java project that was modified about 2 years ago based on the dates.
The project uses a the Play Framework which as I recalled built and ran just fine back in 2012.
The developer apparently had tried to change the project to be a Maven project but the folder structure is all over the place and not within the Maven src folder structure.
Attempting to run the Play commands does not work on building the project any longer and using the Maven commands does not compile the code.
What occurs is just the packaging of all of the folders and source code into a .jar file.
So the question is 'Can files outside of the Maven folder structure get compiled?' if so how, OR do I need to restructure all the code to be placed into the proper Maven folder structure to try and get this to work again?
Thanks for your time.
Rough view of the folder tree below: Unable to post the POM as it is on another system
Project Name
src
main/java/
trunk
Project Name
... play framework folder structure in here eclipse, modules, precompiled, tmp
conf
lib
Web Content
META-INF
WEB-INF
Yes you can compile files in a non-standard Maven folder structure. Maven natively supports multiple source directories for the purposes of generated sources.
Read the Maven use guide When You Can't Use the Conventions
Using Multiple Source Directories This occurs when you are producing a
single JAR (or other artifact), and have several source directories
with classes you want to include.
This answer shows how to edit the directory structure in Maven by specifying the appropriate properties to override from the superpom.
The Maven pom docs show the build element set mentioned in the link above.
As a side note this answer covers a non standard directory layout for building war.

Eclipse JAR export settings for external JAR file creation(for import into another project)

I have a project where I want to add an external JAR file. The desired external JAR file has a nifty Github page with source, but no pre-compiled JAR file.
These are the steps I've completed so far:
1. I have downloaded the source in a zip. (its Twinkle from SwingFx.ch in case you're interested)
2. I have extracted the zip file to my workspace.
3. I have created a new project with the same name as the extracted folder from the zip file. (project loads the source successfully)
4. I select the export option from the File menu and selected the 'JAR file' option and clicked next.
Note: I had to add an external library to the above Twinkle project for it to build successfully (in case that makes a difference to the settings).
On the JAR File Specification page there are multiple check-box options available(see below):
Export generated class file and resources
Export all output folder for checked projects
Export Java source files and resources
Export refactorings for checked projects
Compress the contents of the JAR file
Add directory entries
I am not sure which are supposed to be selected and if it makes a difference in the behaviour of the project I will add the (soon-to-be) exported JAR file to. I tested it by exporting with the default settings. This worked ok.. However, I now do not know if I should have chosen different settings in case of any reasons I am not aware of. I am not sure if there are specific settings I should choose when I intend for the JAR file to, specifically, be added as an external JAR file to another project.
Please enlighten me!
This is a traditional Java library that uses Maven. It should be fairly easy to build using Maven, which should be better and quicker to build this, if you already have Maven and git installed.
Let's consider that you did not download the source file as a zip, but take the github approach, where you'd use git to download the source code.
If you don't have git, download its latest version and install it.
If you don't have Maven, download its latest version and install it.
Once Maven and git are installed, make sure the Maven and git binaries are configured in your environment PATH variable. If not set, you would, on the Windows platform and for Maven binaries, set it this way (using the default installation path):
set PATH=%PATH%;C:\Program Files (x86)\Apache\maven-3.1.1\bin
Create and change directory in a work directory of your choice, that we'll refer to %work_directory% from now on.
Run the following:
cd %work_directory%
git clone https://github.com/spreiter301/Core.git
git clone https://github.com/spreiter301/Twinkle.git
cd Core
mvn clean install
cd ../Twinkle
mvn package
6. Retrieve the twinkle-1.0.0.jar file in the newly created '%work_directory%/Twinkle/target' folder.
In this case, it was necessary to retrieve the Core library because it is a dependency of the Twinkle project. Normally, this is not necessary because dependencies are automatically retrieved from a maven repository. But in that case, that dependency is not available on any Maven repository. Hence we manually retrieved the dependency from github, compiled it and installed it in your local cached repository. Then we could package the Twinkle project into the JAR file.
This should do it. If you want a 5 minutes tutorial on Maven, there is a tutorial for this here. I highly recommend it, you will encounter this often in the Java world. Maven is the standard build tool for Java, just like 'make' is for C, 'rake' for Ruby, 'sbt' for Scala, etc..! Good luck with the rest.

How to construct maven project from source code

I have compiled sources of java web application. I know that project uses maven, because there is pom.xml files inside .war file.
I want to know is it possible to re create maven project using .war file. I use Java Decompiler to get sources, but i do not know how to combine all folders and .java files as it was in original project.
Is there any tool or howto to do it automaticaly?
Here is sources directory tree structure
For information: I do not want to stole some project or code, it's just my work. There is some web app in our production that was done by other developers in 2007. Now we are supporting this projects, and i don't know why customers do not have sources.
Create a new project from scratch as explained in Maven - Guide to Webapps. Then find the src/main/java directory and create a directory structure that reflects packages of classes in the war. Move the resources to resources folder. Use the command mvn package to recreate the war.
You can follow following steps. If your pom.xml is proper
Create a folder say, project
Copy your source code files with package structure intact to project folder( Note: if subfolder should src /project/src .
Copy pom.xml
In eclipse File->Import->select Maven-> Existing maven projects-> select the folder(project)-> Follow the instruction

How to build project from maven pom file

I have a maven pom file for an open source project. This pom file has all the info like what other jars it depends on etc. I installed maven. Created a dir samprj and copied the pom file into that dir. Cd into that dir and ran mvn command without any arguments but I got bunch of errors. I am absolutely new to maven so I think I am missing something. I tried also from Eclipse ( Import project -- exisitng maven project) but that also does not work except eclipse creates a project that has just that file pom.xml. I expect something that first it will download the jar for the project and then download all dependent jars and config files but nothing there.
So given a pom file how do I build the project from it?
mvn install should get you going
I have a maven pom file for an open source project. This pom file has all the info like what other jars it depends on etc. I installed maven. Created a dir samprj and copied the pom file into that dir ...
It sounds like you only have the project's POM file. This is not sufficient. You need to checkout the complete source tree for the project. Having done that, change directory to the directory containing the POM file and run mvn install.
Also, don't copy the POM to a different directory. Maven expects to find all of the source files relative to the POM file location.
FOLLOW UP
Thanks for advice. I was not able to use the command mvn install as it gave errors.
Probably because you hadn't checked out the source.
I don't know how to check the source tree of the project ...
Use a subversion client (the svn command for example), or one of the Eclipse subversion plugins.
If this was a properly documented project, there would be clear instructions on what version control and build tools you needed, how to checkout the source code and how to build it.
... as I thought POM itself should have this information to automatically checkout if the source is not check out.
It doesn't necessarily, though in this particular case it does.
Anyway I was able use Eclipse to build the project without errors.
(Other readers can read #icyrock.com's answer for links to the m2eclipse plugin and documentation.)
The only problem is the dependent jars were downloaded but hidden deep paths in .m2 repository folder on my linux box.
But I would like these dependent jars to be relative to dir where POM file is.
Sorry, but that is not the way Maven works.
The ~/.m2/repository directory is a fundamental part of Maven. It is not a problem. It is a feature. (Don't fight it!)
If you want to open this within Eclipse, you need to install m2eclipse:
http://www.eclipse.org/m2e/
and then import the project as a Maven project as described here:
http://books.sonatype.com/m2eclipse-book/reference/creating-sect-importing-projects.html
Try out their getting started guide. It has a lot of good examples:
http://maven.apache.org/guides/getting-started/

Automating build process for a web application created in Eclipse

I have an eclipse Tomcat project that has several dependencies on other eclipse projects.
For example imagine the main project is called server and has several dependencies:
server
(depends on):
data-lib
server-utils
messaging-utils
Currently every time I change data-lib,server-utils,messaging-utils I have to recreate the .jar file and copy it into WEB-INF/lib directory of server. At that point I export the server as a .war and deploy to my server.
I want to make this process work from the cmd line using ant (note I know maven is out there but I know ant pretty well from past experience so would prefer sticking to it for now). Its easy enough to create the build file for server -- it will end up creating a .war file. But I want it to automatically build the dependent libs. I want to do this while preserving my development workspace in Eclipse.
What is the easiest and cleanest way to do this? Currently my thought is each individual project will have its own build.xml (i.e. data-lib/build.xml , server-utils/build.xml , etc). I will have the server/build.xml do an antcall to these individual build files and then copy the jars to the server/WEB-INF/lib directory.
Is there an easier/better way?
if you want an Ant based script, I would go with Apache Ivy. The basic idea is that each of your submodule has its own build.xml file and publishes (via Ivy) their "publications" (like a Jar file) to a repository on the file system. The other modules then import these "publications" to build the final product.
I am not sure if it can help you, but in your WAR project, right-click on it in Package Explorer, and click on Properties.
There is a "J2EE Module Dependencies". In this option, select all of the dependencies (i.e. "data-lib", "server-utils" and "messaging-utils").
Now, when you modify a Java class in one of the dependencies, Eclipse will recreate the JAR file and deploy it directly in the WEB-INF/lib of your web application.

Categories

Resources