Cannot add application insights bare api to java web application - java

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.

Related

GWT project doesn't build server side code

I'm novice in GWT and trying to build my first GWT application.
I downloaded GWT 2.6.1 and created demo application ('mydemo') using webApplicationCreator.
It works perferct on my developer machine. Then, I want to deploy this application to production server. I installed Apache Tomcat which requires war package. Well, I created war package. But it doesn't contain file mydemo.jar with server-side code (GreetingServiceImpl).
So, I need to configure build.xml to create .jar file with server side of my GWT application. Please, help.
webApplicationCreator's generated Ant file compiles your classes to WEB-INF/classes, it doesn't package them in a JAR.
If you have an error on your "production server", I'd suggest you ask about that error and server.

how to create gwt gae with app engine modules using google eclipse plugin

How to create a new GWT and GAE project with modules using google eclipse plugin in Java? I tried using make a new web applications from the eclipse, but it just create me a GWT and GAE project without modules.
Thanks.
You'll probably want to first create a WTP project using GPE, because to use modules you'll need to create an EAR project. This is described here:
https://developers.google.com/appengine/docs/java/webtoolsplatform
You'll create modules, which will each be a dynamic web project. Your GWT app will be one of those. And follow the instructions for modules here:
https://developers.google.com/appengine/docs/java/modules/
Note that there will be two Google related items when you right-click your project: Google and Google App Engine WTP. Commands related to app engine in the Google menu don't seem to work. Instead use the app engine related commands in the Google App Engine WTP menu.
Apparently, it is an open feature request to do this programmatically:
https://code.google.com/p/google-web-toolkit/issues/detail?id=3584
and
https://code.google.com/p/google-plugin-for-eclipse/issues/detail?id=121
There is a proposed workaround:
GWT Compile and copy the /war/ output into a standard Dynamic Web Project.
I have tested this workaround and it works. Simply copy the Google Web Applications Project's "war" directory into the web content directory (default: "WebContent") of a stub Dynamic Web Project.
For the local AppEngine dev server for Dynamic Web Projects and EAR projects it is important that project names do not contain a space. Moreover, this also applies to the AppEngine agent file path, see Error opening zip file or JAR manifest missing : C:\Program.
How to create a new GWT and GAE project with modules using google eclipse plugin in Java?
Do check in each option to create project with sample code.
Use Google Web Toolkit
User Google App Engine
Sample Code : It creates sample code with module as you expect.

Deploying to Glassfish via Eclipse

I have set up a project inside Eclipse which I can debug on a Glassfish (3.1) server using the Eclipse Glassfish plugin. So when I click 'Debug on server', it uploads fine and I am able to step through the code correctly etc.
The problem is that I don't know if the program is being compiled/build (to a new .war) each time I press debug. I have got an Ant script in the project (as I previously built the project via terminal) but I'm not sure if it is actually being used in Eclipse.
Is there any way to check if my ant script is being run?
Also, how does Glassfish know what resources to upload? Does it just look for any .war files in the project?
Not sure about this particular jar plugin but as far as I know here is how Eclipse handles web applications:
Eclipse automatically compiles all of the sources in the class path
Then it creates a configuration file which tells Application Server to look for webapp on your project folder and does some mapping based
on your project setup. This will not create a WAR file. Eclipse will
just map WEB-INF/classes to {projectDir}/bin, your classpath jars to
WEB-INF/lib and so on.
When launching the Application Server, eclipse will feed it the config file made above.
Actually answering your question: Eclipse will not use the Ant script you created, nor will it create a WAR of any kind. It will just use project configuration to properly map project folders to web application structure.
Again, this is how eclipse handles things by default, the plugin you're using might do something different. This is based on my experience and is not based on some kind of documentation.

Eclipse Web Service Client Project Type?

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.

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