I am pretty new to Maven and I have the following question when I shall:
Build a web application (Java EE 6) and use web-services. If I use one of the maven arcetypes I get a src/java/main & src/java/test and a web app folder. This is packaged as a WAR, but can I use webservice API when the package is WAR? How do you use Maven when you want to use all API's and create a web app?
Not sure I'd I understand your question, but the archetype you use to create the project is of no importance. It is a simple way to create some of the artifacts that is needed.
If you want to use Webservices add the appropriate dependencies (most likely scoped as 'provided' since your container will already supply the implementation.
If you package it as a WAR you will not be able to use the full EE stack (only servlets) unless you're deploying to a EE6 compliant application server.
If you want to use EJBs and REsource Adapters you need to package it as an EAR (EJB supported in WAR as o EE6 as mentioned above).
I think there is an archetype for a "full" EE application as well if you want more modules and packaging :)
Hope it helps.
Related
I am developing a project(Spring+Hibernate+Maven+Intellij Idea for develop) without any application server such as tomcat. Now I don't know how create Web Service from my project to use it in other projcets ?! My Question is how to create Web Service from jar file that created by maven?
You can embed Jetty in your application or use Restlet which provides an embedded server.
Simply add them as dependencies and have all the resolved jars on your classpath (the maven assembly plugin may help you package your application)
So I am working on a project whereby we needed to create a custom Tomcat Realm implementation to read authentication credentials from a mongo backed datastore.
This has been pretty painless, but the implementation we have come up with has several dependencies on external libs i.e. scala libs, the java mongo-db driver, spring, salat (a mongodb ORM) etc....
Now in order for Tomcat to use this Realm we must deploy our Jar (and all the dependent jars) to tomcats lib folder.
Being pretty new to Java, I have no idea how much of an issue this is, but it doesn't seem nice to me. So really, my question is what issues would I have with dumping a load of JARs into Tomcats lib directory?
Cheers, Chris.
Most likely dependencies will become a problem. All JARs you place in tomcat/lib are visible to the WARs you deploy at a later time. I suppose your Realm implementation is the base for one or more web applications.
Let's say your Realm depends on Spring 2.0 and you're required to place those libs in tomcat/lib and afterwords you deploy a WAR using Spring 3.0. The WAR will see all classes available in tomcat/lib - the Spring 2.0 classes. So your WAR ships the 3.0 classes in WEB-INF/lib, at runtime it can see the Spring 2.0 libs in tomcat/lib as well as its own Spring 3.0 libs in WEB-INF lib. This is going to cause trouble...
I'm not aware of a simple solution for this, maybe you should have a look at OSGI and Tomcat integration. No question, it won't make life easier...
I am trying to recreate an existing project with Maven (any IDE is ok, but mainly Netbeans), and I'm a bit confused about the best way to do this, so any help is greatly appreciated.
Currently I have an Enterprise application with the following components:
Web application (some jsps, servlets).
Ejb project
Client project (Swing application / applet)
Common project (Contains common files used by the applet and the Web app).
The problem is the packaging and dependencies, currently the Client (Applet) jar is packaged within the Web application, so that when the web app is deployed, the users can access the applet via their browser.
Is there any similar existing archetype for this, or does it require heavy customization ?
Oh, and I am using Glassfish 3.1
Thanks in advance.
So first of all, for me it looks like you need multi module maven project. In that case there will be no single archetype that will fulfill your needs.
When it comes to "the Client (Applet) jar is packaged within the Web application" you can use maven-dependency-plugin (http://maven.apache.org/plugins/maven-dependency-plugin/) and its goal:
dependency:copy - takes a list of artifacts defined in the plugin configuration section and copies them to a specified location, renaming them or stripping the version if desired. This goal can resolve the artifacts from remote repositories if they don't exist in local.
I have a Java Project, for which I'm now creating a Web interface, using a Dynamic Web Project from Eclipse. The Web project consists of a single servlet and two JSP's. Something like this:
/JavaApplication
/src
/lib
/resources
/WebApplication
/src
/Servlet.java
/WebContent
/WEB-INF
index.jsp
other.jsp
Now, I need to reference JavaApplication from WebApplication, in order to use its classes to process web requests. What's the best way to accomplish this ? My idea is to create a .jar of the JavaApplication, containing all the .class files, /resources, and /libs. In this way, I could include the .jar in the web application, and I could have a single .war file that contained the entire application.
What do you think? How is this problem typically solved ?
Note: I don't want to convert the Java Project into a Web project.
In Eclipse project properties, add the project to the Java EE Module Dependencies (Eclipse 3.5 or older)
or Deployment Assembly (Eclipse 3.6 or newer) entry in the project properties.
This way Eclipse will take care about doing the right thing to create a WAR out of this all (it will end in /WEB-INF/lib). No other configuration is necessary, even not some fiddling in Build Path.
Under Eclipse, you can declare Project References for a given project, the web application in your case. To do so, right click on your web application project, then go for Properties > Project References and select the JavaApplication project. This should allow you to call code from the JavaApplication project from the WebApplication without having to build a WAR. This is a solution for development.
For standard deployment (outside the IDE), you should indeed create a standard WAR. To do so, you'll have to package your JavaApplication as a JAR including the .class files and the files under /resources but not the libraries it depends on (JARs under /lib). These dependencies will actually end up in the WEB-INF/lib directory of the WAR, beside the JAR of your JavaApplication. These steps are typically automated with tools like Ant or Maven.
Connecting java app to web app for development :
right click on web project :
properties>project references> add the java project you want to refer
Now in properties tab of web project go to
properties>deployment assembly> add the project manually and run the app
Consider moving up to EAR level, if your web container supports that.
The tricky part with shared code is where should the common code be put. A copy pr web application? A copy in the web container? Overdoing the "share these classes" might end up in class loader problems.
If you are creating two separate web applications refactor common java code into a separate Eclipse project and refer to it from both WAR projects.
EDIT: Apparently I have misread the problem description, and thought you asked about an existing and a new web application sharing code.
If you have an Eclipse project with your application, and another with your web frontend, then you can let your application export the necessary resources which the "Export WAR" in Eclipse Java EE can wrap up in a jar file and put in WEB-INF/lib for you. You need to say this explicitly with a checkmark in Properties -> Java EE Module Dependencies for your web project. Expect you have to experiment a bit - this took me a while to learn.
Typically you would create an API interface using remote service beans from the Java application that expose the methods that you want to invoke in the web application. You would include a proxy of the API interface with your web application that calls the remote service bean in the Java application. Remember that you will need to register the remote bean in the web.xml file.
I am writing an application that integrates Geoserver with a custom component, intended to be hosted on a single servlet engine. Both are Maven based projects, and I would like to stay in Maven land to package it all into a nice distributable. The general idea I have is to add another module to my application that packages the application itself, Geoserver and all dependencies into one nice archive.
I am aware of the maven-assembly-plugin and its capability of storing all dependencies in a target folder, but I am not sure what would be the best way to create a package that it easy to deploy. Googling for any examples has not been successful.
Extra bonus points if the module can be started via mvn jetty:run.
Have you considered packaging them into an EAR project. It will bundle a set of WARs (and jars), and allows you to specify or generate a deployment descriptor.