Java and iMacros - java

I'm trying to follow this tutorial, regarding using Java with iMacros, but it isn't working. I'm getting an error saying "Could not find or load the main class" even though there is clearly a main class in the sample code on the website. Does anyone know why this might be happening? Thanks!
Update: Code sample
import com.jacob.activeX.*;
public class iMacroJACOBtest {
public static void main(String[] args) {
// Connect to iMacros Scripting Interface
System.out.println("Started.");
ActiveXComponent iim = new ActiveXComponent("imacros");
System.out.println("Calling iimInit");
// call iimInit()
iim.invoke("iimInit");
// call iimPlay()
System.out.println("Calling iimPlay");
iim.invoke("iimPlay", "CODE:URL GOTO=google.de");
}
}

Related

Getting error: Route() in Route cannot be applied to String

I'm designing a Java based MongoDB app and I've ran into a snag when working with Spark.
package com.tengen;
import spark.Request;
import spark.Response;
import spark.Route;
import spark.Spark;
public class HelloWorldSparkStyle {
public static void main(String[] args) {
Spark.get(new Route("/") {
#Override
public Object handle(Request request, Response response) {
return "Hello World From Spark";
}
});
}
}
On new Route("/") I get the error Route() in route cannot be applied to java.lang.string.
I'm confused as to why this doesn't work as I've followed their code exactly.
This should probably be posted on the MongoDB class forum, but I ran into a similar issue. Looks like the get method changed from when the course material was produced. The get now requires a path and a Route
get(path, Route)
import spark.Request;
import spark.Response;
import spark.Route;
import spark.Spark;
public class HelloWorldSparkStyle {
public static void main(String[] args){
Spark.get("/", new Route() {
public Object handle(final Request request, final Response response){
return "Hello World from Spark";
}
});
}
}
Actually I used spark-core-1.1.1.jar it worked fine for me, may be the newer versions of Spark(version 2.0.0) support some different syntax.So if you are using the latest version then you can follow the example given by Mike or just add spark-core-1.1.1.jar to your classpath your example will work fine
That would work in Spark 1. In Spark 2 is recommended by Spark the following (source: http://sparkjava.com/news.html):
import static spark.Spark.*;
public class HelloWorld {
public static void main(String[] args) {
get("/", (req, res) -> "Hello World From Spark");
}
}
Currently, Implementation of Spark Java framework needs to use directory out of Route. So you have to correct your code as follow:
public static void main(String[] args) {
spark.Spark.port(PortNumber);
Spark.get("/", new Route() {
public Object handle(Request request, Response response) throws Exception {
return "This is a sample page";
}
});
}
actually, "/" is the resource to your program. And if you want to change the default spark.Spark.port(PortNumber).
Change the version of Spark in the POM file from the exercise files you download from handout. That fixed issue for me.

Java org.osgi Bundle.getEntry undefined

I have the following code.
import org.osgi.framework.Bundle;
class Sample {
public static void main(String[] args) {
Bundle bundle = Platform.getBundle("abc.abc");
URL packageBundleUrl = bundle.getEntry("/");
}
}
But I am getting a compilation error for bundle.getEntry(). It says "The method getEntry(String) is undefined for the type Bundle".
I cannot understand what is the problem. Somebody please help me.

Can not find symbol in main AND Can not find symbol errors

I have been working on an assignment for my first class in programming. I am working with NetBeans. I finished my project and it worked fine. I felt I could do better so I scraped it and started with a fresh slate. Now I am getting a message that says "No main class found" when i try to run it. But I have a main class. Here is some of the code:
package MyName;
import java.util.*;
import java.io.*;
public class MyName {
public static void main(String[] args)throws Exception {
//declare new file
java.io.File newFile = new java.io.File("LuisRamosp4.txt");
//check to see if file exist, if it does then delete it
if (newFile.exists()) {
newFile.delete();
}
//used to create a file
System.setOut(new PrintStream(newFile));
//instance 1 of Guitar object
Guitar myGuitar = new Guitar();
On the this line there is an error message saying "Can not find symbol" only I have a class built already. here is the line:
Guitar myGuitar = new Guitar();
Here is a piece of my class:
public class Guitar {
boolean isPlaying = false;
boolean isTuned = false;
I understand i should have kept the code I had. I wanted to try again and now I am stuck. Any advice will be greatly appreciated.
in java, you shouldn't use throws for the main method, it is already expected.

Java-Sandbox example throwing java.lang.NoClassDefFoundError

Anyone with experience using Java-Sandbox, I have implemented one of the basic examples found in the documentation but i cant get it working.
Code:
SandPlayground.java
import java.util.concurrent.TimeUnit;
import net.datenwerke.sandbox.*;
import net.datenwerke.sandbox.SandboxContext.AccessType;
import net.datenwerke.sandbox.SandboxContext.RuntimeMode;
import net.datenwerke.sandbox.SandboxedEnvironment;
public class SandPlayground {
/**
* #param args
*/
public static void main(String[] args) {
System.out.println("Running...");
SandboxService sandboxService = SandboxServiceImpl.initLocalSandboxService();
// configure context
SandboxContext context = new SandboxContext();
//context.setRunRemote(true);
context.setRunInThread(true);
context.setMaximumRunTime(2, TimeUnit.SECONDS, RuntimeMode.ABSOLUTE_TIME);
context.addClassPermission(AccessType.PERMIT, "java.lang.System");
context.addClassPermission(AccessType.PERMIT, "java.io.PrintStream");
//run code in sandbox
SandboxedCallResult<String> result = sandboxService.runSandboxed(MyEnvironment.class, context, "This is some value");
// output result
System.out.println(result.get());
}
}
MyEnvironment.java
import net.datenwerke.sandbox.SandboxedEnvironment;
public class MyEnvironment implements SandboxedEnvironment<String> {
private final String myValue;
public MyEnvironment(String myValue){
this.myValue = myValue;
}
#Override
public String execute() throws Exception {
/* run untrusted code */
System.out.println(myValue);
/* return some value */
return "This is a different value";
}
}
And I'm getting the error:
EDIT: I've included the dependencies, but I'm still getting some errors:
With the code above I get:
Exception in thread "main" net.datenwerke.sandbox.exception.SandboxedTaskKilledException: killed task as maxmimum runtime was exceeded
at net.datenwerke.sandbox.SandboxMonitorDaemon.testRuntime(SandboxMonitorDaemon.java:82)
at net.datenwerke.sandbox.SandboxMonitorDaemon.run(SandboxMonitorDaemon.java:57)
at java.lang.Thread.run(Thread.java:724)
and when i remove the context.setMaximumRunTime() call, I get:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/map/IdentityMap ...
Any help is much appreciated.
most likely you are missing the javassist library (see the documentatio of the sandbox for dependencies: http://blog.datenwerke.net/p/the-java-sandbox.html). You'll find the javassist library on sourceforge at: https://sourceforge.net/projects/jboss/files/Javassist/
The javaassist library is used to remove finalizers in loaded code. This can be turned off in the sandbox context:
contex.setRemoveFinalizers(false)
Hope this helps.

Java - Boilerpipe running in Eclipse not working properly for a demo program

So I'm running boilerpipe in eclipse. I'm just trying to get it to work, here is the code..
package de.l3s.boilerpipe.demo;
import java.net.URL;
import de.l3s.boilerpipe.extractors.DefaultExtractor;
public static void main(final String[] args) throws Exception {
URL url;
url = new URL("http://religion.blogs.cnn.com/2012/11/16/my-take-113th-congress-looks-like-old-america/?hpt=hp_c3");
final InputStream urlStream = url.openStream();
final InputSource is = new InputSource(urlStream);
final BoilerpipeSAXInput in = new BoilerpipeSAXInput(is);
final TextDocument doc = in.getTextDocument();
urlStream.close();
System.out.println(DefaultExtractor.INSTANCE.getText(doc));
//System.out.println(ArticleExtractor.INSTANCE.getText(doc));
}
I'm not sure if I set it up in Eclipse properly or not, but my console just says things like...
SAX features:
http://xml.org/sax/features/namespaces
http://xml.org/sax/features/namespace-prefixes
http://xml.org/sax/features/string-interning
http://xml.org/sax/features/validation
http://xml.org/sax/features/external-general-entities
http://xml.org/sax/features/external-parameter-entities
I've never heard of Boilerpipe before, so please forgive me if this is not how it works, but doesn't your code still need to be inside a class?
You have your main method (and in fact all your code) not within a class - or does Boilerplate make the java work very differently?

Categories

Resources