Jess "Class not found" exception at Maven project - java

First of all I want to say this is kind of a follow up of a question I posted yesterday which I solved myself (How to add Jess in Maven project?).
This time, it's Jess' turn to have problems finding the project's classes. More specifically, everything runs fine until the execution of the 1st line of engine.batch("rules.clp"), where I get a "Class not found exception".
(import cz.cuni.amis.pogamut.ut2004.examples.huntbot)
(deftemplate HunterBot (declare (from-class HunterBot)))
The package structure is:
-cz.cuni.amis.pogamut.ut2004.examples.huntbot
-- HunterBot.java
Below are the first lines of the HunterBot.java file:
package cz.cuni.amis.pogamut.ut2004.examples.huntbot;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import jess.*;
import cz.cuni.amis.introspection.java.JProp;
import cz.cuni.amis.pogamut.base.agent.navigation.IPathExecutorState;
import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.EventListener;
import cz.cuni.amis.pogamut.base.utils.Pogamut;
import cz.cuni.amis.pogamut.base.utils.guice.AgentScoped;
import cz.cuni.amis.pogamut.base.utils.math.DistanceUtils;
import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated;
import cz.cuni.amis.pogamut.ut2004.agent.module.utils.TabooSet;
import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004PathAutoFixer;
import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004DistanceStuckDetector;
import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004PositionStuckDetector;
import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004TimeStuckDetector;
import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotModuleController;
import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType;
import cz.cuni.amis.pogamut.ut2004.communication.messages.UT2004ItemType;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Initialize;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Move;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Rotate;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Stop;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.StopShooting;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.BotDamaged;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.BotKilled;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Item;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PlayerDamaged;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PlayerKilled;
import cz.cuni.amis.pogamut.ut2004.utils.UT2004BotRunner;
import cz.cuni.amis.utils.exception.PogamutException;
import cz.cuni.amis.utils.flag.FlagListener;
import java.util.logging.Logger;
/**
* Example of Simple Pogamut bot, that randomly walks around the map searching for preys shooting at everything that is in its way.
*
* #author Rudolf Kadlec aka ik
* #author Jimmy
*/
#AgentScoped
public class HunterBot extends UT2004BotModuleController<UT2004Bot> {
Rete engine;
...
And finally this is the pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>cz.cuni.amis.pogamut.ut2004</groupId>
<artifactId>pogamut-ut2004-bot-pom</artifactId>
<version>3.6.1</version>
</parent>
<groupId>cz.cuni.amis.pogamut.ut2004.examples</groupId>
<artifactId>huntbot</artifactId>
<version>3.3.1</version>
<packaging>jar</packaging>
<name>04-hunter-bot</name>
<url>http://pogamut.cuni.cz</url>
<properties>
<bot.main.class>cz.cuni.amis.pogamut.ut2004.examples.huntbot.HunterBot</bot.main.class>
</properties>
<repositories>
<repository>
<id>amis-artifactory</id>
<name>AMIS Artifactory</name>
<url>http://diana.ms.mff.cuni.cz:8081/artifactory/repo</url>
</repository>
<repository>
<id>data-local</id>
<name>data</name>
<url>file://${project.basedir}/repo</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.dstovall</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<configuration>
<mainClass>${bot.main.class}</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>gov.sandia</groupId>
<artifactId>jess</artifactId>
<version>7.1p2</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
The jess-7.1p2.jar file is located at (base.dir)\repo\gov\sandia\jess\7.1p2\ . It is recognized without problems.
PS: I tried to make this question as detailed as possible. If more info is needed, I can provide it immediately.

The import function permits both for importing a single class or all classes in a package. A package alone can't be imported - it doesn't make sense.
(import some.pack.SomeClass)
and
(import another.pack.*)
If you need access to the static members of a class you must use the specific form. The statics are then available as if they were a user function:
(SomeClass.MAX_NUMBER_OF_X)

Related

The type java.sql.SQLException cannot be resolved. It is indirectly referenced from required type com.alibaba.druid.pool.DruidDataSource

package com.test.redis.config;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import javax.sql.DataSource;
import java.sql.SQLException;
IDEA SpringTooSuit4, maven pom.xml config jpa.
javax.sql.DataSource,java.sql.SQLException can not be resolved.
no idea ............
expect import success
try to import this maven library
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.0.32</version>
</dependency>
it should be jre compatibility issue, jre1.8 is ok

groovy-eclipse-compiler compiles but javac compilation fails

My project builds successfully with groovy-eclipse-compiler, but fails without groovy-eclipse-compiler (using just javac). The build fails with an error message as given below (reported in a test class, while mocking an invocation)
java: reference to getFileResource is ambiguous
In order to debug the issue, I created a project with minimal files (given below). Though in project we have groovy source also, but I have not included them here to keep the code minimal.
The code is also pushed to git and is available at https://github.com/kaushalkumar/project-debug
My Doubt: The reported issue looks to be legitimate and I feel that groovy-eclipse-compiler must also fail, but it seems that the error is ignored. I am trying to understand what make groovy compiler to ignore it. Is it an issue in groovy compiler?
src/main/java/pkg1/IStrategy.java
package pkg1;
import java.util.Map;
public interface IStrategy {
Map<String, Object> getEnvMap();
}
src/main/java/pkg1/SharedResourceHelper.java
package pkg1;
import java.io.File;
import java.io.IOException;
import java.util.Map;
public class SharedResourceHelper {
public static File getFileResource(final String resourceName, final IStrategy strategy) throws IOException {
return getFileResource(resourceName, strategy.getEnvMap());
}
public static File getFileResource(final String resourceName, final Map<String, Object> envConfig) throws IOException {
return null;
}
}
src/test/java/pkg1/StrategyTest.java
package pkg1;
import pkg1.SharedResourceHelper;
import org.easymock.EasyMock;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.junit.Test;
import org.powermock.modules.junit4.PowerMockRunner;
import org.junit.runner.RunWith;
import java.io.File;
#PrepareForTest({SharedResourceHelper.class})
#RunWith(PowerMockRunner.class)
public class StrategyTest {
#Test
#PrepareForTest({SharedResourceHelper.class})
public void testGetFileResource() throws Exception {
PowerMock.mockStatic(SharedResourceHelper.class);
EasyMock.expect(SharedResourceHelper.getFileResource(EasyMock.anyString(), EasyMock.anyObject())).andReturn(File.createTempFile("tmp", "s"));
// EasyMock.expect(SharedResourceHelper.getFileResource("test", null)).andReturn(File.createTempFile("tmp", "s"));
}
}
/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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>project.debug</groupId>
<artifactId>project</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-easymock</artifactId>
<version>2.0.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<source>1.8</source>
<target>1.8</target>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.9.2-01</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.4.3-01</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Java version - 1.8.0_231
Maven - 3.6.2
OS - Mac 10.15.6
groovy-eclipse-compiler - 2.9.2-01
groovy-eclipse-batch - 2.4.3-01
You reference "SharedResourceHelper.getFileResource(EasyMock.anyString(), EasyMock.anyObject())" is indeed ambiguous. If you add a typecast before "EasyMock.anyObject()" you could disambiguate. And EasyMock probably provides an "any" method that you can pass a type into as well.
groovy-eclipse-compiler is based upon ecj (eclipse compiler for java) and not javac, so there are bound to be differences. It may also be that ecj has a different default error/warning level for this particular case. If you feel this should be an error, you can file a JDT bug at bugs.eclipse.org.
eric-milles gave some direction to further explore this. His input is available at https://github.com/groovy/groovy-eclipse/issues/1157.
Based on his comment, we explored the history of https://github.com/groovy/groovy-eclipse/blob/master/extras/groovy-eclipse-batch-builder/build.properties and found that the compilation issue was between 2.4.12-01 (compilation works) and 2.4.12-02 (compilation breaks- as expected), which was part of release 2.9.2.
The change happened on Aug 10, 2017 (13c1c2a#diff-c8c111c3afb6080ae6b32148caaf6a0a), with comment as "Remove codehaus references". The jdt.patch.target was targeted for e44 which is Luna. This was same for both the files.
I invested some time in exploring https://github.com/eclipse/eclipse.jdt.core, to figure out how compiler behaviour could have altered, but could not get much. Though I am not very sure, but I feel that change in groovy-eclipse-batch (between 2.4.12-01 and 2.4.12-02) might be the cause of this.
Having invested this much time, I feel that it is not worth to further debug on this to figure out the root cause as the issue is already fixed in next version(s) [2.4.12-02 and beyond].

Javacv face recognition - mismatch in methods arguments types

I'm trying to run a face recognition example using javacv, but there is a mismatch in the methods arguments types.
I'm using the following maven dependencies:
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>opencv</artifactId>
<version>3.0.0-1.1</version>
</dependency>
<dependency>
I'm referring to this example: http://pcbje.github.io/misc/2012/12/01/doing-face-recognition-with-javacv.html
Imports:
import static org.bytedeco.javacpp.opencv_face.createFisherFaceRecognizer;
import static org.bytedeco.javacpp.opencv_imgproc.CV_BGR2GRAY;
import static org.bytedeco.javacpp.opencv_imgproc.cvCvtColor;
import static org.bytedeco.javacpp.opencv_imgcodecs.cvLoadImage;
import static org.bytedeco.javacpp.opencv_core.IPL_DEPTH_8U;
import java.io.File;
import java.io.FilenameFilter;
import org.bytedeco.javacpp.opencv_core.IplImage;
import org.bytedeco.javacpp.opencv_core.Mat;
import org.bytedeco.javacpp.opencv_core.MatVector;
import org.bytedeco.javacpp.opencv_face.FaceRecognizer;
The only difference is that they are using com.googlecode.javacv, but as far as I understand this is old. However I downloaded those jars from http://www.java2s.com/Code/Jar/j/Downloadjavacvjar.htm, but I'm still not able to compile successfully.
Can you please advice. Thank you.
[SOLVED] - Please refer to this example

How can I connect Storm and D3.js using Redis and Flask?

I have my Storm testing topology done, and before I created a d3 script on an Html code, that readed the data from a text file. I want it now to read the data directly from a Storm topology (a bolt maybe?) But I have no clue of how to do it. I'm using Horton Works Sandbox for the testing, Any help would be apprecieated.
Thanks in advance!
I've found a storm package for redis that I'm trying to use now. It allows you to set a bolt for writting on redis, and I've set the node already. My problem now is that eclipse can't find the imports of the java code and the ones on the pom.xml.I've downloaded the package. My current java bolt and imports are:
package Storm.practice.Storm.Prova;
import backtype.storm.Config;
import backtype.storm.LocalCluster;
import backtype.storm.StormSubmitter;
import backtype.storm.task.OutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.testing.TestWordSpout;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.topology.TopologyBuilder;
import backtype.storm.topology.base.BaseRichBolt;
import backtype.storm.tuple.Fields;
import backtype.storm.tuple.Tuple;
import backtype.storm.tuple.Values;
import backtype.storm.utils.Utils;
import backtype.storm.spout.SpoutOutputCollector;
import backtype.storm.topology.base.BaseRichSpout;
import java.util.Map;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicLong;
import storm.external.*;// error from here
import storm.external.storm-redis.org.apache.storm.redis.common.config.JedisClusterConfig;
import org.apache.storm.redis.common.config.JedisPoolConfig;
import org.apache.storm.redis.common.mapper.RedisDataTypeDescription;
import org.apache.storm.redis.common.mapper.RedisStoreMapper;
import redis.clients.jedis.JedisCommands;//to here
..........
class MortsStoreMapper implements RedisStoreMapper {
private RedisDataTypeDescription description;
private final String hashKey = "wordCount";
public WordCountStoreMapper() {
description = new RedisDataTypeDescription(
RedisDataTypeDescription.RedisDataType.HASH, hashKey);
}
#Override
public RedisDataTypeDescription getDataTypeDescription() {
return description;
}
#Override
public String getKeyFromTuple(ITuple tuple) {
return tuple.getStringByField("word");
}
#Override
public String getValueFromTuple(ITuple tuple) {
return tuple.getStringByField("count");
}
}
And 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Storm.practice</groupId>
<artifactId>Storm.Prova</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Storm.Prova</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.storm</groupId>
<artifactId>storm-core</artifactId>
<version>0.9.1-incubating</version>
</dependency>
<dependency> #error from here...
<groupId>org.apache.storm</groupId>
<artifactId>storm-redis</artifactId>
<version>{0.9.1-incubating}</version>
<type>jar</type>
</dependency>#... to here
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>Storm.practice.Storm.Prova.ProvaTopology</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
The errors are that Eclipse can't find the dependences and the packages
Based on your scenario, I think you will need some system or code in the middle that will read data from Storm and push to D3. You can try out something like WSO2 CEP [1], which has the ability to connect to Storm and uses websockets to push events to a dashboard based on d3 [2].
In your scenario, you can map your logic in the Storm bolt to a Siddhi query [3] and then get those events from Storm to WSO2 CEP. Then you can create a websocket publisher to send events to your D3 code using the built-in websocket capabilities of the server.
Please note that this is one of the possible solutions based on your requirements and you might be better off utilizing the capabilities of an already existing CEP system that has integration to Storm and D3.
Hope this helps!
[1] http://wso2.com/products/complex-event-processor/
[2] https://docs.wso2.com/display/CEP400/Visualizing+Results+in+the+Analytics+Dashboard
[3] https://docs.wso2.com/display/CEP400/Sample+0501+-+Processing+a+Simple+Filter+Query+with+Apache+Storm+Deployment
I now it's a bit late, almost a year, but I was reviewing my account, and saw this question.
I finally used Redis, interfaced wit Jedis, that I import as a Maven artifact. Once this was working and I was able to see the results with the Redis Monitor via telnet, I created a simple Node.js code, launched it, and the data was arriving to the client, hence to d3. I needed Socket.io and Redis.js to achieve this, but is working now.
If someone need some details, please, ask me and I will help you happily.

Java htmlunit: incompatible types for getPage?

In my code it is giving an error when trying to use the getPage method. I'm not sure what the problem is, any ideas of perhaps where I should be looking?
I've tried adding the class under "found" to my import but it doesn't seem to exist. This is my first time posting a java problem so please let me know if more information is needed.
The error:
java: incompatible types
required: com.gargoylesoftware.htmlunit.html.HtmlPage
found: com.gargoylesoftware.htmlunit.Page
My code
package com.buth.trabot;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.lang.Object;
import com.gargoylesoftware.htmlunit.*;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.WebClient;
import static org.junit.Assert.*;
/**
* Created with IntelliJ IDEA.
* User: Tyler
* Date: 9/28/13
* Time: 7:28 PM
* To change this template use File | Settings | File Templates.
*/
public class Main {
public static void main (String [] args) {
final WebClient webClient = new WebClient();
final HtmlPage startPage = webClient.getPage("http://htmlunit.sf.net");
assertEquals("HtmlUnit - Welcome to HtmlUnit", startPage.getTitleText());
}
}
My pom.xml file
<?xml version="1.0" encoding="UTF-8"?>
<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>MavenFirst</groupId>
<artifactId>MavenFirst</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>1.14</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
</project>
It seems the return type of getPage is com.gargoylesoftware.htmlunit.Page.
Your variable is of type com.gargoylesoftware.htmlunit.html.HtmlPage.
You need to either change the type of your variable or add a cast.
I guess you should be linking it this way:
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.12</version>
</dependency>

Categories