ClassNotFoundException in build path jar in run time - java

My team exported a jar from java project which having classes and jars in that lib.
I got that jar from my team and just add that jar using build path as external jar in my project.
I got an error while create an object for a class(canon.class) in that jar file, from my project controller class.
it says
java.lang.ClassNotFoundException: ch.qos.logback.core.Context
while this class is in other jar file is also in the build path.
I am not sure why this happens. Can anyone give me assistance in this?

Make sure the logback.jar is on the classpath. That should solve it.

Related

Creating a jar from maven project Intellij

I created a new maven project in IntelliJ and set packaging to jar and when I build it, there is a jar file target folder. But when I run the file I get the error as
no main manifest attribute, in QeToolHelper-0.1-SNAPSHOT.jar
I have created jar file using maven-assembly-plugin. I have added these lines in pom.xml for that.
Tried few methods described in other similar questions but to no avail.
Have you looked at SpringBoot and associated plugins. It can be used to build a standalone java applications.
With regards to your specific issue, that error is symtomatic of a failure to declare main class in your manifest. The main-class attribute in the manifest tells the jvm what class to load from the built jar. Looks like the settings in your maven config are failing to generate the resources correctly.
I was able to solve this issue by creating jar package from maven.
Running the build package created the jar in target directory.

Eclipse is showing me the jar, but I'm unable to use the classes in it

I'm building an existing project with Maven in Eclipse and all the dependencies are downloaded. But some of my classes using some classes from a specific jar are not found : the import statement shows an error.
The strange thing is that when I browse the Maven dependencies in Eclipse, I see the jar. I'm also able to unfold the jar, and browse in the packages, and see the classes in it. So as far as I can say, the jar is here in my classpath, available to my project. But somehow, it's not seen by my code. I've tried rebuilding, from Eclipse and from mvn command line, but I still have the same issue.
Any idea where that issue could come from ?
Thanks
One root cause would be that your jar is corrupted. Not corrupted enough to make it unavailable in Eclipse, but corrupted enough to prevent Eclipse from using the classes inside.
To make sure of this :
go to your local Maven repo, where the jar is supposed to be.
try to open the jar with your zip tool (Winzip or equivalent)
if you get an error saying your jar is corrupted, then all you have to do is delete the directory containing the corrupted jar, and build again your project with Maven : jar file would be downloaded again from your remote Maven repository.
If this time you're able to open it, then probably Eclipse will also, and you'll be able to use the classes inside and your problem will be solved.
If you're still unable to open it, check if the jar is not corrupted on central repository itself.
Had you add the jar file to your Build Path, if not, then you can not find the classes in the jar file.
Try to do this:
In Eclipse:
Right click on the jar file --> Build Path --> Add to Build Path.
Then try again if you can find the classes in the jar file or not.

How to use Netbeans Jar file in Eclipse Project

I have developed a web service client in Netbeans through WSDL file, i have build the project and get jar file. When i run that jar file, it work fine but now i have to use this jar file in my eclipse project. But when i use this jar file i get error.
"THe type javax.xml.bind.annotation.XmlAccesstype.cannot be resolved. "
Attach is the screenshot.
How can i solve this problem.
You have to check your classpath and probably add you WS libraries in it. Open grepcode.com and paste your missing class name in it. You will see the dependency missing.

class not found add jar via eclipse

When I was working with java spring hibernate struts2 eclipse project. I used buildpath-> addjar option to add jars from a folder inside the workspace. Even if the class is available it shows class not found exception.
If i put those jar files in web-inf/lib folder everything works.. Should i keep those files in the lib itself? Can i just include those jars in a seperate folder and add jar using eclipse configure build path??
what is the problem ? please help me... thanks in advance...
If you're using a standard Eclipse Dynamic web project, best way to go is to put all your Jars in the WEB-INF\lib folder. This will automatically add them to your build path and also include them in your WAR when you export it.
If you still want to use the Build Path > Add Jar option on the project, and want your Jars to also be included in your WAR, you have to go to the Project Properties > Deployment Assembly configuration and include them there. Of course this is double the work for every Jar.

How to execute a jar that uses another jar

I have a little problem importing a project to my android project.
I have built a little library using Ical4Java to parse a .ical file, and that library is exported to a .jar.
In my Android Project i have imported and added to the build path my generated .jar from my library that includes some jars to make my library work.
But when i run my application it just crashes and i get this on the LogCat:
E/AndroidRuntime(14382): java.lang.NoClassDefFoundError: net.fortuna.ical4j.data.CalendarBuilder
That library (ical4j.jar) is imported on the library buildpath and is exported whith my library (mylibrary.jar)..
You can use One-Jar to help you use a jar file that is dependent on other jar files. Basically you can combine them into one jar file.
Here is a little tutorial to help you.
Just put the content of the one jar into the other jar (combine them). They are just zip files.
Is mylibrary.jar an executable jar file?
If so, you cannot reference external jars.

Categories