Libgdx: The import org.json cannot be resolved - libgdx

The following error occurs when I try to compile my project to Html with gradlew html:superDev command. In Android and Desktop is Ok.
[ERROR] Line 14: The import org.json cannot be resolved
[ERROR] Line 51: JSONObject cannot be resolved to a type

You need sources for every library you use for GWT to compile it to JS.
As a general advice, if you use features libGDX provides itself, you should not use third libs to avoid such problems. Use the built-in json parser.

Related

Using json as a source for cxf-wadl2java

I received a specification of a RESTful service in json format and need to create a java api library for the client.
Now swagger can do it without a problem, but I would prefer to use cxf-wadl2java maven plugin. By default it doesn't expect the json format. See the exception cause stack trace below.
Is there a way to configure the cxf-wadl2java plugin to read json document?
Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '{' (code 123) in prolog; expected '<'
at [row,col {unknown-source}]: [1,1]
at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:653)
at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2133)
at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1181)
at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1367)
at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1261)
at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1189)
at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1178)
at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1168)
at org.apache.cxf.tools.wadlto.jaxrs.SourceGenerator.readXmlDocument(SourceGenerator.java:1757)
... 32 more
May be you can have two step conversion. swagger.json to wadl file and then use wadl2java plugin.
Install npm in you machine
Use maven exec plugin and run command defined in this npm package to convert from swagger to wadl.
Use cxf wadl2java plugin to generate java file from generated wadl file from above.
EDIT
There is a maven plugin provided by swagger.io. Please refer a usage example here

Problems with Clojurescript quickstart -- build fails

I'm trying to follow the Clojurescript Quick-Start
I have downloaded the Clojurescript jar as described in the Quick-Start guide. I have verified that it has the appropriate size (about 19M). I have created the files. But when I try to build using the command:
java -cp cljs.jar:src clojure.main build.clj
Java returns the following stacktrace:
Exception in thread "main" java.io.FileNotFoundException: Could not locate cls/build/api__init.class or cls/build/api.clj on classpath., compiling:(/Users/jnedzel/Documents/prj/closurescript/quickstart/hello_world/build.clj:1:1)
at clojure.lang.Compiler.load(Compiler.java:7249)
at clojure.lang.Compiler.loadFile(Compiler.java:7175)
at clojure.main$load_script.invoke(main.clj:275)
at clojure.main$script_opt.invoke(main.clj:337)
at clojure.main$main.doInvoke(main.clj:421)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.lang.Var.invoke(Var.java:379)
at clojure.lang.AFn.applyToHelper(AFn.java:154)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
Caused by: java.io.FileNotFoundException: Could not locate cls/build/api__init.class or cls/build/api.clj on classpath.
Any ideas?
TL;DR: There's a typo in build.clj
Full explanation
As of the Quick-Start, the file build.clj should have the following content:
(require 'cljs.build.api)
(cljs.build.api/build "src" {:output-to "out/main.js"})
The error message says Could not locate cls/build/api__init.class. When the clojure compiler compiles a ns, a loader classfile is generated with the name my/domain/lib__init.class. That's the class that will be loaded given (require 'my.domain.lib).
In the case of cljs.build.api, that would be cljs/build/api__init.class. But it is trying to load cls/build/api__init.class instead, so you have a typo there.

How to setup Robot Framework standalone jar with SwingLibrary?

I'm using Robot Framework with SwingLibrary to test a Java Swing based application. Since I'm not used to Python and also don't want to setup the Python environment, I decided to go with the Robot standalone JAR version (current version 2.8.4).
My problem is the setup in combination with SwingLibrary (version 1.8.0). I don't know where to put the library such that it gets recognized by Robot.
So far, I have the following test case (mytest.txt):
*** Settings ***
Library SwingLibrary
*** Test Cases ***
MyTestCase
Start Application MyApp
I tried with putting the standalone jar in conjunction with the test case in a folder, and created one subfolder (called it Lib) where I put the SwingLibrary JAR (and later also extracted the JAR).
I added the SwingLibrary as well as my own application to the classpath, tried executing robot the following way:
java -Xbootclasspath/a:Lib/swinglibrary-1.8.0.jar:Lib/MyApp.jar -jar robotframework-2.8.4.jar mytest.txt
and also with
java -jar robotframework-2.8.4.jar mytest.txt
I always get one of the following errors:
[ WARN ] Imported library 'SwingLibrary' contains no keywords
==============================================================================
Mytest
==============================================================================
MyTestCase | FAIL |
No keyword with name 'Start Application' found.
or
[ ERROR ] Error in file 'mytest.txt': Importing test library 'SwingLibrary' failed: ImportError: No module named SwingLibrary
You can use the standalone jar without the -jar option, allowing you to specify the classpath in the standard manner. The main class for the standalone jar is org.robotframework.RobotFramework, so the syntax would be
java -cp robotframework-2.8.4.jar:Lib/swinglibrary-1.8.0.jar:Lib/MyApp.jar org.robotframework.RobotFramework
Slightly more verbose but it's standard and so avoids any oddnesses caused by using the non-standard -Xbootclasspath option.

Error while parsing json in J2ME

I am running Java ME application in Eclipse..I have JSON code in my pp and I have also json.jar lib, but when I run the application, I get an eror like this.
Uncaught exception: java.lang.NoClassDefFoundError: org/json/me/JSONObject
- parsing.Parsing$1.run(), bci=88
Looks like your json.jar lib is not bundled with your app code. The contents from json.jar must be available inside the final app jar file.
If you are using Eclipse Pulsar be sure to check this lib at Project .. Properties .. Java Build Path .. Order and Export tab.

Why does Jython refuse to find my Java package?

I know it's something silly, but for some reason Jython refuses to find javax.swing. I'm using Java 1.6.0_11. This is my start-up script:
#echo off
"%JAVA_HOME%\bin\java" -Xmx1024M -classpath ".;c:\Projects\Jython2.5.1\jython.jar" org.python.util.jython
My output looks like:
Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54)
[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_10
Type "help", "copyright", "credits" or "license" for more information.
>>> import javax.swing
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named swing
>>> import javax
>>> dir(javax)
['__name__']
>>>
Most likely Jython is not scanning your packages. On startup, Jython tries to go through the jars and class files on its path and scan for Java packages. This is necessary because there is no way to look for Java packages by reflection. Package scanning can be deliberately turned off, or you could lack write privileges where it wants to write the cached information out see http://wiki.python.org/jython/PackageScanning for more. The best way to import Java classes is to do so explicitly class by class, like so:
from javax.swing import JFrame
This method should always work, even if package scanning is off or otherwise unable to work, and is the recommended approach (though it can be a bit tedious). If you do want to import packages (or if you want to do "from javax.swing import *" which also depends on package scanning - but is discouraged) you will need to figure out why your package scanning isn't working.
I had similar issues, and it turns out that since the standalone Jython dist does not support caching, it also does not support the "import *" approach. This is not clearly documented anywhere in the official Jython docs, but I concluded this based on a number of different bug reports:
https://groups.google.com/forum/?hl=en&fromgroups=#!topic/robotframework-users/6ipB0DYJkvU
http://bugs.jython.org/issue1778514
http://bugs.jython.org/issue1422
http://bugs.jython.org/issue1692579
Notable from that last link:
So as Oti noted, in standalone you must do full imports to succeed.
To fix your issue, use the non-standalone standard jython.jar generated by installing jython using the 'Standard' option.
If you wanted to package and distribute jython.jar with your application, in case a user does not have Jython installed, then you will also need to copy/pase the complete "Lib" folder from the jython installation directory into whichever location you end up placing jython.jar. This enables access to the python stdlib which is not included in the standard jar file.
UPDATE:
After playing around more, I think I have a fix to enable "import *" type imports even when using the standalone jar. All that needs to be done is to enable caching!
You can do this by either adding the following options to the jvm when running jython:
-Dpython.cachedir.skip=false -Dpython.cachedir=DESIRED CACHE PATH
(Note that the second argument is optional, and if left blank, a default value will be used)
If you are having an issue running the InteractiveConsole embedded in an app (which is what my problem was) you can add these properties before initializing the console:
Properties props = new Properties();
props.put("python.cachedir.skip", "false");
props.put("python.cachedir", "DESIRED CACHE PATH"); // again, this option is optional
InteractiveConsole.initialize(System.getProperties(), props, new String[0]);
I'm using Java 1.6.0_11
No, you're using
[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_10
What happens if you delete the cachedir from the Jython distribution directory, and try again?
Also, why are you explicitly setting the classpath that way? Why not simply
java -jar jython.jar
?