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.
Related
I am working on a framework "beadledom".
I am also relatively very new to IntelliJ Idea, I have used eclipse before, the beadledom framework contains the project sub-module,
api
service
client
In Eclipse if we want to run the services, I would right click on "service" sub-module Run on Server -> tomcat ; and it would run.
My webapp is stored in "service" folder.
I have no clue how do I do it on IntelliJ
I did set the Run Configuartion.
I am being asked to create a "artifact" in Edit Configuration>Tomcat
enter image description here
The artifact is an archive, built from your project sources which constitutes your application. For Java EE web projects it is usually a war achrive which you deploy to an application server (e.g. Tomcat). In case of a Maven-based poject IntelliJ IDEA automatically creates web artifact, based on Maven pom.xml configuration which then you can select to deploy in Tomcat Run/Debug Configuration Deployment tab.
You could check Developing a Java EE Application tutorial for the general workflows in JavaEE-based projects in IntelliJ IDEA.
I created a basic Java project in Eclipse then added a Web Service Client using the File->New "Web Service Client" wizard.
This generated my stubs correctly and I am able to connect to the web service, however, I get the following error/warning when I run:
WARNING: Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
I then tried to create the client using a Dynamic Web Project (instead of a basic Java project) and the error went away.
This is obviously due to the fact that the Dynamic Web Project includes libraries that are not included in a basic Java project.
My question is, why do I need to make a Dynamic Web Project (it seems like overkill) just to make a web service client? Is there some simpler project type you would recommend using?
Thank you.
Since it is just a warning, you could leave it as is. To make it go away, you could look up the jars that contain those classes and add them to your project.
I think we normally use a JavaEE project type, and that may bring in some extra library files. I wouldn't normally think you need a dynamic web project to make the error go away.
The only difference in the project type is the Libraries included automatically for you when you start them. You can start any project as a Java project and then in the Project Properties, Build Path, Libraries tab add additional libraries to the project.
Both of the missing classes above are in the j2ee.jar file, so if you can add that jar to your build path of the project it should go away.
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.
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.