Build vs Deploy vs Publish (Eclipse IDE) - eclipse

I'm a newbie to J2ee though not a complete newbie. I'm unable to find a good resource (book or video) that could help me understand what exactly happens when we build, deploy and publish. I have a fair idea though. So my questions are -
Is there a good resource out there that can help me understand these concepts? I've read some books on struts and servlets/jsp but they don't delve into eclipse and how/what it does. The eclipse documentation has been helpful but only slightly.
When we build an application the the java files are converted into the class files and stored in the java build path. What else happens during build? Many people use the term 'library dependencies', what does this mean? Also, when people refer to dependencies do they refer to files like xml and tld?
At what stage (build or run on server) does the container check to see if the dependencies are alright? Say for instance, if the servlet class/name in the web.xml file.
Is it appropriate to say that build is basically compilation while deploying the project and running it is the same as executing it?

Familiarity with the servlet specification would help you (perhaps some older version would be quicker to read like 2.4), but general understanding of what you build and how you do it in Eclipse is what you are after.
The way I see it is that during the build Eclipse creates almost complete version of WAR (or some other archive, if you use EJBs for instance) and by publishing you deploy it to some server (this is practically the same thing although Eclipse might just configure the server to use exploded WAR that it just prepared instead of copying it to some "deploy" dir that you are supposed to do if you work without an IDE).
If you configure your project well, the build can only mean compilation, but if you have more ceremony in it, then some source generation and moving files around might happen too.
To address your second question, library dependencies can be files that reside in WEB-INF/lib for instance. Read the spec to know what should be there and what should not. Eclipse tries to copy there all defined dependencies of your project.

Related

Running jersey 2 server using jetty 9

I have been struggling for many hours on trying to deploy a simple HelloWorld webservice written in java on a windows 7 (later ill need on linux) pc.
Most of the examples I found (from general places, and others questetions on stackoverflow) didn't work or used deprecated versions of jersey and other librarys.
My goal, is to write a webservice in java, where coding it should be easy and so does deploying it. It doesn't need to suuport anything special regarding the amount of request running and performance (my requirements are minimum)
Frommy research, I have come to believe the use of jersey with embeded netty web service should anser what I was looking for (if someone knows better, I would also like to hear about it, tough it isn't my main problem in this questetion but might just be an alternative solution)
I have came across this eaxmple:
jersey2-jetty-example
It gives you a working project with the dependencies needed from maven to run jersey and jetty embedded server (which can be run as a standalone jar which is exactly the kind of easy deploy im looking for)
I cloned the example and got everything running. I had problems importing it to eclipse, so I used the following command on the example folder:
mvn -DoutputDirectory=./lib dependency:copy-dependencies
which will give you a copy of the lib folder of the deps from maven needed,
then I created a java project with this lib folder in the build path and same source code as the sample, and all worked good.
The problem occurs when I try to take this java project and export it as an runnable jar (with the source files included option !).
I can then use java -jar to run the service, but when I try to access it from the browser (same as used in when I run it from eclipse), it never works, im always getting error 404 for the same routes that worked a second ago when running from eclipse. I couldn't figure out whats the source of the problem or what eclipse does differently that makes it behave in a different fashion.
I have found the reason the jar didn't work while in eclipse it did work, it was because of a duplicate jar that I was importing the caused the problem. The jars I got from maven in the git sample had 2 duplicate jars called hamcrest-all and hamcrest-core. removing one of them from the project build path fixed the problem.
If someone can answer the other open ended questetion that I asked, which is if using jersey and jetty like this is the best solution for my requirments I will be happy to hear about it

How to Create a Spring+Primefaces+Hibernate (no maven) project in eclipse?

I am new to J2EE. I would like to create a Spring+Primefaces+Hibernate project.
I googled for it.
But I found all projects examples show in internet contains maven. My questions are
Is it possible to create a spring+primefaces+hibernate project in eclipse without Maven? If no, what is need of maven?
How to add the jar file of primefaces and spring and hibernate in eclipse?
Will the spring controller xml file (spring context or dispatcher servlet) be created automatically or manually?I mean Spring MVC.
Will the hibernate file (mapping file) also be created automatically or manually?
If possible, can anyone guide me to tutorial (preferably video) to implement the same?
I am using tomcat 7 and Eclipse - kepler.
Any help is appreciated.
If this is downvoted , do specify the reason also.
Although it's not a 'must' to use Maven or any other build tool, you should strongly consider using one.Eclipse Kepler has by default maven support but feel free to use other build tools(Gradle, Ant) or none(see 2.).Maven and the other build tools remove the headache of scaffolding, searching for dependencies(external jars like spring-mvc, hibernate, some db drivers), even deploying applications in a server.
If you chose not to use a build tool you have to manually get your project dependencies and enter them
into your project's buildpath(Right Click -> Build Path then enter their location).As you have noticed this step can be really really time consuming...
No, you have to manually create the configuration unless you use another project that already has what you need, again this might get easier with a build tool(maven archetypes for example)
The same as 3.
You won't have a hard time finding resources about these technologies, they are being used practically everywhere, and I think the Spring team has some videos in their YouTube channel.
Hope that helps a little!
1:* The fundamental difference between Maven and Ant is that Maven's design regards all projects as having a certain structure and a set of supported task work-flows (e.g., getting resources from source control, compiling the project, unit testing, etc.). While most software projects in effect support these operations and actually do have a well-defined structure, Maven requires that this structure and the operation implementation details be defined in the POM file. Thus, Maven relies on a convention on how to define projects and on the list of work-flows that are generally supported in all projects.
This design constraint resembles the way that an IDE handles a project, and it provides many benefits, such as a succinct project definition, and the possibility of automatic integration of a Maven project with other development tools such as IDEs, build servers, etc.
But one drawback to this approach is that Maven requires a user to first understand what a project is from the Maven point of view, and how Maven works with projects, because what happens when one executes a phase in Maven is not immediately obvious just from examining the Maven project file. In many cases, this required structure is also a significant hurdle in migrating a mature project to Maven, because it is usually hard to adapt from other approaches.
In Ant, projects do not really exist from the tool's technical perspective. Ant works with XML build scripts defined in one or more files. It processes targets from these files and each target executes tasks. Each task performs a technical operation such as running a compiler or copying files around. Targets are executed primarily in the order given by their defined dependency on other targets. Thus, Ant is a tool that chains together targets and executes them based on inter-dependencies and other Boolean conditions.
The benefits provided by Ant are also numerous. It has an XML language optimized for clearer definition of what each task does and on what it depends. Also, all the information about what will be executed by an Ant target can be found in the Ant script.
A developer not familiar with Ant would normally be able to determine what a simple Ant script does just by examining the script. This is not usually true for Maven.
However, even an experienced developer who is new to a project using Ant cannot infer what the higher level structure of an Ant script is and what it does without examining the script in detail. Depending on the script's complexity, this can quickly become a daunting challenge. With Maven, a developer who previously worked with other Maven projects can quickly examine the structure of a never-before-seen Maven project and execute the standard Maven work-flows against it while already knowing what to expect as an outcome.
It is possible to use Ant scripts that are defined and behave in a uniform manner for all projects in a working group or an organization. However, when the number and complexity of projects rises, it is also very easy to stray from the initially desired uniformity. With Maven this is less of a problem because the tool always imposes a certain way of doing thi
2:* You have to download all required jars file for hibernate/spring/primefaces from internet and place them in your project build path or in lib folder.
3:* Spring configuration files need to be created by you so that you can get the concept.
4:* Hibernate mapping files can be created by using reverse Engineering techniques for hibernate from where you can generates hbm files or you can use annotations if you dont want xml.
I suggest you to first create a sample java project in eclipse then download all required jars and place them in lib folder. Then configure hibernate in projects and spring integration.

Dynamic web application in eclipse using MAVEN 3.04

From past 90 hours I am trying to know how to use Maven in my web project, generate a war file and deploy it into my JBoss 4.2 Server.
I am not getting.
I am reading all kinds of blogs, googling almost all time, trying out all kinds of way to build a dynamic web project with maven, but trying out different methods make a simple thing more complex.
Few examples tell me how to run, few tell me to change the folder structure, few tell me transfer the contents of web content but nothing is matching my requirements. In some of the examples war file is getting generated, but of some big name, and it does not contain the jars inside. Uff.
I know maven is easy and makes our lives better but learning it for the first time makes it complex.
My requirement is simple.
1) Build a Dynamic web project in eclipse indigo. (Preferably in JAVA perspective )
2) Enable Maven dependencies, in eclipse.
3) Update pom.xml to add dependencies.
4) Finish the web application i want to do by writing classes, html pages, deployment descriptors.
5) Build the war file using maven "IN ECLIPSE ONLY". (the WAR file must have user specific name and not some name like "V1- Snapshot dash dash dash")
6) Deploy my war file in jboss 4.2 server deployment location. (Preferably from eclipse )
7) Run my localhost server and my application from the browser.
And Done.
By spending time on it I am understanding how beautiful is maven, but I am not able to achieve what I want.
Please help me by giving me a detailed procedure on how to use maven to meet my requirements above.
Fist I would suggest to use the newest Eclipse (Juno) with Maven support (m2e and wtp-m2e).
The first step is to define your pom with the appropriate dependencies and the correct packaging type which is in your case war.
If you really need a different naming you should leave Maven, cause maven makes assumptions about the naming of your artifacts which usually isn't a problem. The default version patterns as 1.0.0-SNAPSHOT etc.
If you wan't to deploy the war into JBoss there exist a number of possibilites to do such things and if you like to run your application locally it sounds you wan't to do some kind of testing (integration testing) which is supported by Maven (see maven-failsafe-plugin).
Furthermore you must learn if you like to use Maven to understand that not Eclipse is anymore the leader of the project configuration. This job has been moved to Maven or in other words into the pom file. If you like to use the project in Eclipse you need to import this project into Eclipse.
Apart from the above i would suggest to go to a Maven training to lear all that stuff which is more effective than learning it yourself.

ant deployment issues

i am looking to make our deployments here not suck and i need some help, if you can help me with these few things i owe you beer
right now whenever i make a change thats not to the jsps i need to clean-including-tomcat otherwise my change doesnt take. this is really annoying.
any clues as to what i can change to make it work?
my current build is really simple, just the regular old, javac, war, deploy
one thing that isnt done is that there is no build dir, the project itself contains a web-inf and the javac is done in place, then the war excludes all the .java resources and wars the project.
edit:
I am looking to fix this problem with least amount of effort - so while switching to maven and learning how to use it might solve this problem, but it will create another problem ;)
You've already identified some of the weaknesses, in your current build.
The easiest way that I can suggest to clean it up would be to start with the directory structure.
I highly recommend using the maven directory structure, I would go further to suggest using maven as a build tool instead of ant, however for some folk that remains open for debate.
The maven directory structure has been well thought out, I really like working on projects that use the maven directory structure, because they follow a convention that allows me to save a lot of time, by knowing from previous experience where to find the application components
java source
unit test source
resources etc.
Also by following the convention, the maven plugins work with less configuration required.
Another useful advantage that I get from working on maven based projects is good code metrics, to measure the health of the application. There are various report available as maven plugins, which will give you new insight into your codebase, including:
checkstyle
pmd
findbugs
and more.
Created a build directory where everything got copied before build
Added some flags to not copy over things that rarely change, like images (also to not remove them on clean)
Started using ant-reload task after deploying code
Now i don't need to restart tomcat on every build, and build takes much less time.

Set up an Eclipse Dynamic Web Project referencing another project

I've got a simple Dynamic Web project set up in Eclipse 3.6 Helios, but am having trouble getting it to make use of the code in another project that I've got.
I've added a reference to my other project to the build path of my web project, and I've got no problems in terms of compiling, only in terms of deploying and testing the result. The built web application doesn't have a jar in the WEB-INF/lib directory, so fair enough it can't find the code. The question is how I set this up. I've looked through the help that I can find and googled a bit but can't find anything obvious that helps out.
How do I set up my web project so that on deploying it it magically has the code from my dependent project inside it?
Thanks.
Note: Ideally I'd like a solution that doesn't involve setting up some kind of build tool. The web project deploys itself without recourse to any build tool (or at least none visible to end user), so was rather hoping that a references project could be integrated into that easily.
What goes in the deployment is determined not by the build path but by the Deployment Assembly entry in Preferences for the dynamic web project.
Use some build tool like ANT or Ivy or Maven that, on build, copies all the dependencies to WEB-INF/lib
Using a build tool is a good practice to automate build, test and deployment. You may also be interested in plug-ins like Maven Reactor.