Only a type can be imported. org.apache.poi.hssf.usermodel.HSSFWorkbook resolves to a package - eclipse

Trying to use Apache POI in a Eclipse JSP project. The POI jar is in the project's Java Resources Library list.
<%# page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
at run the following error occurs:
An error occurred at line: 7 in the
generated java file Only a type can be
imported.
org.apache.poi.hssf.usermodel.HSSFWorkbook
resolves to a package
Any ideas? Thanks
Don Lawton

The message indicates that the class could not be found on the classpath of your deployed application. Did you make sure that the POI jar is in your WEB-INF/lib folder?

Same happened to me, even when the needed jars were indeed in the WEB-INF folder.
I was using the provided server in SpringSource ToolSuite (STS). It took me several attempts to clean, republish, etc... before it finally worked.

Related

Error occurred during initialization of boot layer java.lang.module.FindException executing Selenium tests using TestNG and Java 12 through Eclipse

ErrorOccuredDuringInitializationofbootlayer I keep getting this error when I run
my test:
Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for
C:\Users\Bonfire.eclipse\org.eclipse.platform_4.12.0_867647348_win32_win32_x86_64\plugins\com.beust.jcommander_1.72.0.jar
Caused by: java.lang.IllegalArgumentException:
com.beust.jcommander.1.72.0: Invalid module name: '1' is not a Java
identifier
How can I fix it?
Add TestNG Library to classpath in buildpath ( not to module path). It will work fine.
To avoid this error, do not add TestNG library in the project or src folder. Try adding it into the package. To do so , follow the below mentioned procedure.
Right click on the package, click Build Path->Configure Build Path, go to Libraries tab, select Classpath and click on Add Library to select TestNG.
This error message...
Error occurred during initialization of boot layer java.lang.module.FindException:
Unable to derive module descriptor for C:\Users\Bonfire.eclipse\org.eclipse.platform_4.12.0_867647348_win32_win32_x86_64\plugins\com.beust.jcommander_1.72.0.jar
Caused by: java.lang.IllegalArgumentException: com.beust.jcommander.1.72.0: Invalid module name: '1' is not a Java identifier
...implies that there was an issue with the java classpath.
As per the discussion Launch with java 11 fails: Error: Could not find or load main class with Caused by: java.lang.ClassNotFoundException: with there are some issues with some particular classpaths for java-11 and the launch fails if:
The classpath contains a folder with spaces
The classpath length is larger than 32767 characters.
Where as java-8 works fine.
Reference
Unable to import org.openqa.selenium.WebDriver using Selenium and Java 11
Outro
Eclipse plugin: TestNG testcase does not run with Jdk11
Need to add 1.8 version library
Remove TestNG from build path library and add again
Recheck - the issue should be resolved.
I got same issue and I solved it. When creating the project, don't create module-info.java. When the project was already created with the module-info.java, deleting this file didn't help me.
I just created new project without module-info.java, and all works good now.
Best option to resolve this:
Find all file and folder starting with . e.g. — .metadata / .setting and delete them.
Add all the JARS.
Add testNG Libraries.
Execute it.
Done.

Eclipse JAR at runtime

I'm importing several JARs all sitting in the same directory. When my program runs I'm able to access the classes in several of those JARs, no problem. So my classpath is fine (I assume). But there is one JAR giving me trouble. When I try to run:
Configuration conf = new BaseConfiguration();
I get a NoClassDefFoundError error. The searching I did on "NoClassDefFound" typically points to classpath problems but as mentioned above, other JARs in the same directory are being found so I think that's not the problem.
This is in Eclipse 3.8.
The import statements:
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.configuration.Configuration;
And the name of the JAR is:
commons-configuration-1.6.jar
Any ideas?
Tom
Perhaps it's failing to load a dependency of one of the classes in commons-configuration-1.6.jar? Maybe from another commons- JAR? The NoClassDefFoundError should tell you which class the runtime failed to load. Have you checked this?

can't compile play showcase html

I installed playN however I get this error:
[INFO] --- gwt-maven-plugin:2.4.0:compile (default) # playn-showcase-html ---
[ERROR] Error: Could not find or load main class com.google.gwt.dev.Compiler
I checked the m2 repository, and the gwt jars for 2.4 2.5 gwt seem to be there.
If I try to use GWT 2.5 in the project then I get this
The GWT SDK 'C:\Users\user.m2\repository\com\google\gwt' on the project's build path is not valid (Version is not supported, must be 2.0.0 or later)
playn-showcase-html
Unknown Google Web Toolkit Problem
Does this make sense at all?
How to fix it?
Thanks
It seems that some gwt jars in the maven repository were corrupted. I deleted them, i run the playN sample again, the jars were downloaded correctly, and the whole think worked
C:\Users\user.m2 <-- this is very strange. it looks like somehow your maven repository path is munged up.
Check your environmental variables for MAVEN_REPOSITORY and see if its set to C:\Users\user. Also, find your maven installation directory, and look under the conf directory for a settings.xml, and see if you have <localRepository>${env.MAVEN_REPOSITORY}/.m2/repository</localRepository>.

Error in Eclipse about type indirectly referenced from required .class file

I'm having this exception with some stubs generateds by Axis2:
"The type org.apache.axiom.om.OMElement cannot be resolved. It is
indirectly referenced from required .class files"
I've been reading many posts, and trying to find a solution. What I've found so far is to add the apache tomcat 5.5 library to the build path. It removed the error in the java file, but then, when I to execute any java program inside the project, I got this error:
'Launching myApp' has encountered a problem Exception occurred
executing command line. Cannot run program "C:\Program
Files\Java\jdk1.5.0_22\bin\javaw.exe" (in directory
"D:\Digicel\workspace\Digicel\myClassSample"): CreateProcess error=87,
The parameter is incorrect
then if I remove the apache tomcat library from the build path, I can run the other java programs, but not the one mentioned initially.
Any thoughts about it?
Okay, I've found the cause of the problem with the help of a friend :)
The thing is that Eclipse is aware that one of my dependencies, depends of another library, and Eclipse is checking for it when it tries to build the code.
So, what I've done is try to check which jar file contains this library: " org.apache.axiom.om.OMElement".
I've googled it and found that it is "axiom-api-1.2.10.jar" and finally my file compiled with 0 errors.
He also explained to me that my original solution of adding the apache tomcat server library is adding all the jars that cames with apache tomcat (which is a big list), and probably there may have been a version conflict with my current list of added jars.
So, the fix was to find the appropriate jar and add it to the project.
This error can also occur when a indirect dependency has a corrupt jar file. This may be caused by problems at the public maven repository.
If this is the case removing the local maven repository to download fresh jar files will fix your problem:
rm -Rf ~/.m2/repository/{enter/path/to/broken/stuff}
Goto Maven >Update Maven project>checkmark the Force update >Then Run
..That error Will gone....

NoClassDefFoundError in Eclipse when adding project in build path

I am receiving an NoClassDefFoundError in Eclipse when I try to run my project.
My Project looks like this:
JavaProject: BulkAdmin
- src
- com.mycompany.bulkadmin.SDK.util
- Login.java
Dynamic Web Project: JSPTesting
- src
- com.mycompany.bulkadmin.jspController
- Controller.java
- WebContent
- index.html
- execute.jsp
This is the control flow:
index.html loads
index.html has a form that redirects to execute.jsp
execute.jsp takes the info returned in the form and makes a static call to Login.java
execute.jsp prints the results of the call
Controller.java uses Login.java. I was receiving compilation errors. To resolve them I did this:
Right click on JSPTesting -> properties
Choose java build path on the left bar
Choose projects tab
Click add
Choose BulkAdmin (Project)
I am not sure why but now when I am getting a NoClassDefFoundError. I have done some googling. I think that this means that I have messed up my classpath somehow but I am not sure how to resolve this.
java.lang.NoClassDefFoundError: com/myCompany/bulkadmin/SDK/util/Login
at com.myCompany.bulkadmin.jspController.Controller.process(Controller.java:44)
at org.apache.jsp.execute_jsp._jspService(execute_jsp.java:63)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:321)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:257)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:595)
Other information:
I am using tomcat (in Eclipse) as my server
The exception shows up in the browser and the eclipse console
execute.jsp is a JSP
It seems like there are many similar questions to this on SO. I have read about 15 of them and tried various things however I think that my question has a different solution. I can provide more information.
Rightclick your dynamic web project, go to Properties > Deployment Assembly and add the dependent projects there. This way they will end up as JAR in /WEB-INF/lib, exactly there where you want it to be.
In Eclipse versions older than 3.5 you need to go to Properties > Java EE Module Dependencies.
See also:
ClassNotFoundException when using User Libraries in Eclipse build path
Difference between Deployment Assembly and J2EE Module Dependencies in Eclipse
The NoClassDefFoundError indicates that a class that was available during compilation is no longer available at runtime. Your problem is that the com/myCompany/bulkadmin/cSDK/util/Login class is available in the compilation classpath (in Eclipse via the Project reference you added to the build path) but not in the runtime classpath (Tomcat, which has no idea how to find this class).
You need to add the BulkAdmin project to the web-app class path when deployed on Tomcat as well.
One way to do this would be to export the BulkAdmin project as a JAR and put it into the WEB-INF/lib directory of your JSPTesting project.