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.
Related
I am setting up websockets with my Java j2ee servlet application. I was able to write the entire code and got the websockets working using following maven configuration -
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>
My implementation does not work without <scope>provided</scope> and gives handshake exception: 404 not found.
Now, when I deploy my application on dev machines using travis, it gives exception while creating a build, and throws Java exception that ServerEndpoint class not found. I am assuming that it is because since scope is provided, Travis is not downloading the required jars while building a build on travis.
How do I avoid this, and ensure that we are able to work on local as well as deploy our builds via travis.
I have used elastic search in nodejs. But now for a java app I need elasticsearch. So I read the documentation in elastic search official website. But I cant follow one thing
I have installed Maven plugin in Eclipse.
I have done dependency setup in pom.xml in my project.
<dependencies>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.5.0</version>
</dependency>
</dependencies>
But whenever I write below line in java it says cant resolve.
import static org.elasticsearch.node.NodeBuilder.*;
So I'm unable to use elastic search in java.
I have read this as source
https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/index.html
http://java.dzone.com/articles/elasticsearch-java-api
I am not sure what you are doing here, you shouldnt have to download the jar manually and add to eclipse as a project dependency. Please go through this tutorial to understand how maven dependency works. Relevant text below:
Maven connects to remote repositories (or you can set up your own
local repos) and automatically downloads all of the dependencies
needed to build your project. For example, lets say you have a project
that uses Apache's Camel routing tool, version 2.10.6, but a new
version of Camel is released, 2.11.1. Instead of having to go to
Apache's website, download the 2.11.1 distribution and replace 2.10.6
with it, you can just tell Maven to use the new distribution and the
work will be done for you.
I have a requirement where i have two develop two projects, one with EJB2.1 and one with EJB3.x.
The EJB2.1 will be an extension to an existing project hence the reason it is v2.1 and cannot be migrated to 3.x just yet.
Both projects have to be built using Maven and this is where i am struggling. Believe it or not, i have spent the last 3 days trying to find a simple example of a stateless EJB project built using Maven but have had no luck.
Here are a couple of pointers i found through googling but none of them work.
Create project using Eclipse
Eclipse allows you to create an EJB3 project. Latest versions dont allow you to create EJB2 projects. Also, you cant create a Maven EJB project.
Use the maven archetypes.
I have tried the following archetypes in Maven but none of them work
ejb2-j2ee13
ejb2-j2ee14
ejb-javaee6
ejb-jee5
ear-jee5
ejb-jee5
The above archetypes are only for EJB3 or for those that are for v2.x there will be some dependencies missing.
Jboss sample projects
I also found the following tutorials on the Jboss documentation http://anonsvn.jboss.org/repos/jbossas/projects/ejb3/trunk/docs/tutorial/reference21_30/. I intend to use the EJBs on Jboss v5.1. The projects on this URL are Maven projects but they also complain about missing dependencies (The ant build does work).
If anyone can point me to where i can download a vanilla "Hello world" maven project for both EJB2.x and EJB3.x (That would run on Jboss 5.1.x) i would really appreciate it.
I have spent so much time on google and have finally decided to ask here as i am not getting anywhere. I suspect that maybe they are making it difficult to find these dependencies as they dont want people to use EJB2.x anymore. The problem is some people have no other option.
you really dont need the archetype for Java EE5, or JEE6 there is so little boilerplate code, that all you need is a regular java archetype and add the dependency for
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
or
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>5.0</version>
<scope>provided</scope>
</dependency>
add your beans.xml and you are done. Avoiding any JBoss depdencies is actually a good practice, as this ensures your application remains portable.
Note: If you want to mock or use any classes from the respective javax.XXX packages, you will need to include your application server specific dependencies into your maven test scope. This is because Sun/Oracle altered the bytecode of the API jars, to guarantee nobody accidently uses these classes, instead of the ones provided by the server.
I have two projects in eclipse:
framework: A general library used in several projects.
client: A project that uses framework.
client is quite large, possibly larger than framework at this point. I am using client as sort of a test fixture for framework. I want to make a few changes in framework and test them in client. Currently, I have to do a full build of framework, install it into a maven repo, and then rebuild client.
Is there a way to just have client point to framework directly on my local disk? Any other hints for developing in such a situation (ie is the a better way)?
Running mvn install on Framework will build it and install it in your local Maven repository (that is, the Maven repository on your local disk). When you run your tests in Client, Maven will automatically use the version of Framework in your local repository.
You can specify dependencies from the local disk using <systemPath> like so:
<dependency>
<groupId>example.logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/commons-logging.jar</systemPath>
</dependency>
I'm not sure if you can point to a directory that has a pom in it, but at least you don't have to deploy it into maven.
The m2eclipse plugin is fairly intelligent about Maven dependencies. If you have the framework dependency open as a separate project in Eclipse, I think it should use its code for client rather than the version in your repository. You might need to tweak your project settings if you're already using m2eclipse and it doesn't do this.
Is there a tutorial somewhere which shows how to use spring framework with maven instead of ant? This one seems very good but it's all built with ant.
EDIT
I really don't know which answer to accept both are valid. I'll wait for some time let the community decide
Basically, the build.xml of the tutorial has 3 main targets :
build the application
deploy it on Tomcat server
Unit testing using a in-memory database (hsqldb)
Regarding the first point, you will just need to create a war project on Maven. As you told in your comment, you are already using Maven in anothers projects, so I don't think it will cause you lots of troubles. You will just need to add the Spring dependency:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.2</version>
</dependency>
The second part concerns the deployment on Tomcat. Just use the cargo plugin for that.
For the last point, you will just need to add the HSQLDB dependency in your pom.xml:
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.7</version>
<scope>test</scope>
</dependency>
Then, you will have to instanciate the database in one of your JUnit test case...
If you already know maven, then you can quickly start working with spring using this archetype
appfuse-basic-spring
Note that it sets everything up for Spring MVC, Spring and Hibernate so you should remove unnecessary files. Still, it's a great start.
If you don't know much about maven templates check this URL that explains how to use archetypes. An archetype is basically a project template.
The complete list of templates can be found here.
The Spring 3.0 samples are Maven based:
https://src.springframework.org/svn/spring-samples/mvc-basic/trunk/
https://src.springframework.org/svn/spring-samples/petclinic/trunk/
https://src.springframework.org/svn/spring-samples/spring-travel/trunk/