How to add Tika to my project classpath? - java

I'm trying to use a Tika class.
I am Following the instructions here: https://tika.apache.org/1.6/gettingstarted.html
I'm on OS X, and I'm using Eclipse 4.5.1 Mars 1.
The jar files have been built, and I don't understand how to make those classes available in my class. I don't know what they mean by 'as a Maven dependency' vs 'in an Ant project'
I've added tika-core-1.11.jar tika-parsers-1.11.jar in Project Properties / Build Path / Libraries
The code is:
import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.mime.MediaType;
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.AbstractParser;
import org.apache.tika.sax.XHTMLContentHandler;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
...
{... AutoDetectParser parser = new AutoDetectParser(); ... }
but
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
AutoDetectParser cannot be resolved to a type
How to make those classes known to the compiler ?

You should add both tika-core-{version}.jar and tika-parsers-{version}.jar to your build path. You should be able to do this by right clicking your project name and choosing Build Path->Add External Archives. (Note: these directions work in Eclipse Kepler with Tika 1.11, but other versions should be similar.)
Also make sure that you import org.apache.tika.parser.AutoDetectParser before referencing it in your code.
If you want full functionality, make sure you have added all the jars listed under Build Artifacts on the Tika Getting Started page (https://tika.apache.org/1.6/gettingstarted.html).

Related

Encountering a Problem in IntelliJ which only accepts Wildcard Imports of java packages instead of specific Classes from java packages

Information about my Project:
Gradle Version 6.8.3
Lombok Version 1.18.18
IDE Version 2020.3
My JAVA_HOME Path in the Windows environment variables is set to the newest Java JDK (15.0.2). The Project Language in the Project Structure Path is also set to Java 15.
I am currently using IntelliJ version 2020.3 and since a few days I have the following Problem.
When I want to import specific Classes or Interfaces from the java package e.g java.time.LocalDate. IntelliJ marks this import as an unused import Unused Import java.time.LocalDate
After I replace the LocalDate with an Wildcard * the Message is gone java.time.*
In the next Step I did the same with another Class I want to import. This time I used the java.util.Set import. The same message occurred after I wrote Set<TestClass> foo;. Cannot resolve Symbol 'Set'
When I replaced the java.util.Set with java.util.* the Message disappeared. Wildcard import for java.util
I got this Problem everytime I want to import a specific Class from the Java JDK libraries. When I import libraries from the Gradle Dependencies everythings works fine. So this Problem only occurs on Java libraries.
I Already tried the following Steps to solve the Problem:
import Project with IntelliJ VCS
Checked if there are any incorrect settings in Project structure
File -> Invalidate Caches/Restart
Project Structure -> Project SDK and added the same Java JDK again
Ctrl + Shift + A and Restored default Settings
Code Sample:
import java.time.LocalDate;
import java.util.*;
import lombok.Getter;
import lombok.Builder;
#Builder
#Getter
public class TestClass {
private LocalDate testDate;
private Set<TestClass> foo;
}
After Installing Eclipse and getting the same Error Reports like in IntelliJ. I reinstalled jdk 15.0.2. I reopened the project again in IntelliJ and everything worked fine. IntelliJ recommend imports when I used java.util classes. So I will close this question now. Thank you guys very much for trying to help me with this problem. In the end it was something much easier which fixed the problem.

What is the correct package name for importing MigLayout?

FYI, I'm new to Java development and Netbeans!
I have downloaded the MigLayout jar files, both core and for swing, and added their path in the NetBeans 8.2 IDE under 'Tools->Libraries->Library_Classpath'.
My problem is that I'm trying to use the API MigLayout() but every package name that I've tried to import it results in the error "package 'Package_Name' does not exist"
The following package names fail at compile time:
import MigLayout;
import net.miginfocom.MigLayout;
import net.miginfocom.swing.MigLayout;
The following package names only fail at run time:
import net.miginfocom.layout.Grid;
import net.miginfocom.swing;
import net.miginfocom.miglayout;
Links to the MigLayout forum are broken, and none of the tutorials I've seen have the import statements. All I am asking for is a link to or list of the packages needed to use MigLayout.
If MigLayout is no longer supported, it would be nice to know that as well!
Of all packages you mentioned, the following are actually working:
import net.miginfocom.swing.MigLayout;
import net.miginfocom.layout.Grid;
It is not enough to set the jar files in the library configuration of NetBeans (Tools > Libraries). You also need to set it inside your project to get your classpath working.
In the projects view, locate the directory called Libraries (JDK will be located there) and right click on it, then click on Add Library and choose the library where you defined your jar files, in your case Library_Classpath.

How to search unresolved libraries in Intellij IDEA or Android Studio?

I'm trying to port Apache Flink to Android. One of the biggest problem is that some java tools doesn't exist for Android, but these conflict are not detected at compile time and the errors (NoClassDefFoundError excpetion) are detected only at runtime.
For example, Java's ManagementFactory doesn't exists for android, BUT no compile error is thrown even if in this class there are unresolved symbols/libraries, in particular:
import javax.management.MBeanServer;
import java.lang.management.BufferPoolMXBean;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.MemoryType;
import java.lang.management.MemoryUsage;
Now, I included the Flink's jars (flink-clients, flink-java, flink-runtime and flink-streaming) in my Android Studio project and I would like to search all these kind of unresolved dependencies to avoid these kind of exception at runtime. There is any Android Studio tool for this purpose?
I think including jar dependencies in the project will not make Android Studio and a compiler to search for missing classes in already built jars. Try to include src of flink into your project. I tried that and I had all unresolved imports being red.

How to add (import) java websocket library to my project?

First, sorry if question is trivial - I'm new to java world.
So, I've created new project. Then I downloaded websocket jar file here:
http://www.java2s.com/Code/Jar/j/Downloadjavawebsocket130jar.htm
After that I've created 'lib' dir, copyed jar file there, selected it, added to build path.
Basically, I was following instructions from here:
http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-%28Java%29
Then I copied source code into my class:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.Collection;
import org.java_websocket.WebSocket;
import org.java_websocket.WebSocketImpl;
import org.java_websocket.framing.Framedata;
import org.java_websocket.handshake.ClientHandshake;
import org.java_websocket.server.WebSocketServer;
So, first part of imports is ok...standard Java imports. But problem is second group. For every import, starting from:
import org.java_websocket.WebSocket;
I'm getting error "Import.... can not be resolved." And rest of the code that's using those classes is shooting errors because of that of course.
So, I added jar file to build path, but I still can't import classes from that library. What's missing here?
First, extract the jar from the zip file, then right click the folder you're working on in your Eclipse. Click "Build path", then click "Configure Build Path", then click on "Libraries" and on the right hand side click on "Add external Jars", and then find your extracted jar.
Download the bundle from the below repository.
MVN Repository
This should resolve your issues.

Java library import difficulty

I'm trying to compile a small test program I have written for a raspberry pi.
The program makes use of the Pi4J library to control the piface add-on board.
What I have done so far is based on the following tutorial: http://www.savagehomeautomation.com/piface
While I can get the above example program to compile within my IDE after setting up the class paths I get compile errors with the one I have made and as far as I can tell the imports are set up in the same way.
It says that each of the following packages does not exist:
import java.io.IOException;
import com.pi4j.component.switches.SwitchListener;
import com.pi4j.component.switches.SwitchState;
import com.pi4j.component.switches.SwitchStateChangeEvent;
import com.pi4j.device.piface.PiFace;
import com.pi4j.device.piface.PiFaceLed;
import com.pi4j.device.piface.PiFaceRelay;
import com.pi4j.device.piface.PiFaceSwitch;
import com.pi4j.device.piface.impl.PiFaceDevice;
import com.pi4j.wiringpi.Spi;
I'm assuming that my problem is relatively simple but I don't really understand how import statements work and it's quite vague topic to search about. I have included some file paths if that helps.
This is where my project resides:
/home/pi/JBerries/relay
and this is where the pi4j library is:
/opt/pi4j
I hope the following image provides some of the information requested, note that the class paths are already set up:
You need to set the CLASSPATH environment variable to /opt/pi4j or the jar file therein. WIthout this the compiler is unable to know where your libary is located and will give you the errors you describe.
If you're using a project in JBerries you need to configure the classpath for the project - the screenshot shows the classpath for single-file compilations only. To edit the project config right-click the root node in the project window and select properties.

Categories

Resources