converting a Webproject into maven project structure - java

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.

Related

There is no java resources folder in my eclipse maven project

In my eclipse maven project there is no java resources folder like this.
When I create my dynamic web application there is no java resources folder in it. I tick the Generate web.xml deployment descriptor at the end also but there is no Java resources folder. Can you resolve my problem?
This is my project explorer. Can you see there is no java resources folder.
Which eclipse version are you using? I am using the newest stable version and the tree node "java resources" does not appear. It might have been called like that in older eclipse versions but I am not sure. The important thing is though, that you should have a tree node for "src/main/resources" or at least a hierarchical structure like
src
main
resources
You can also compare your structure with a sample project which you can create from maven archetypes. Go to File > New > Project > Maven > Maven Project > Next > and select one of the sample archetypes like maven-archetype-webapp > enter an artifact name and finish. Now you can see how it should be displayed in eclipse correctly.

Convert Maven Desktop App to Dynamic App in Eclipse

I have a Maven based desktop App and I have to convert it to a dynamic web app in eclipse or any other IDE ( I am using Eclipse Neon-Java EE).
I have tried with Project Facets (Right click on project name --> Properties --> Project Facets --> dynamic web app) It generates some files but it doesn't seem to be converted to web as in the project folder still appears the letter "M" and not the golobe icon. When I try to run it in Tomcat it doesn't work.
Project Folder
Any suggestion?
Thank you
Look into the project if you have the Maven convert option...
If not, you should check the property of the project, and change them manually, starting from the Deployment Assembly, the target runtime, check all the facets..
Then take a look into the folder of the project, into .classpath and .project and see if they have been refreshed by Eclipse, the pom should package as a war and so on...
The problem here is that you are fighting with Maven and Eclipse togheter, so my main suggestion to do this in lees time, is to create a new Dynamic project and then to copy and paste all the previous Desktop project.. you can do this in a lot of ways...
Or directly from the IDE, or simply by hand than importing again the project...
Let me know if you try one of the above suggestions :)
Moreover obviously after all of this it won't start in tomcat, you have before to configure your web.xml and so on... but at least your structure will follow the Dynamic Web Project structure standards..

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

Difference webcontent and webapp

I've two Spring MVC projects in Eclipse, but the web content is in different positions.
In one app it's located under:
/WebContent
In the other app under:
/src/main/webapp
Why that? What's the difference?
Is there any way I can see how each project was created in order to create a new one in the same fashion?
Project directory structure depends on how it was created and the build tool which you are using.
If you create by selecting File -> New ->Dynamic web project in eclipse, then you find the /WebContent directory.
If it is created using Maven, directory strutcure will be /src/main/webapp.
Please go throuh here for more information on Maven project strutcure.
If someone like me messed up with the project and ended up with both folders but wants to keep the maven structure just disable/re-enable the Dynamic Web Module facet and configure the content directory
Finally, delete the WebContent folder.

creating a jar for a project in Eclipse

I am using Eclipse and I have just started working on a project that needs another project (say pjkt) to function. The pjkt project files are stored in a specific folder. I would like to create a jar from pjkt and then add this jar to my project buildpath. How do I do this? Do I need create first in Eclipse a new project from the pjkt code, build it and then select the export command?
Yes create a new project and export as .jar.
To answer the question about the build path:
Create a project directory (in the using project) for library files - it's common to create it in parallel to /src and /bin and call it /lib;
Once you've created (by exporting) your jar from the used project, copy it into the /lib directory;
If you did any of this creating and copying outside of eclipse, refresh your project so everything will show up in the Project Explorer;
In the Project Explorer, right-click on the .jar in the /lib folder and do "Build Path | Add to Build Path".
Done!
If you need to work on both projects, and have them open in Eclipse at the same time, another approach is to open Properties -> Build Path for the new project, and add pjkt on the Project Dependencies tab. This will provide all the exported resources from pjkt to the master project.

Categories

Resources