Strange Exception while working with EWS - java

I'm creating a project to get emails from exchange server. I'm taking the EWS help to get this job done.
I've the below dependencies added to my pom.xml
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.microsoft.ews-java-api</groupId>
<artifactId>ews-java-api</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
In my code I'm getting the below import errors.
The import microsoft.exchange.webservices.data.core.ExchangeService
cannot be resolved
The import
microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion
cannot be resolved
And also , I'm getting an error on my package and it reads as below.
The type
microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion
cannot be resolved. It is indirectly referenced from required .class
files
when I opened my decencies tree, I'm surprised to see core.ExchangeService available(please see the below screenshot). But the core.enumeration.misc.ExchangeVersion is missing.
please let me know how can I fix these issues.
Thanks

This seems to be an Eclipse bug, though restarting Eclipse worked great for me, hope this helps somebody else too.
See [http://dev-answers.blogspot.de/2009/06/eclipse-build-errors-javalangobject.html][1] for a possible solution, otherwise try the following;
Close the project and reopen it.
Clean the project (It will rebuild the buildpath hence reconfiguring with the JDK libraries)
OR
Delete and Re-import the project and if necessary do the above steps again.
OR
If anything not working please try with other IDE it might work.

This bug arises when Eclipse is unable to import the jars properly. Along with the fix mentioned by Maheshwar Ligade above, you may also try removing the import statements from code, saving it, re adding the import code & then saving it again.

Related

package javax.jws does not exist. I need this package that support jdk1.7

I am trying to run an old maven project, a Website Application from my company, so I can do some changes for an update.
Currently, I'm still making some changes in pom.xml file because some library is not available in the repository. And after some configuration, I've been stuck in this error while I try to run the project using Tomcat Server 7 with JDK 1.7. It is showing that:
error: package javax.jws does not exist
import javax.jws.WebMethod;
error: package javax.jws does not exist
import javax.jws.WebService;
so I search and found this: https://askubuntu.com/a/1149525/1644122
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-ri</artifactId>
<version>2.3.0</version>
<type>pom</type>
</dependency>
I have add this library and it went well when I build it using maven.
But, this error appears when I do "run on server" in eclipse.
Unsupported major.minor version 52.0 (unable to load class [com.sun.xml.ws.transport.http.servlet.WSServletContainerInitializer])
I believe that the dependency that I add before require JDK 1.8 or above to run. The problem is, I need to to make it run in our tomcat server for a development environtment.
Now, the question is, Is there library that includes package javax.jws and support JDK 1.7?
Or Is there any way to handle this issue?
I'm newbie in Java. This project really driving me crazy :(
Please help me.
I'm not sure if is this the right answer.
But anyway, I add these dependencies, and the errors are not showing anymore.
<dependency>
<groupId>org.glassfish.metro</groupId>
<artifactId>webservices-rt</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.metro</groupId>
<artifactId>webservices-api</artifactId>
<version>2.3.1</version>
<scope>provided</scope>
</dependency>

How to solve my dependencies problem using Maven and slf4j with OWLAPI on Eclipse please

First of all, I'm a newbie with Maven, so I apologize if I misunderstood something.
In a recent question I ask about the import of OWLApi in my Java project and people told me to use Maven to import it, instead of importing JAR file.
I tried a new Maven Project and imported to test OWLApi and it worked well.
Today, for my profesionnal project, I managed to work with Maven. I converted my project to Maven, added OWLApi in my dependencies... and when I build with Maven, I got the error :
Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError
Moreover, my classes are not compiled anymore (impossible to run my classes, because no .class are compiled).
If it helps, this is my pom, where I tried to excluse slf4j, as I found in another question. But it didn't help me :
<dependencies>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-distribution</artifactId>
<version>5.0.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
Thank you in advance.
What's happening here is that the classpath contains two adapters, one that passes logging calls done with Log4J to a SLF4J logger, and one that does exactly the reverse. With both in the classpath, any logging call would go first to one logging system, then be passed to the other, and this would create an infinite loop. This would result in a stack overflow, which is what the error message is reporting.
OWLAPI doesn't import either jar, it only imports the SLF4J API, so the conflicting jars must be dependencies of other libraries.
You have tagged Eclipse here, so I assume you're using Eclipse. When you open a pom file in Eclipse, you get a tabbed editor, with one tab being Dependency Hierarchy. You can use this tab to look for the jars you wish to exclude, the tab will show which of your dependencies are bringing in the jars, so you can put the exclusions in the right place. It should be sufficient to exclude one of the jars (it depends on which logging system you mean to actually use).

Maven Dependencies? Doesn't access servlet - 404 Error

I have a program that I wrote a couple years ago for a class, and it worked fine. Recently I updated a lot of things - Java, Eclipse, Tomcat, etc. because I haven't been programming in a while. I messed with the dependencies and now I cannot get it to work. It correctly displays the opening jsp, but never makes it to the handling servlet, giving me a 404 error. I think that I must not have the correct dependency for the servlet anymore? I know the program works, so I have not included code for it. The program uses Eclipselink, mySQL, JSP, and Servlets. (Yes, kicking myself for messing with it). These are the dependencies I have. Am I missing one? Have the wrong one? I am not well versed in maven dependencies
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
And my build has:
Apache Tomcat 9
Java jdk 13.1
Maven Dependencies
Thanks for any help you can give.
Well, dang it all. I have been trying to get this working for 2 days. Decided problem was with Tomcat. Downloaded and reinstalled it all. Port errors. Changed to every number in the world. Cleaned server, updated project, etc. Nothing worked. Kept getting port number error. Finally saw where someone said they fixed it by restarting computer. Last ditch effort and for some godforsaken reason, it worked. SOOOOOO frustrating. Thanks for your help anyway. I should know - when in doubt, reboot.

About dependency in maven

I have some code, its depend org.apache.batik.*. Many jars are necessary.I tried import this im my pom.xml.
<dependency>
<groupId>org.apache.batik</groupId>
<artifactId>org.apache.batik</artifactId>
<version>1.6.0-20070705</version>
</dependency>
So, That I found all jars I need have entered in project libraries.Following this.
Inside this jar that has a lib folder, That all jars I need are in there.
The problem is my code seems can not find some jar they need.
I can't sure if cause is the jar that I imported has a lib folder, and I found other maven jar's structure doesn't like this.
So thank if you can help me!
EDIT 1
I imported this successful, this dependency's type is 'pom', so I think my
code should can find those dependency they need, but in fact, it didn't work. I don't know why.
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik</artifactId>
<version>1.10</version>
<type>pom</type>
</dependency>
The artifact you are using is not directly usable in maven.
If you can use a more recent version (1.9, 1.10) of batik you can try this:
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-all</artifactId>
<version>1.9</version>
<type>pom</type>
</dependency>
If not search on https://mvnrepository.com/artifact/batik
In the latter case it seems you need to add each dependency one by one
Define dependencies for all jars you use in your source code. This usually means all jars from which you import at least one class in your source code.
Run clean package with Maven.
If you have errors, check if dependencies are missing.
If you get stuck, try a new question on Stackoverflow.

cannot resolve "org.h2.tools.Server"?

I downloaded some code from net and opened it in Eclipse. The problem is
my Eclipse says
The import org.h2 cannot be resolved
for following code:
import org.h2.tools.Server;
I am learning Java and that was a sample code. I'm using jdk1.8.0_40. I cleaned my project but it still there!
Personally, I changed the h2 dependency on pom.xml
It was
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
I removed the scope and it found the Server package
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
A good explanation on why this is happening on runtime here:
Maven : what is the "runtime" scope purpose?
Actually, this means your code requires a so called 3rd party library which is not part of the jdk. H2 is a java based database. To remove this error, download the current version of the h2 database driver and do the following in eclipse - open context menu on your project, choose the properties ( last entry). Search for "build path", choose the third tab and add the download driver (should be a jar file, maybe packed in a zip) to your project.
Cannot better describe this now, I am on my mobile.

Categories