Axiom class cannot be found - java

I'm trying to compile a simple SOAP client example shipped with Axis2. However the Java compiler cannot find the imports:
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
I have checked my classpath variable is up-to-date on the command line and it includes:
C:\axis2-1.6.1\lib
I have also checked the lib directory contains the required Axiom jars (it does)
axiom-api-1.2.12
axiom-dom-1.2.12
axiom-impl-1.2.12
And that these jars match the package I'm importing (they do). How can I still be getting the error:
error: package org.apache.axiom.om does not exist
?

Asix2 User Guide describes the directory structure and the use of Axis2 tools to prevent the need to set the CLASSPATH environment variable:
The bin directory includes a number of useful scripts. They include
axis2.bat (or axis2.sh), which enables you to easily execute a Java
command without having to manually add all the Axis2 jar files to the
classpath

Related

Why poi-4.1.2 for xls dos not find dependencies even though classpath is right?

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.

Eclipse cannot import import com.google.maps.* (For java Fx programme)

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.

How do I set up extJWNL in a Java project?

I am trying to determine whether a set of strings, from an English sentence, are all words from the WordNet dictionary. I put the JARs in a folder in my project in eclipse.
I've downloaded the binary release of extJWNL and put the JARs in a folder called lib.
I also added these jar files to the class path and the module path using Right Click > Build Path > Configure Build Path:
I used the following code to try to import dictionary
import net.sf.extjwnl.dictionary;
This error is shown on the import statement
The package net.sf.extjwnl.dictionary is accessible from more than one module:
<unnamed>, extjwnl
I thought that this error was showing up because it was a package, not a class/type. But adding a new class and trying to change the package doesn't show this new package, namely WORDNET_JARS, just the default package.
Why is this error being returned and what do I need to do to get rid of the error and import the wordnet packages?
Platforms
I am using Eclipse IDE, and write all this code in Java. The API I am trying to import is the WordNet API.
Edit (8/21/2019)
By removing the module path, it gives a new error:
Only a type can be imported. net.sf.extjwnl.dictionary resolves to a package
I'm surprised it was this easy:
Instead of
import net.sf.extjwnl.dictionary
I had to do
import net.sf.extjwnl.dictionary.*
to get all the types. The only other thing that had to be done had already been done where I add the JARs to the class path

why some imports cannot be resolved?

I'm new to java , i tried to use word net for senitment analysis .
when i used class of wordnet , i got the following failure in importing
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.lucene.analysis.en.EnglishMinimalStemmer;
import org.apache.stanbol.commons.stanboltools.datafileprovider.DataFileListener;
import org.apache.stanbol.commons.stanboltools.datafileprovider.DataFileTracker;
import org.apache.stanbol.enhancer.engines.sentiment.api.LexicalCategoryClassifier;
import org.apache.stanbol.enhancer.engines.sentiment.api.SentimentClassifier;
import org.apache.stanbol.enhancer.engines.sentiment.util.WordSentimentDictionary;
import org.apache.stanbol.enhancer.nlp.pos.LexicalCategory;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;
all the above imports cannot be resolved like org.apache.felix , org.apache.lucene ,org.apache.stanbol,org.osgi
This is because your compiler is not able to find the necessary packages and or libraries that are needed to resolve these imports. These packages must be included in your class path. For example all of the errors regarding
org.apache.felix.scr.annotations.x
can be resolved after downloading the latest .jar from https://mvnrepository.com/artifact/org.apache.felix/org.apache.felix.scr.annotations/1.11.0
Follow these steps to include jar files in your class path.
-
Drag the required jar file from your download directory to the src
directory of your project in eclipse
Right click on the jar file, Select Build Path and then select Add To Build Path option.
A dialogue box will appear asking you to link all files in the jar file, just stick with the defaults and hit OK.
You are done now, all your errors regarding imports will be resolved.
These packages need to be within the compiler's class path.
Another way to say it : the compiler needs to be able to know where to find these files. This imposes several constraints:
these files need to actually exist in your hard drive (whether added manually, or automatically by a dependency manager)
they should be organized in folders that match the parts of the package name
the folder where they are must be within the class path, which can be specified with the 'classpath' compiler option, or in your IDE's options

Java using classes from jar

This must be a super overasked question. Although here goes:
I have a java file for testing around (hworld.java) and am trying to import conio.jar, a JAR which is a wrapper of Conio. The JAR contains only one class file (conio.class) and META-INF. Trying to do import conio.* or import conio.conio shows me this:
C:\Documents and Settings\Nick\Desktop>javac -cp *.jar; hworld.java
hworld.java:3: error: package conio does not exist
import conio.*;
^
1 error
And compiling it like javac -cp conio.jar hworld.java still errors out while compiling. I even extracted the jar and had conio.class in the same directory as hworld.java but to no avail. The JAR is in the same directory as hworld.java, as well.
Anyone have any idea on how to fix this?
You don't mention whether conio.class is defined in package conio. If it is not, then simply use the class without importing it. Remove the import.
It's actually not possible. You need to put the other class in a package if you want to import it.
What's the syntax to import a class in a default package in Java?
Find out what package Conio is in - an easy way to do this is to open the jar as a zip file, the package will correspond with the folder structure of the archive. For example if Conio is in x/y/z then import x.y.z.Conio and compile/run with conio.jar on the classmate.

Categories