I am working with Microsoft Device Twins tutorial available here. Using maven 3.5.0 and java 1.8.0_144.
My service app is building without any errors, but the problem is with a device app.
After copy-pasting code from the tutorial and trying to build the project with command "mvn clean package -DskipTests" I receive this error:
cannot find symbol
[ERROR] symbol: class DeviceTwinStatusCallBack
[ERROR] location: class com.mycompany.app.App
There is my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>simulated-device</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>simulated-device</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.azure.sdk.iot</groupId>
<artifactId>iot-device-client</artifactId>
<version>1.3.33</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
DeviceTwinStatusCallBack isn't available on Microsoft Azure documentation. Anyone has any idea?
Problem resolved, I just made my own class implementing IotHubEventCallback:
protected static class MyTwinCallback implements IotHubEventCallback
{
public void execute(IotHubStatusCode status, Object context)
{
System.out.println("IoT Hub responded to device twin operation with status " + status.name());
}
}
and my startDevice Twin method now looks like:
client.startDeviceTwin(new MyTwinCallback(), null, dataCollector, null);
Related
I'm new to using maven and have a Project where I'm trying to create an instance of an object but keep getting the error:
error: cannot find symbol
CommentProcessor p = new CommentProcessor();
^
symbol: class CommentProcessor
location: class App
I have the files:
App.java
package com.group.pack;
public class App {
public static void main(String[] args) {
CommentProcessor p = new CommentProcessor();
p.connect();
}
}
CommentProcessor.java
package com.group.pack;
public class CommentProcessor {
public CommentProcessor(){
}
public void connect(){
...
}
}
App.java and commentProcessor.java are both in src/main/java/com.group/pack
If i take the files out into a separate project without the package (and not using maven), it will compile without any issues. Would this be something to do with how maven works?
Ive also tried creating a jar file, but this won't work either.
This is the pom that VSCode generated:
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- The Basics -->
<groupId>com.group.pack</groupId>
<artifactId>pack</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>pack</name>
<url>http://maven.apache.org</url>
<properties>
<maven.compiler.release>11</maven.compiler.release>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- Build Settings -->
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
I've recreated a mock project, I see no issues for me. Try recreating a simple mock project.
note:
I've noticed a problem in your pom.xml file.
When you create a jar file, you will need to create a jar with the dependencies
I created a maven project and added a JavaFX project to it. I made the following pom.xml
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>SEF-PROJ</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
<javafx.version>16</javafx.version>
<javafx.maven.plugin.version>0.0.6</javafx.maven.plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>${maven.compiler.release}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>${javafx.maven.plugin.version}</version>
<configuration>
<executable>/home/mrsaiba/.jdks/corretto-1.8.0_292/jre</executable>
<mainClass>src.sampe.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
When I run the mvn javafx:run, I got the error
Failed to execute goal org.openjfx:javafx-maven-plugin:0.0.6:run (default-cli) on project SEF-PROJ: Error
I googled it for days, but nothing useful showed up. I am using Java 8 and JavaFX 16(I don't want use a newer version of Java). I set up the JAVA_HOME with the path to the Java 8 jre.
In Maven 3 if you just had a failed download and have fixed it (e.g. by uploading the jar to a repository) it will cache the failure.
To force a refresh add -U to the command line.
Source: https://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
I am trying to test the basic structure of my GUI application that I started using WindowBuilder. I am also using Maven so that I can just download the dependencies from their repository.
I don't have any errors when I do a "Maven Clean" or a "Maven Install", but when I try to do "Run As--->Java Application", I get the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no swt-win32-3044 in java.library.path
swt-win32-3044 was what I found in the Maven Repository to satisfy the requirements for the WindowBuilder. I don't have any errors in my POM file, but here is what I have...
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>blah.blah.blah</groupId>
<artifactId>blah</artifactId>
<version>1.0.0</version>
<name>blah</name>
<dependencies>
<dependency>
<groupId>swt</groupId>
<artifactId>swt-win32</artifactId>
<version>3.0m8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<property>
<name>java.library.path</name>
<value>${project.build.directory}</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
Any help would be greatly appreciated. Thanks.
So I changed the POM around a little bit. I tried a different Maven dependency for WindowBuilder and changed my syntax for defining the maven-surefire-plugin.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>blah.blah.blah</groupId>
<artifactId>blah</artifactId>
<version>1.0.0</version>
<name>blah</name>
<dependencies>
<dependency>
<groupId>org.eclipse.swt</groupId>
<artifactId>org.eclipse.swt.win32.win32.x86_64</artifactId>
<version>4.3</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
It now launches the Java application window as expected.
I want to read a file from Google Cloud Storage using NIO as described in the SDK Javadoc and the package README. I think I'm missing something about triggering the installation of a new FileSystemProvider in the Maven configuration.
I created a simple-as-possible project to demonstrate. The highlights follow.
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>gcs-nio</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<name>playground</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-nio -->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-nio</artifactId>
<version>0.22.0-alpha</version>
</dependency>
</dependencies>
</project>
App.java:
public class App {
public static void main(String[] args) {
System.out.println("FileSystemProvider schemes:");
List<FileSystemProvider> fileSystemProviders = FileSystemProvider.installedProviders();
for (FileSystemProvider provider : fileSystemProviders) {
System.out.println(provider.getScheme());
}
// This fails; I want it to succeed.
Paths.get(URI.create("gs://dataflow-samples/shakespeare/kinglear.txt"));
}
}
Output:
$ mvn compile -q exec:java -Dexec.mainClass=com.example.App
FileSystemProvider schemes:
file
jar
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project gcs-nio: An exception occured while executing the Java class. Provider "gs" not installed -> [Help 1]
I am using maven in my project & I've put database.properties file under
maven resources folder.
I am accessing it in spring application context
<context:property-placeholder location="classpath:database.properties" />
But I don't understand why I am getting this file not found error on server start.
Could not load properties; nested exception is
java.io.FileNotFoundException: class path resource
[database.properties] cannot be opened because it does not exist
To my knowledge whatever resource is put under resources folder it is added to the classpath automatically by maven.
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp</groupId>
<artifactId>myapp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>myapp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>myapp</finalName>
</build>
</project>
NOTE: Seems like there is some problem with the M2E plugin of eclipse luna. Executed the same code in Juno & it worked fine.
That's not enough to build a deployable war file with maven. You need at least the war plugin. There's a thorough tutorial here:
http://crunchify.com/how-to-create-a-war-file-from-eclipse-using-maven-plugin-apache-maven-war-plugin-usage/
Your pom will look something like below, and you'll need to run mvn clean install against that.
Also I see you have a spring app, where are the spring dependencies in the pom file?
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>CrunchifyTutorial</groupId>
<artifactId>CrunchifyTutorial</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
</project>