Java 15: Make a Maven Project of jaxws using tomcat10 embedded - java

I try to make a java 15 maven project of a jaxws webservice using a embedded tomcat 10.
My current project is on https://github.com/BeRoots/MeteoWS/tree/master/src/main/java
I'm not sure it's a good idea to make this project using the cargo-maven2-plugin instead of building this project from an Axis2 or CXF Java-First SOAP archtype. But I want to preserve this way if it's acceptable. More informations about this choice are welcome ;)
To explain my actual problem. I have an error when I run maven:build with the error:
SEVERE: Error configuring application listener of class com.sun.xml.ws.transport.http.servlet.WSServletContextListener
java.lang.NoClassDefFoundError: jakarta/servlet/ServletContextAttributeListener
If someone have an idea. Thanks in advance

We just faced the same problem and the solution was adding jakarta.servlet-api to the project:
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
</dependency>

After a lot of searchs. I finally find a good answer about server uses. It explain that tomcat isn't a good server for this kind of project.
Difference between an application server and a servlet container?
and
enter link description here
So I choose to abord this maven project type to recreate a new one using glassfish.

Related

LWM2M implementation on Spring boot java application

We have an application on java springboot which would interact with IoT devices via HTTP Rest API. However, there is an IoT device that communicates with the LWM2M protocol. So, I need to set up an LWM2M server and make the application an LWM2M client.
First I wanted to make a prototype on my local machine running application on Windows with eclipse ide. I tried importing the Leshan project from this link on eclipse workspace. However when maven clean install, it is not creating a jar file for every project. Attaching the result at eclipse console, when I do maven clean install..
My ask is:
Am I going the right way, in order to implement the LWM2M protocol locally?
How to resolve all jars not creating with Maven clean Install.
Our commercial LWM2M offering that is part of Cumulocity IoT in fact is a Spring Boot application which includes Leshan. So you are definitely on the right track.
While I am not able to disclose internals, I am happy to provide you some pointers how to get this flying.
In your pom.xml, declare the needed Leshan dependencies, for example:
<dependency>
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-core</artifactId>
<version>2.0.0-M9</version>
</dependency>
<dependency>
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-server-core</artifactId>
<version>2.0.0-M9</version>
</dependency>
<dependency>
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-server-cf</artifactId>
<version>2.0.0-M9</version>
</dependency>
<dependency>
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-server-redis</artifactId>
<version>2.0.0-M9</version>
</dependency>
<dependency>
<groupId>org.eclipse.californium</groupId>
<artifactId>californium-core</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.californium</groupId>
<artifactId>scandium</artifactId>
<version>3.7.0</version>
</dependency>
I assume you know how to set up a Spring Boot application using maven. If not, this tutorial shows precisely how it can be done.
In your spring boot application you then can construct a LeshanServer object and accept LWM2M traffic. Have a look at the leshan-server-demo maven module in the Eclipse Leshan source code on how to do that.
Questions about build issues get much better help and answers, if you use Eclipse/Leshan - github issues. Not all open-source projects are watching stackoverflow and so you can get a "first hand first class" answers only there.
I have skipped the integration testing by commenting its dependency in the pom file. Then all other modules got compiled.

Tomcat can't find JSF API in a JSF webapp built by Maven with javaee-api dependency

I have searched many similar posts, however I cannot find a definitive answer on the correct way to build and deploy JSF applications, therefore I'm hoping someone can help...
Currently I am using Eclipse with Maven to build a simple JSF application and deploy it onto Tomcat 7, with one dependency in the POM.xml of:
<dependency>
<groupid>javax</groupid>
<artifactid>javaee-api</artifactid>
<version>6.0</version>
</dependency>
When I deploy onto the server I get:
java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListener
I cant figure out where this is coming from? I have no listeners defined in web.xml.
If I then change my dependency to:
<dependency>
<groupid>javax</groupid>
<artifactid>javaee-api</artifactid>
<version>6.0</version>
<scope>provided</provided>
</dependency>
And attempt to run the application on the server I get:
java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet
Which I can understand because I am now using scope as provided and thus it expects Tomcat to have the implementation and it cannot find it.
Finally if I drop javax.faces.2.1.13.jar into tomcat install dir/lib folder it works fine.
The javaee-api-6.0.jar imported using the Maven dependencies seems to contain the same javax.faces.* classes as the javax.faces.2.1.13.jar, therefore can anyone tell me why this doesn't work when I try and run the application on the server without scope as provided?
Although it works when having the javax.faces.2.1.13.jar in the tomcat install dir/lib folder, is this the correct way to deploy a faces application?

Adding Richfaces to Maven based project

Good evening,
Currently I'm trying to add Richfaces to a Maven based project in Eclipse. However, when I deploy my application (Glassfish) I get the following warnings in my browser:
Warning: This page calls for XML namespace h++p://richfaces.org/rich declared with prefix rich but no taglibrary exists for that namespace.
Additionally, I get no error messages in my console.
In Netbeans, I had the same problem when trying Richfaces the first time. However, I was able to solve this by doing Right-click on the Dependencies folder in my web project, and then selecting Download Declared Dependencies. However, I don't have this option in Eclipse.
The project in Eclipse uses JSF 2.1 (Apache MyFaces 2.1.5). The dependencies were added as follows:
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-api</artifactId>
<version>4.2.2.Final</version>
</dependency>
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-ui</artifactId>
<version>4.2.2.Final</version>
</dependency>
<dependency>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-api</artifactId>
<version>4.2.2.Final</version>
</dependency>
<dependency>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-impl</artifactId>
<version>4.2.2.Final</version>
</dependency>
Although this code worked fine in Netbeans I also tried following the advice on:
https://community.jboss.org/wiki/HowToAddRichFaces4xToMavenBasedProject
https://community.jboss.org/wiki/MavenGettingStarted-Users
However, the problem persisted. Any ideas why this is happening?
This looks as though Maven hasn't downloaded the dependencies into its local repo. The easiest way to do this in eclipse is to use the m2e plugin. Once installed, right click on your project and select;
Run As > Maven Clean
which attempts to clean a project's working directory of the files that we're generated at build-time. You can read about it here: http://maven.apache.org/plugins/maven-clean-plugin/
The again do right click on your project and select:
Run As > Maven Install
which is used to add artifact(s) to your local repository. You can read about it here: http://maven.apache.org/plugins/maven-install-plugin/
Try deploying that to your server, and it should'nt moan about missing dependencies. Also I suggest once you're happy with the concepts of maven, to get familiar with using it from the command line. Good luck!
Here's a short cookbook approach I found worked after about a dozen promised simple JSF Get Started. I have a target dictated by other areas of a project. Netbeans and no big server (e.g.) Glassfish, JBOSS. I want to start with Tomcat and migrate to an embedded server. I expected the problems with the migration. It has taken about 4 days off and on to find an example that works. Start here:
Getting Started With RichFaces 4
It is really disappointing because exact same demo took 30 min AngularJS. The first problem is there's no ready examples that run. People writing these projects just want flash examples that don't explain the basics. Secondly there's not much (virtually) nothing that works when you do it with Netbeans 8. So be prepared to hack about at first until you find what works for you.
So far I got Netbeans 8 and Tomcat 8 to run this example. I'm happy enough but there's still an error on starting. The index.xhtml works OK, so I'm counting a 'win'. If you are on Windows, you may wan to edit this on one line.
mvn archetype:generate \
-DarchetypeGroupId=org.richfaces.archetypes \
-DarchetypeArtifactId=richfaces-archetype-simpleapp \
-DarchetypeVersion=4.0.0.Final \
-DgroupId=com.jasmineconseil.samples.richfaces4 \
-DartifactId=richfaces4-start
This generatd doesn't completely work. It flounder on a missing resources/ folder. Odd since it was responsible for generating the resources folder imho. I made the resouces folder and re-did the generate. That at least gave me a POM file. Oh, yes, I'm using maven 3 if that helps people.
I moved to the project directory, and the next step of installing the POM:
mvn install
That also did some stuff and failed. Something to do with a compile. At this point I shifted to Netbeans. The POM file doesn't load as a project, I had to click on the "resolved problems" menu choice.
When I clicked resolve, most of the issues went away.
Next, Project Properties. The main thing was to set the Java version (1.8 on this project). Set the Tomcat server of choice. Check the component libraries and ensure RichFaces is ticked.
Click build -- It builds. Click Run/Debug ... If your Tomcat install is all set-up, it works! With a runtime error from Catalina. Still the web page comes up and the error doesn't display after that (so far, so good....)
13-Aug-2014 00:04:11.058 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/hellojsf]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:702)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:697)
....
I haven't looked at that yet. There are notes on JavaHotChocolate about different kinds of poblems with Jars and errors. I'm hoping I'll come across something or I'll be back here with a question on the error.
You may also find these useful to unravel the ball of wool.
RichFaces for JSF use ... this site is VERY good, the author is taking time to explain what's working (for him)
RichFaces Developer's Guide
JSF 2, Maven and Tomcat 7 ... This was to be my next example to build.
Netbeans warns blacklisted repository declarations for "http://download.java.net/maven/2" in pom.xml. How to deal? [Update]
Gotcha ...
Some things I found with Netbeans(?) especially after a clean or closing Netbeans and reopening the project.
Wants to change my server / Tomcat setting
Wants to change RichFaces (uncheck)
Standard maven plugins are missing their version number (this is a warning now, soon an error)
Also take a look at your Maven setting.xml file (see JBOSS manual).
Change the URL for java-net repository as shown: Netbeans warns blacklisted repository declarations for "http://download.java.net/maven/2" in pom.xml. How to deal? [Update]
Ensure Tomcat Catalina deployment folder is 'clean': $ tomcat\conf\Catalina\localhost [Update]
Hopefully some of the people looking on this topic can take one step forward with these examples. Bon chance!

how to include javax.jms.* in eclipse?

Iam trying to implement JMS using eclipse.But when I tried to save the code, it showed that javax.jms.* cannot be resolved and there are no suggestions as well recommended by it.
How can I include it and use it? when I googled I found that javax.jms.* is not a part of java API,then how can I use it in eclipse and get my program run successfully?
I would like to implement JMS with the help of activemq,what all do I need to download and include in code?
Iam a newbie to this JMS, please suggest some references or sample code that can implement JMS using activemq.
When you download the activemq archive file from Internet. Extract this archive: /apache-activemq-x.x.x
cd into this apache... directory.
You will see activemq-all-x.x.x jar file.
Include this in your build path.
This should resolve your issue.
If it is a maven project, add the following dependency to your pom.xml and it should start working as expected.
<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
<version>1.1</version>
</dependency>
There are actually many ways to fix this. As already stated in the comment you need the Java Enterprise Edition API. Java EE is an abstract specification so what you need is an implementation of the JMS API. Since JMS is part of the Java EE specification the easiest thing is to download a application server such as GlassFish (which is the reference implementation) or JBoss.
I assume you already got the Java compiler so you only need the SDK, not the JDK.
Java EE 6 SDK Update 4 A free integrated development kit used to
build, test, and deploy Java EE 6 applications.
http://www.oracle.com/technetwork/java/javaee/downloads/index.html
Then after you have downloaded GlassFish you will end up with a lot of files that is an implementation of the different Java EE specification API's. You will probably want to download the plugin that I linked to beneath so that you can start, deploy and do many other administration task of your server from Eclipse. I do not use Eclipse so I don't remember if you want this version of Eclipse as well.
http://marketplace.eclipse.org/node/867
At last you want to add GlassFish to your buildpath.
I found this blog post (Scroll to "Create projects in Eclipse") if you are unsure what to add, but there are several blog posts on how to add GlassFish to the build path in Eclipse so I won't list them here.
http://www.webagesolutions.com/knowledgebase/javakb/jkb005/index.html
In addition to the answers already provided, if you are using Maven you can add the following dependency (available from Maven2 Central repo):
<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</dependency>
When you have downloaded activemq zip file from http://activemq.apache.org then when you extract it, head on to .jar file of activemq(This jar file is required). Now from Eclipse do as follows:
RightClick on Project and go to Properties
Java Build Path tab
Libraries tab
Add External JARs...
Get that .jar file from activemq folder
I fixed this problem by including the dependency of Activemq.
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.15.0</version>
</dependency>
It can be found in jboss-jms-api.jar
If you are using/Testing ActiveMQ.
Then configure your build path and add external jar activemq-all-.jar. (Path:In )
Clean and Build.
This will helped me , will do same to you as well.
Danke,
Rahul.
If you want to resolve this issue using maven, then the correct maven dependency, available in maven repository, is the following:
<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms-api</artifactId>
<version>1.1-rev-1</version>
</dependency>
See post: The following artifacts could not be resolved: javax.jms:jms:jar:1.1

Assistance need to get Spring MVC project going with IntelliJ IDEA

So I downloaded a trial of idea ultimate, and I want to get spring mvc going with tomcat.
So I setup a new project, configured it to use sun jdk.
I chose a spring application, and it created and downloaded the following:
I don't see any spring-mvc libraries, are they included in there or do I have to do something about that?
Can someone outline what I have to do to get this to build like a spring mvc web application?
I find that the best way to start a new IDEA project is to use the Maven. This allows you to easily build your project without launching the IDE, automatically maintaining all libraries for you.
"Create project from scratch", then select "Maven module" in the next screen. Click on "Create from archetype" and select the "maven-archetype-webapp". This will give you a basic Maven layout which builds a simple WAR file.
Now to add the Spring libraries, open the Maven build file - pom.xml - and insert a new dependency on the Spring MVC framework:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
From here, you can follow the Spring MVC reference documentation - add the Dispatcher Servlet and Context Listener to web.xml, a Spring XML context and so on.
Something else you might find useful is the Maven Jetty plugin. Once configured, you can run your app by simply typing "mvn jetty:run" at the command prompt (or launching it from within the IDE). Maven will fetch all that's required and deploy the app for you, no need for an external app server setup for quick testing.
I'm not sure if your setup would be identical to mine, but when I downloaded spring-framework-2.5.6 there were jar files named spring-web.jar, spring-webmvc.jar, etc. in the \dist\modules subfolders. The tutorial indicated at least spring-webmvc.jar should be in your WEB-INF/lib folder.
This tutorial optionally used eclipse, but might be helpful anyways, especially getting started:
http://static.springsource.org/docs/Spring-MVC-step-by-step/
I think there are specific JARs for the Spring MVC stuff. Basically when you download the latest Spring Framework and you extract the zip you need to go to the dist folder and add the org.springframework.web.jar and org.springframework.web.servlet.jar/org.springframework.portlet.jar to your project. I'm pretty sure that the servlet/portlet jars will have your MVC specific classes.

Categories

Resources