I am currently trying to make a web-scraping program with jsoup. However, everything I have imported does not seem to show up when I compile my program, and it errors out saying it can't find any objects that I reference from jsoup.
This is how I imported it:
`
import java.io.*;//for website
import java.net.URL;//retrieve url
import java.util.logging.Level;//log errors
import java.util.logging.Logger;
import java.io.*; //I/O stream
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jsoup.Jsoup;//web scraper
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.net.URL;`
And these are the types of errors I'm getting:
Images.java:25: error: cannot find symbol
for(Element el : img){// for each element, get source (src) url
Where Element from jsoup cannot be found.
This is my environment variable set up, since I thought that would have to do with it.
This issue is very weird to me, because I seem to be importing everything correctly. I also have the jsoup.jar and the extracted jsoup files in the root directory of my project, if that is the correct way to do it. I am using the java10SDK to compile through cmd, and I have have tried using intelliJ ultimate to use their dependency injection, but I can't seem to figure it out. I have also tried to compile with java7, I am not sure if it actually compiled with it with the method I tried.
Classpath image as requested:
You shoul add Maven support to your project, because it is the easiest way to manage all the dependencies. To do that you just need to select your project folder in IntelliJ from the Project Toolbar and select "Add Framework support" and then scroll down until you see "Maven".
Once you add Maven support to your project you just need to Enable Auto-imports, IntelliJ itself will display you a menu to select if you want to Enable them or not, you have to select Yes.
Finally, you need to add this block to the new file created in your project folder called pom.xml, just before the project block closes (< /project>):
<dependencies>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.3</version>
</dependency>
</dependencies>
Once you do that, now you can import and use the JSOUP packages in your project. If you want to add more libraries, you can check out: https://mvnrepository.com/ and select the desired version of the library you want to install and copy&paste the dependency block on your Maven file.
As a tip, I highly recommend you to use a dependency manager (like Maven f.e.) for your projects and always add it once you create the project.
Hope it helps!
Related
I am building a simple project using Ant (not Maven as I need the project to be build and distributed in an .msi package when it is finished), added all the dependencies according to this article (end even more poi jar files) to the classpath and still I am getting the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/math3/util/ArithmeticUtils
It seems that there are more dependencies that the poi-4.1.2.jar file does not contain. Can I add them by hand or will it require more dependencies after that? And where do I have to look. (org.apache.commons.*)
As said building this project with Maven is not an option.
Here are all the imports I have in my class that fails to compile:
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
And those are the jar files added to the Libraries in NetBeans
poi-4.1.2.jar
poi-excelant-4.1.2.jar
poi-ooxml-4.1.2.jar
poi-ooxml-schemas-4.1.2.jar
xmlbeans-3.1.0.jar
You can look on the website what dependency you need for general operations.
Still, for me it seems, that all the import-dependecy are correct. Maybe the dependencies are not correctly added?
Every dependency can be added per hand, even those you mentioned in your post. There are two options:
add the dependency via POM (this one I cannot tell in more detail)
in Projects Structure:
go to Modules, then Dependency. Here you can add any dependency vial MAVEN PROJECT library. In your case just write org.apache.poi in the search field, click the search button and look up the list of dependency you need. Here is a picture of the last step without the list, the screenshot did not allow it.
Also, it can even happen, that your setting in the project structure is not correct. When I did everything, the dependecies were added with the Scope of "Compile", like in the picture
I did the whole procedure in IntelliJ, but it should be quite the same in all other IDE's.
I am working on a Java fx application and I need to import some libraries from com.google.maps.
I imported these libraries :
import com.google.maps.GeoApiContext;
import com.google.maps.PlaceDetailsRequest;
import com.google.maps.PlacesApi;
import com.google.maps.QueryAutocompleteRequest;
import com.google.maps.errors.ApiException;
import com.google.maps.model.AddressComponent;
import com.google.maps.model.AddressComponentType;
import com.google.maps.model.AutocompletePrediction;
import com.google.maps.model.PlaceDetails;
The java import statement is a little bit misnamed, it really means alias. import com.google.maps.GeoApiContext; really just means: Any time you find the type GeoApiContext anywhere in this source file, assume I meant to write com.google.maps.GeoApiContext.
Crucially, it does not 'invoke' any code in that class whatsoever, nor does it find or download any dependencies from the internet for you.
You will need to find the jar(s) that provide these classes and put them on the classpath of this project.
It can be as simple as downloading the relevant jar (perhaps com.google.maps-google-maps-services.jar?), put it in a lib dir someplace inside this project, finding that in the package explorer, right clicking it, and selecting 'add to classpath'.
Or, more likely, you want to use gradle or maven to take care of this for you: These tools turn simply mentioning the dependency in a list of libraries you require into automatically finding that on the internet, downloading it, configuring your IDE so that it knows where it is, and using that dependency during build and run steps.
we are trying to implement a web application for "Database Managment Systems" lecture.
We have used native wicket. (Not maven wicket repo, because i don't have a pom.xml file)
I want to use the Wicket Bootstrap DatePicker in the project. (http://agilecoders.de/demo/datepicker)
Can i use this datepicker extension in my project?
I downloaded the wicket bootstrap from github. (github(dot)com/l0rdn1kk0n/wicket-bootstrap/)
I found the sample file html/java codes. It imports these:
import de.agilecoders.wicket.core.markup.html.bootstrap.block.Code;
import de.agilecoders.wicket.core.markup.html.bootstrap.button.BootstrapButton;
import de.agilecoders.wicket.core.markup.html.bootstrap.button.Buttons;
import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.DateTextField;
import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.DateTextFieldConfig;
import de.agilecoders.wicket.samples.components.basecss.DatePickerModal;
import org.apache.wicket.Component;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.joda.time.DateTime;
import org.wicketstuff.annotation.mount.MountPath;
When i import the sources which start with "de.agilecoder...." Eclipse says "The import de cannot be resolved"
How can i solve this problem?
I dont want to use wicket's default datepicker, because it is hard to pick birthday from it.
I hope, i can expres myself.
Thanks.
If you don't want to use Maven in your project, there are two things you can do:
Use Maven to build the Wicket Bootstrap project: Download the project archive file (like you already did), download Maven and run mvn package in the Wicket Bootstrap project directory with a pom.xml file. This will result in bunch of "jar" files (under "subproject-name/target" directory) which you can add as dependencies to your project.
Just go to the "bootstrap-extensions/src/main/java/de/agilecoders/wicket/extensions/markup/html/bootstrap/form" Direcotry, copy the "DateTextField.java" File to your project (in appropriate package "de.agilecoders.wicket.extensions.markup.html.bootstrap.form") and resolve all dependencies for this class in similar way. But this sounds like really hard work... You could also learn Maven in the same time ;)
I have a simple XML file that I have parsed to JSON. All is fine and dandy, I have a Java class that is stand alone (i.e. it has a public static void main (String args[])....)
This has a private constructor (because I need to call it with Strings either a filename or the actual data). So I have two methods that return an instance of the object. I know a bit of Java as you can tell.
OK. When I run the code in Eclipse that runs the main method my file is loaded and decoded as required. It also works for a raw String that I run via JUnit.
So I know the following facts -
the parsing of a static String works and decodes perfectly
if I provide a file it is loaded and decoded correctly.
Now the issue:
As soon as I run it in Spring framework I can write to standard out the entire file content that I have run via the stand alone code.
But before it can run anything at all I get the below error -
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/json/simple/parser/ParseException
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:920)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
The stand alone code is run in Eclipse, and the Spring is run pointing to that code using Tomcat 7.
Why is it not finding the ParsException correctly?
The imports in the calling Spring controller are
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.commons.lang.StringUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
Is their a way of altering the build order, and would that fix it?
Looks like you have missed including the json-simple-.jar in your classpath. Include the same and it should get solved.
Hope this helps !
Add json-simple-1.1.1.jar file in your build path. On Eclipse, right click on project-> build path -> configure build path -> java build path -> add external jars -> select the jar file.
Add build path entry into deployment assembly. On the same properties window, Select "deployment assembly" option. Then add "Java Build Path" entries. This should show you the build path entry you just made in step one.
you are missing a jar deployment.
it is related for Tomcat7. A few jar needed to be exported ( forgot which ones) other web server doesn't need but Tomcat.
Could you please add this jar json-simple-1.1.1.jar in your classpath and try it out ?
This jar can be downloaded at http://code.google.com/p/json-simple/downloads/detail?name=json-simple-1.1.1.jar
The solution that I used in the end was to change to sourceforge.net json parser, a couple of code tweaks and my JUnit tests still worked and Tomcat did not complain. This may not be the best solution but it worked.
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
I have had a similar error and spent 3 4 hours removing and adding new jar files. What my problem was that i added jar file directly from the download location ie THE ZIP files ..!!! after adding a proper extracted jar file , My problem seems to be resolved. Hope this helps someone..!!
IF you are making an AI in Spring as I was when I had this error:
You also need to add the Jar to your AI "jlib" folder, for instance "...\AI\Skirmish\MyAI\0.1\jlib".
It's not enough to add it in Eclipse or Netbeans and build the project. Spring must have the jar too.
I know it is a late answer it but can help other people with the same error.
Use the below java library for process JSONArray and JSONObject
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20200518</version>
</dependency>
Just add maven dependency of JSON simple in your pom.xml. No need to configure any classpath.
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
I'm using Netbeans IDE 7.0.1.
I base my question on the CalculatorApp sample application available with the IDE.
The sample is running fine but I wish I could use some JSON, ad so I download google-gson-stream-1.7.1.jar library, and included it in my libraries :
- right click on "Library", then "Properties" then "Add JAR/Folder" and selected my JAR (located somewhere in "My Documents/Download".
The problem is that when i type the following :
import com.google.gson;
(or even com.google), the IDE fires a "Package com.google does not exist". The JAR and its hierarchy is correctly shown on the left side pane,in the "Libraries" section. Most surprising, the IDE can autocomplete the com.google.** stuff.
AFAIK, I need to further to get this work, don't I ? Any ideas ?
Thank you !
In Java, import statements are for classes and interfaces (types) not for packages themselves. Are you sure you tried to import a class under com.google.gson package and not the package itself?
import com.google.gson.Foo; should work.
So should
import com.google.gson.*; or
import com.google.*;
Note however that wildcard imports aren't particularly recommended.
I am using:
import com.google.gson.Gson;