I am using openjdk version 11.0.15 on Debian 4.19. I want to use the JSON library available in Java: javax.json-1.0.jar. After downloading the jar file, I have added the classpath like so:
export CLASSPATH=/Diss/frontend/javax.json-1.0.jar
echo $CLASSPATH:
/Diss/frontend/javax.json-1.0.jar
my code is this:
import javax.json.Json;
import javax.json.JsonReader;
import javax.json.JsonStructure;
import javax.json.JsonObject;
public class ns3_inputs {
public static void main (String[] args)
{
JSONObject obj = new Json.createObjectBuilder();
obj.add("foo", "bar");
obj.build();
}
}
I compile like this: javac -cp .:$CLASSPATH ns3_inputs.java
to which I get the following error:
error: cannot find symbol
JSONObject obj = new Json.createObjectBuilder();
^
symbol: class JSONObject
location: class ns3_inputs
ns3_inputs.java:25: error: cannot find symbol
JSONObject obj = new Json.createObjectBuilder();
^
symbol: class createObjectBuilder
location: class Json
2 errors
The java source code file and the jar file are in the same directory. Am I supposed to place the jar file in a specific path? I am very new to Java so I may be missing something very basic here. I am trying to build a desktop Java application and I cannot use any libraries suitable for android. Please suggest a solution
The class name is JsonObject, not JSONObject.
The following compilation is successful.
~ $ export CLASSPATH=~/Downloads/javax.json-api-1.0.jar
~ $
~ $ cat ns3_inputs.java
import javax.json.Json;
import javax.json.JsonObjectBuilder;
public class ns3_inputs {
public static void main (String[] args)
{
JsonObjectBuilder obj = javax.json.Json.createObjectBuilder();
obj.add("foo", "bar");
obj.build();
}
}
~ $
~ $ javac ns3_inputs.java
Related
i have a scenario such as below:
pyhton file name is sir_desc.py placed into this path "E:/Program Files/Java/jdk1.8.0_92/bin/sir_desc.py"
jython-2.5 jar file placed into ext folder of java dierectory
i able to run python code by using these command from commandprompt :
C:\Python27>python
import sir_desc
sir_desc.get_url_text("http://www.tutorialspoint.com/java/")
steps to run python file
python code run successfully and return text as output
how to run python file from following java code and how i remove "sys-package-mgr : can't create package cashe dir" ??
import org.python.core.PyObject;
import org.python.core.PyString;
import org.python.util.PythonInterpreter;
public class method {
public static void main(String[] args) {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("E:/Program Files/Java/jdk1.8.0_92/bin/sir_desc.py");
PyObject str = interpreter.eval("repr(get_url_text(\"http://www.tutorialspoint.com/java/\"))");
System.out.println(str.toString());
}
}
I get the following error when I try to run
java -cp 'angus-sdk-java-0.0.2-jar-with-dependencies.jar:.' FaceDetect
I am following a tutorial for face detection in http://angus-doc.readthedocs.io/en/latest/getting-started/java.html . Below is my java code,
import java.io.IOException;
import org.json.simple.JSONObject;
import ai.angus.sdk.Configuration;
import ai.angus.sdk.Job;
import ai.angus.sdk.ProcessException;
import ai.angus.sdk.Root;
import ai.angus.sdk.Service;
import ai.angus.sdk.impl.ConfigurationImpl;
import ai.angus.sdk.impl.File;
public class FaceDetect {
public static void main(String[] args) throws IOException, ProcessException {
Configuration conf = new ConfigurationImpl();
Root root = conf.connect();
Service service = root.getServices().getService("age_and_gender_estimation", 1);
JSONObject params = new JSONObject();
params.put("image", new File("Downloads/IMG_1060.jpg"));
Job job = service.process(params);
System.out.println(job.getResult().toJSONString());
}
}
I don't understand the problem with it. I have tried all the answers in the stack overflow but nothing is working for me.
remove the single qoutes around the classpath:
java -cp angus-sdk-java-0.0.2-jar-with-dependencies.jar:. FaceDetect
im trying to do simple OCR application but i get errors like this:
Code:
import org.bytedeco.javacpp.*;
import static org.bytedeco.javacpp.lept.*;
import static org.bytedeco.javacpp.tesseract.*;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.UnsupportedEncodingException;
public class Main {
public void tesseract(String filename){
BytePointer outText;
tesseract.TessBaseAPI api = new tesseract.TessBaseAPI();
// Initialize tesseract-ocr with English, without specifying tessdata path
if (api.Init("/Users/Marcel/tesseract-ocr", "ENG") != 0) {
System.err.println("Could not initialize tesseract.");
System.exit(1);
}
// Open input image with leptonica library
PIX image = pixRead(filename);
api.SetImage(image);
// Get OCR result
outText = api.GetUTF8Text();
String string = outText.getString();
assertTrue(!string.isEmpty());
System.out.println("OCR output:\n" + string);
// Destroy used object and release memory
api.End();
outText.deallocate();
pixDestroy(image);
}
public static void main(String[] args) {
Main main = new Main();
String fileName = "src/main/resources/test.png";
main.tesseract(fileName);
}
}
I have tried some solutions from google, but it didnt solve this. I using Inteliji (with maven) on Mac OSX. Before i had problem with TESTDATA_PREFIX, but i changed api.init first parameter and now i get this:
dyld: lazy symbol binding failed: Symbol not found: __ZN9tesseract11TessBaseAPI8SetImageEPK3Pix
Referenced from: /private/var/folders/lq/3mb8s_jj1ql0klqzznm1j1tm0000gn/T/javacpp33697284992581/libjnitesseract.dylib
Expected in: /usr/local/lib/libtesseract.3.dylib
dyld: Symbol not found: __ZN9tesseract11TessBaseAPI8SetImageEPK3Pix
Referenced from: /private/var/folders/lq/3mb8s_jj1ql0klqzznm1j1tm0000gn/T/javacpp33697284992581/libjnitesseract.dylib
Expected in: /usr/local/lib/libtesseract.3.dylib
This is because of 2 conflicting libtesseract.3.dylib.
If you have installed tesseract on mac using brew then it is referring to the libtesseract.3.dylib inside tesseract folder /usr/local/Cellar/tesseract/3.04.01_1/lib/
instead of /usr/local/lib/libtesseract.3.dylib
I am trying to crawl the javascript webpages(content present within IFrame html tag) using Crawljax. I have added slf4j, crawljax 2.1 and Guava 18.0 jar to the application.
Error Message displayed in popup:
cannot find symbol
import com.crawljax.core.configuration.CrawljaxConfiguration.CrawljaxConfigurationBuild‌​er;
symbol: class CrawljaxConfigurationBuilder
location: class CrawljaxConfiguration.
Code:
import com.crawljax.core.CrawlerContext;
import com.crawljax.core.CrawljaxRunner;
import com.crawljax.core.configuration.CrawljaxConfiguration;
import com.crawljax.core.configuration.CrawljaxConfiguration.CrawljaxConfigurationBuilder;
import com.crawljax.core.plugin.OnNewStatePlugin;
import com.crawljax.core.state.StateVertex;
public class CrawljaxExamples {
public static void main(String[] args) {
CrawljaxConfigurationBuilder builder
= CrawljaxConfiguration.builderFor("http://help.syncfusion.com/ug/wpf/default.htm#!documents/overview.htm");
builder.addPlugin(new OnNewStatePlugin() {
#Override
public void onNewState(CrawlerContext context, StateVertex newState) {
}
#Override
public String toString() {
return "Our example plugin";
}
});
CrawljaxRunner crawljax = new CrawljaxRunner(builder.build());
crawljax.call();
}
}
Error Message:
java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Uncompilable source code - cannot find symbol
symbol: class CrawljaxConfigurationBuilder
location: class com.crawljax.core.configuration.CrawljaxConfiguration
at crawljaxexamples.CrawljaxExamples.<clinit>(CrawljaxExamples.java:12)
Exception in thread "main" Java Result: 1
Same code could be found in below Link,
https://github.com/crawljax/crawljax/blob/master/examples/src/main/java/com/crawljax/examples/PluginExample.java
Can someone please tell what are jars files required to run this program? Or is there any settings to be changed in IDE?
Thanks
It seems you are using old version of crawljax.
Download latest version crawljax-cli-3.5.1.zip
Add all jars from lib folder and crawljax-cli-3.5.1.jar from the main folder as lib path.
Tested and now it works well.
Brand new to Python & JYthon. I'm going through a simple tutorial and am struggling with the basics and am hoping for some insight.
Created a PyDev project called 'PythonTest' In that I created a module called test (test.py) and the code looks like this
class test():
def __init__(self,name,number):
self.name = name
self.number = number
def getName(self):
return self.name
def getNumber(self):
return self.number
I then created a java project called pythonJava and in it created three classes.
ITest.java which looks like this
package com.foo.bar;
public interface ITest {
public String getName();
public String getNumber();
}
TestFactory.java which looks like this
package com.ngc.metro;
import org.python.core.PyObject;
import org.python.core.PyString;
import org.python.util.PythonInterpreter;
public class TestFactory {
private final PyObject testClass;
public TestFactory() {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("from test import test");
testClass = interpreter.get("test");
}
public ITest create(String name, String number) {
PyObject testObject = testClass.__call__(new PyString(name),
new PyString(name), new PyString(number));
return (ITest) testObject.__tojava__(ITest.class);
}
}
And finally Main.java
public class Main {
private static void print(ITest testInterface) {
System.out.println("Name: " + testInterface.getName());
System.out.println("Number: " + testInterface.getNumber());
}
public static void main(String[] args) {
TestFactory factory = new TestFactory();
print(factory.create("BUILDING-A", "1"));
print(factory.create("BUILDING-B", "2"));
print(factory.create("BUILDING-C", "3"));
}
}
When I run Main.java I get the following error:
Exception in thread "main" Traceback (most recent call last): File
"", line 1, in ImportError: cannot import name test
Can someone advise me on what I'm doing wrong? I was under the impression I needed two imports one for the module (test.py) and the one for the class "test"
EDIT 1:
To avoid the easy question of my sys.path I have the following from IDLE
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600
32 bit (Intel)] on win32 Type "copyright", "credits" or "license()"
for more information. import sys print(sys.path) ['',
'C:\Python33\Lib\idlelib', 'C:\Python33', 'C:\Python33\Lib',
'C:\Python33\DLLs', 'C:\workspace\myProject\src',
'C:\Windows\system32\python33.zip',
'C:\Python33\lib\site-packages']
from test import test
t = test.test(1,2)
t.getName()
1
Actually, it seems a PYTHONPATH issue... as you're getting it from IDLE I can't say how things are actually in your Java env (and IDLE is using Python, but in your run you should be using Java+Jython -- in which case you're probably not using the proper sys.path for Jython -- at least I don't see any place having the PYTHONPATH defined in the code above to include the path to your .py files).
Also, if you're doing Java+Jython, see the notes on the end of: http://pydev.org/manual_101_project_conf2.html for configuring the project in PyDev.