Eclipse Web Service Client Project Type? - java

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.

Related

Cannot add application insights bare api to java web application

I added all the jar files of application insight sdk for java in java web project and included the code for sending custom telemetry in servlet but when i try to run the servlet it shows classnotfound error for TelemetryConfiguration and TelemetryClient.
Per my experience, I think you can try to check the jar files of Application Insight SDK for Java whether be added the Libraries of Java Build Path, please right click the prject name and select the Properties in the menu.
If using Maven project, you can see the jar files in the Maven Dependencies.
If using the normal Dynamic Web Project, you can see them in the Web App Libraries or a User Library with custom name.
Then you need to try to manually build the project, and run the servlet again.
It seems that you added only the web library without the core library, which contains the TelemetryClient class.
You can read the Application Insights Java SDK article which describes in details how to add the Java SDK to your web project, whether you're using Maven or Gradle as your build system, or manually downloading and referencing the libraries.

How to create a servlet in an existing package of a project

I have a Client-Server (Client and server are seperate projects in eclipse) system setup in Eclipse(Mars) I now need to create a servlet in a new package on the client project.
when I am creating a class and trying to extend HttpServlet to it I am getting an error saying javax.servlet cannot be resolved.
When I am trying File->New->Servlet I am being able to create a new Project altogether but unable to create a servlet in the existing project.
How should I resolve the issue?
You need do set up the "Java Build Path" of your project.
In eclipse, right-click on you project, "Build Path / Configure Build Path"
and there, in "Libraries" tab, you need to add a server runtime, that should contain servlet-api.jar
Servlets are the Java platform technology of choice for extending and enhancing Web servers. Servlets provide a component-based, platform-independent method for building Web-based applications
See :
Java Servlet Technology
Java Servlets Tutorial
So when you try to create a servlet, it should be a separate project....its a web project.

Deploying GWT app with own external library

I have a GWT project [com.bob.gwt] that uses another library of my own, [com.bob.domain], which is used by both in the client and server. The domain project is exposed via gwt.xml project in com.bob.gwt.
When the server runs, it indicates that some Server classes from com.bob.domain could not be found in the web app, but were found on the class path and added. The WAR directory doesn't have the .java or .class files from com.bob.domain.
The com.bob.domain is added as a library in the Java Bulid Path Window's Projects tab, and also checked on the Order and Export tab in Eclipse. Do I have to set com.bob.domain as a jar and import that jar in com.bob.gwt? Can I just include the domain source in my gwt project so I can debug all at once without having to manually build a jar, and have everything in my WAR folder ready to go for deployment?
During development, it's convenient to use Eclipse's project reference mechanism instead of rebuilding "domain.jar" every time. In that case, it's safe to ignore GWT's warning.
When you perform the "real builds" outside of Eclipse (which I would strongly recommend), you usually can't make use of Eclipse's project reference (except maybe if you're using Ant4Eclipse), so you'll need to tell the GWT compiler (gwtc), and the server side compiler (javac), where to find everything they need, including the domain project's files.
Then, for deployment, you'll need to put "domain.jar" into the "WEB-INF/lib" of your war.

Building a Java EE 6 project, with a swing client using Maven

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.

Java Web Project referencing another Java project

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.

Categories

Resources