How to construct maven project from source code - java

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

Related

converting a Webproject into maven project structure

I have the below Web project which is working fine. I wanted to change the structure of the project into a maven project structure.
So, I modified the project to as shown below(I created a new folder called webapp under src/main and I moved the contents of the folder WebContent into webapp and I deleted WebContent folder) Now the application doesn't work although I deploy it in the Tomcat Server. What is wrong in the below project structure . Please help me out
EDIT: I wanted a maven project structure as shown below which is a standard maven project structure
If you are using eclipse (which it looks like you are), you can use the M2Eclipse plugin, which will provide a "convert to maven" utility. Simply right click the project and go to configure -> convert to Maven.
https://www.eclipse.org/m2e/
The structure you are looking for can be defined at the time of project creation in the source directory screen. If you have an existing project you will need to add a new source folder.
To do so,
Add the folders to your project.
Right click on folder > build path > use as source folder.

Maven: Missing Files in modules

I'm using Eclipse and I have Maven project with jar and war modules. I exported it to my github acc. and when I import it from Git it runs correctly but something is not like i wanted to. In my Parent module i have all the files, but situation changes in my jars and war module.
For example in src folder i have two folders, java and webapp, in war called "psy-webapp" java is missing. I read something about it, and i must change the path to let maven see all folders/files right? I'm also sending link to github project and a screenshot to see what i mean.
Github:https://github.com/jakubjaroszek/ltc
screenshot

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.

where to put jar files inside repository

I've got a Java project hosted on github. My project needs few custom .jar files to be imported. Since I was to be able to run the project anywhere, I want to include jar files inside the git repository. Is there a recommended, conventional place where jar files should be kept, e.g. lib dir of the root project directory?
PS
At the moment I'm not using Maven and I'm not considering it.
The usual case is actually a lib folder. Or webapp/WEB-INF/lib it is a web application.
But ths usual case is bad. I would not put jars in my source management system. If you need to add references to another project, you might consider having a look a git submodules (though you are using Github).

Java files needing to be hosted on SVN

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.

Categories

Resources