Cannot resolve json import Intellij after adding dependency and library .jar - java

I cannot seem to resolve this issue after adding the json-lib-2.4-jdk15.jar from an online source to the project dependencies, screenshots provided to show walkthrough of what I am doing. (and yes I have repeatedly tried "Invalidate caches and restart")
The error:
This is my Project Structure ("cmd + ;" or "File > Project Structure")
It doesn't seem to work on "Scope" set to Compile either. Note that I added the .jar file as a library too because I'm just really unsure as to why I can't get this to work. Any help is greatly appreciated, thanks.
What do I seem to be doing incorrectly here?

The jar you have downloaded from https://sourceforge.net/projects/json-lib/ doesn't contain the classes you need. This jar contains net.sf.json package which is a different implementation of JSON Java library.
You are trying to use org.json.* classes which are provided by another library. The library you want to use is this one: JSON-java. At the bottom you can find the link to the Maven repository where you can get the jar file.
The latest version (at the moment of this reply) direct download link for the jar is here: json-20160810.jar.
Add it to the module dependencies and your problem should resolve.
Next time you observe similar issue browse inside the library jar under External Libraries node of IntelliJ IDEA project view and see what classes it contains and under which packages. This way you would know if the issue is caused by the wrong jar you've added to the dependencies and which doesn't actually contain the classes you want to use.

Related

No source code is available for type com.google.gwt.ajaxloader.client.AjaxLoader;

I am migrating an project someone else built to newer packages and I have traced the root of my errors to this
No source code is available for type com.google.gwt.ajaxloader.client.AjaxLoader; did you forget to inherit a required module?
I am new to GWT and not really sure how it works 100% under the hood so I am having trouble applying solutions to similar posts to solve this error.
go to Maven Repository and get gwt-ajaxloader.jar - it contains both .java and .class files
save the jar to war/WEB-INF/lib folder in your project
right-click on the file in Project Explorer (I assume you use Eclipse), select Build Path -> Add to Build Path
enjoy ;)
GWT needs source code as opposed to .class files to do its work.
So any references you might have from your client code towards any jars, etc, need to also include source code.
In your case, you either need the source of com.google.gwt.ajaxloader.client.AjaxLoader, or remove any references towards the mentioned class, from your GWT code.

How can i open an Akka project using eclipse?

i am trying to create a simple hello-akka project using the typesafe activator. I have everything working and the project even runs in the typesafe tab. I clicked on create eclipse project, and some files are added to my directory but i cannot figure out how to open them and run the file in eclipse!
These are the files i currently have in the directory:
.sbtserver
project
src
target
gitignore
(GITIGNORE FILE?)
activator.bat and activator.jar
build.sbt
In another workspace i tried creating my own scala project, by adding akka-actor.jar to the libary but i get the following error :
Description Resource Path Location Type
missing or invalid dependency detected while loading class file 'ActorSystem.class'. Could not access term typesafe in package com, because it (or its dependencies) are missing. Check your build definition for missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.) A full rebuild may help if 'ActorSystem.class' was compiled against an incompatible version of com. tst Unknown Scala Problem
Any help or suggestions would be greatly appreciated!
There are quite a few dependencies you'll need to find and add if you're determined to make this work -- a scala-library, for example. It's better to find a way to integrate your build with your IDE if you can -- this will allow the IDE to find dependencies the same way the build does -- and in this case, the build system is SBT.
The easiest path forward may be to download ScalaIDE, which is a Scala specific package for Eclipse. This should come ready to go with support for SBT projects. Most Actor/Scala devs I know use IntelliJ or ScalaIDE.
Another option would be to use the SBT plugin for Eclipse, but in my experience it tends to be unreliable, changing with far less frequency than the IDE itself. If you install it and it doesn't look like it's working, you're probably right.
Finally, you can ditch SBT for Gradle or Maven and then use the Gradle or Maven plugins for Eclipse. If you have either of those in your shop already this is likely something you will need to do down the road, anyway. SBT is a good build system but nowhere near as feature rich as Gradle or ubiquitous as Maven.

Is there a way by which i can automatically add dependencies based on the jar files present in my build path using maven?

I have a j2ee project which is having many jar files attached to it, now i want to convert it to a maven project, is it possible to get all the dependencies of the attached jar files in the pom.xml automatically without adding them one by one manually?
Sorry if this is a noobish question !
AFAIK, you cannot.
But your IDE could help you. Netbeans or Eclipse both help you to find the names of the group and the artifact for almost any library.
On Netbeans it is Add Dependency.
On my opinion: yes, you can. Will you try such scenario: import your project into Eclipse, then convert project into Maven project throw context menu on project. It's not easy way, but this solution is worked. May be another IDE can convert more effective.

proper way to configure a project in eclipse for eSWT?

can someone direct me on how to configure a project in eclipse so that i can utilise eSWT.
Just by manually adding eswt-converged.jar gives me build/pre verification errors.
I downloaded this and utilised the jar from the folder and copied it to my project folder and added it to the build path.But it shows me something like
Please help.
EDIT
i did what Neil said and i am getting this now:
I see that in the link you provided, there are a number of other jars that I don't see included in your project. If I had to take a guess, your jar is heavily dependent on these jars which aren't there, so all the classes that it uses which are defined in these jars simply aren't there.
Though, without further information on the nature of the problem, it's difficult to determine anything else I'm afraid.

Tool to remove unnecessary dependencies in a Java project

I have a Java project that currently has a lot of JARs in its libraries directory, which are all included in the resulting package when building. I know, however, that some of these libs are never referenced in the project.
Is there a tool that can search for libs that are not referenced within the project? I guess there must be something in that sense.
BTW, an Eclipse plugin would be awesome.
EDIT: I chose to go with ClassDep because it was the only suggestion that worked. However, I'm having some trouble with it: please check this question
Beware of the case that a class is loaded via Class.forName() and not specified as a dependency in the manifest file (there is a Depends-On: attribute that is for that, but many people don't specify it, which breaks tools like this, the bane of my existence when I worked on such a tool).
ClassDep (from Sun, in the Jini development kit) will do this for you.
ClassPathHelper can help you with that.
Espacially the "Not on Classpath View"
This view scans for jars that are not on the classpath (but are under the current project). It provides basic browsing of packages and classes that are available but not on the classpath. This can be helpful when trying to build up a classpath, as you can quickly browse for the missing classes to see which jars contain them.
Not an eclipse plugin, but I believe the "shrinking" functionality of ProGuard is exactly what you're looking for.
I wrote a small eclipse plugin that takes an existing java project from the workspace. For every classpath entry of the projects raw classpath it removes it from the projects raw classpath and builds the project. If no problem markers with severity error appear on the project, it permanently removes the classpath entry from projects raw classpath.
I'm not able to share that plugin, but that is not too much work to implement it yourself with the links to the api given above.
You also can't tell if JARs that you don't import are required dependencies of dependencies. For example, if you use Spring it comes with its own dependencies, even if you don't import or call those classes in your code. I'm ignorant of ProGuard - does it check for those cases?

Categories