Crawler4j with Grails App throws error - grails

This might be a very basic and silly question for experienced people. But please help. I am trying to use Crawler4j with in my Grails app by following this tutorial.
I know its Java code but I am using it in a controller class called CrawlerController.groovy.
I added the jar files but when I write CrawlConfig crawlConfig = new CrawlConfig()
it throws me a compiler error saying "Groovy unable to resolve class" . I refreshed dependencies and tried everything. May be I am missing something since I am a beginner. This is what I have written so far and all the import statements and CrawlConfig statement throws errors:
import edu.uci.ics.crawler4j.crawler.Page;
import edu.uci.ics.crawler4j.crawler.WebCrawler;
import edu.uci.ics.crawler4j.parser.HtmlParseData;
import edu.uci.ics.crawler4j.url.WebURL;
class CrawlerController extends WebCrawler {
public static void main(String[] args) {
CrawlConfig crawlConfig = new CrawlConfig()
}
}
` Please help. Thanks.

Just refresh your dependencies.

Related

Using java in rascal

I have made a java function genImage(List<String lines) which is located in class vis. I am trying to import it into my rascal code, but it won't work. This is the last of my efforts to import it:
#javaClass{visualization.vis}
java void genImage(list[str] lines);
The error I get:
Cannot link method visualization.vis because: visualization.vis.(io.usethesource.vallang.IValueFactory)
Advice: |http://tutor.rascal-mpl.org/Errors/Static/JavaMethodLink/JavaMethodLink.html%7C
The #javaClass tag must point to a fully qualified classname, including the package and the class. It seems it's the class you are missing, right?

Grails 3 logging in src folder not injecting log object

In the src folder of the grails 3 app:
I have a lot of log.xyz and they are is throwing the following exception:
Caused by: groovy.lang.MissingPropertyException: No such property: log for class: com.myApp.runner.RunnerThreadPoolExecutor
Which seems odd as this is a migrated app from grails 2 and having the log object in those classes was very useful.
I can add the following to each class:
import org.slf4j.Logger
import org.slf4j.LoggerFactory
static Logger log = LoggerFactory.getLogger(SomeClass.class)
But this seems very long winded and a bit a backwards step.
Am I missing something in the configuration somewhere?
Just add the slf4j annotation to your classes:
package com.example
import groovy.util.logging.Slf4j
#Slf4j
class MySample {
def test() {
log.debug("log this!")
}
}

dLibs - OpenKinect

Recently I got interested in dLibs, the Java wrapper for OpenKinect.
But I have difficulties in running the codes in eclipse; I've added the libraries based on what I think.
How to run the codes, say the example .pde files?
I've written sth like this to see how it works...
public class Test {
public static void main(String[] args) {
Kinect.loadLibrary( "C:/Users/admin/Dropbox/new_workspace/dLibs/", "freenect.dll" );
Kinect k= new Kinect(0);
System.out.println(k.isReady());
}
}
==========
But I get this error:
#_KINECT_ERROR___#
location: dLibs.freenect.FreenectLibrary.loadLibrary(FreenectLibrary.java:177)
message: Unable to load library : freenect.dll
message: path = "C:\Users\admin\Dropbox\new_workspace\dLibs/freenect.dll"
message: try 'MyKinect.loadLibrary( "your dll path/", "freenect.dll" )'
which the 177 line of the FreenectLibrary is about the loadLibrary(...) method.
Can anyone please help me with that?
I was running the same issue. Make sure you use the 64bit dll file. Also make sure about the path is correct, and the use of / !

dart - its_all_about_you tutorial error

I am trying to run the latest version of its_all_about_you with the latest version of Dart Editor/SDK and I am getting this error. I copied the latest source from github
Internal error: 'http://.../web/out/packages/web_ui/src/linked_list.dart':
Error: line 72 pos 29: cannot resolve class name 'IterableBase' from 'LinkedList'
class LinkedList<E> extends IterableBase<E> {
Does anyone know what the problem is and how to fix it? And for future reference how would one go about debugging the issue?
This looks like a version mismatch. Could you please verify that your sdk (comes with the editor) is up to date.
If the error persists after an upgrade, post the version number of your editor and try the following (untested) example:
import 'dart:collection';
class A extends IterableBase { get iterator => null; }
main() { new A(); }
In recent versions of Dart this should work.

javac will not compile enum, ( Windows Sun 1.6 --> OpenJDK 1.6)

package com.scheduler.process;
public class Process {
public enum state {
NOT_SUBMITTED, SUBMITTED, BLOCKED, READY, RUNNING, COMPLETED
}
private state currentState;
public state getCurrentState() {
return currentState;
}
public void setCurrentState(state currentState) {
this.currentState = currentState;
}
}
package com.scheduler.machine;
import com.scheduler.process.Process;
import com.scheduler.process.Process.state;
public class Machine {
com.scheduler.process.Process p = new com.scheduler.process.Process();
state s = state.READY; //fails if I don't also explicitly import Process.state
p.setCurrentState(s); //says I need a declarator id after 's'... this is wrong.
p.setCurrentState(state.READY);
}
Modified the example to try and direct to the issue. I cannot change the state on this code. Eclipse suggests importing Process.state like I had on my previous example, but this doesn't work either. This allows state s = state.READY but the call to p.setCurrentState(s); fails as does p.setCurrentState(state.READY);
Problem continued.... Following Oleg's suggestions I tried more permutations:
package com.scheduler.machine;
import com.scheduler.process.Process;
import com.scheduler.process.Process.*;
public class Machine {
com.scheduler.process.Process p = new com.scheduler.process.Process();
public state s = Process.state.READY;
p.setCurrentState(s);
p.setCurrentState(state.READY);
}
Okay. It's clear now that I'm a candidate for lobotomy.
package com.scheduler.machine;
import com.scheduler.process.Process;
import com.scheduler.process.Process.state;
public class Machine {
public void doStuff(){
com.scheduler.process.Process p = new com.scheduler.process.Process();
state s = state.READY; //fails if I don't also explicitly import Process.state
p.setCurrentState(s); //says I need a declarator id after 's'... this is wrong.
p.setCurrentState(state.READY);
}
}
I needed to have a method in the class--but we're still missing something (probably obvious) here. When I go via the command line and run javac on the Machine class AFTER compiling Process, I still get the following error:
mseil#context:/media/MULTIMEDIA/Scratch/Scratch/src/com/scheduler/machine$ javac Machine.java
Machine.java:3: package com.scheduler.process does not exist
import com.scheduler.process.Process;
^
So I guess the question now becomes, what idiot thing am I missing that is preventing me from compiling this by hand that eclipse is doing for me behind the scene?
======
Problem solved here:
Java generics code compiles in eclipse but not in command line
This has just worked for me:
Download latest Eclipse
Create new project
Create two packages com.scheduler.process and com.scheduler.machine
Create class Process in package com.scheduler.process and class Machine in com.scheduler.machine and copy their contents from your post modifying them to conform to Java language syntax, like this:
Everything compiles right away.
------ to answer the previous version of the question ------
To answer the question as it is right now: you need to either
import com.scheduler.process.Process.status or import com.scheduler.process.Process.* and refer to status as just status
or
import com.scheduler.process.* or import com.scheduler.process.Process and refer to status as Process.status
------ to answer the original version of the question ------
You can't import classes that are not inside some package. You just can't. It is a compile time error to import a type from the unnamed package.
You don't need to import anything if your classes are in the same package, or if all of your classes are packageless.
If Process class was inside some package it would be possible to import just its status inner class: import a.b.c.Process.status would work just fine.
All your Windows/Linux migration issues don't have anything to do with Java and exceptions that you see. import Process.state; will produce exception on any OS because you can't import classes that don't belong to any package.
Eclipse doesn't use the Sun JDK by default. I would assume that you are using Eclipse's built in compiler as Sun's JDK and the OpenJDK are almost identical.
Java code compiles and runs exact the same on Windows and Linux most of the time (unless you use a few of the platform specific operations)
I suspect you are not building the code the same way and when you compile Machine, the Process class has not been compiled.
I suggest you use a standard build system like maven or ant and it will build the same everywhere. Failing that run Eclipse on Linux or just the same .class you use on windows as they don't need to be re-compiled in any case.
BTW: You don't need to import Process.state as it not used and its in the same package (so you wouldn't need to if you did)

Resources