I get this error when I try to run my project.
java.lang.NoClassDefFoundError: org/yaml/snakeyaml/Yaml
I am trying to include the dependency SnakeYaml.jar in my project so my project is only one jar instead of requiring an external dependency.
in my project SnakeYaml.jar is located at /Libs/SnakeYaml.jar
but it is not being loaded at runtime, what can I do to get it to load the resource at runtime?
The best solution to avoid such problems is creating maven based project by eclipse. when you export your project as jar or war files it puts all dependencies in the jar or war files
In Eclipse, to put the dependency packaged inside your project executable jar you can do this:
I cannot post images due to my reputation so will try to explaing it writting.
Make sure the dependency is in your class path: right click the project -> Build Path
Right click your project again and select "Export"
Now choose "Runnable JAR file" (you can filter the list by typing)
In the next dialog choose the right option for you, in your case it could be "Package required libraries into generated JAR"
Hope it helps
Related
I have a Maven project and I want to add a JAR file as an external dependency to the project.
After clicking 'New' in Project Structure I expect to see an option for "JAR file". Unfortunately, I don't see it. Do you have any idea why or what I can do to add external JAR file as a dependency?
It seems like you're in the wrong tab of project structure settings.
Follow those instructions: Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project
I have some problems while creating a jar of my intelliJ project. First of all I just do the usual procedure:
Go to project structure
Select artifacts
Create a new one with modules and dependecies
Go to build artifact, build it
Execute it at console with java -jar "ddddd.jar"
So when I execute the project (not the jar) all runs ok, libreries and all works, but not in the JAR.
Terminal of IntelliJ:
My libraries are located in the project like: project>lib>"some jars here">otherjars>"here some jars and respective dll
This is because the "other jars" need the dll to work. I already tried to run them without the .dll but doesn't work without it.
Also I have them in the project on Modules>Dependencies I have the folder selected as a library.
Any help would be appreciated.
Edit 1:
Here I add some pictures about how I have my libraries structured.
My question is, I don't want to write XML code for dependencies in the POM.xml again and again.
For example, I want to use the log4j JAR in my project. instead of writing XML code is there any option to download the related JAR files?
Alternate method is downloading the jars from sites like maven or java2s.com and add them to your build path.
You can add a jar in Eclipse by right-clicking on the Project → Build Path → Configure Build Path. Under Libraries tab, click Add Jars or Add External JARs and give the Jar.
Hope that helps
Of course you can download (or copy) these jars, and then manually add them to your build path.
For instance in eclipse, you can select all the libraries under the "Maven Dependiences" and copy them to other folder eg. in other project. Then you need to select these libraries and using the right mouse button add them to build path, done :)
You do not need to write them again and again. You can define and install a parent pom with the common dependencies you use and refer to it in each project pom.
First you could download jars you need in your project from corresponding websites.
Next,follow the steps below:
Step 1: Create a folder under the project to save the JAR package.We usually store jar packages from the outside in the [lib] folder.
Step 2: Copy the jar to the lib folder.
Step 3: Right-click on the project name, and select it in turn [Build Path] - > [Configure Build Path...]
Step 4: In the open window, select the Libraries page and click on the right button the [add JARs...] then select the jar package we just copied into the project, and then click [OK] to close the window.
Finally, we can use this jar package in Eclipse
Yes you can add them through the java build path from your IDE. However, I would recommend that you add these jars as dependencies in the pom.xml and build your project through maven. This will make sure that you will not run into any error regarding the missing dependencies in case any jar gets deleted accidentally or if you want the same set of jars for a new project. And understanding a pom.xml is not a difficult task
Recently I wanted to add the nebula shelf to my eclipse plugin. Therefore I added the org.eclipse.nebula.widgets.pshelf.source_1.1.0.201701302244.jar the build path of my eclipse project.
Sadly eclipse can't find the class files inside of the jar, even after cleaning and rebuilding the whole project.
Picture:
Checking the same jar file with jd-gui results in:
Picture:
I exported the *.java files with jd-gui and copied them to my project. Using this method my project built successfully and worked as expected.
Can someone tell me how I can use the jar file without exporting all of the java files manually? Thanks for your help! :-)
Do not use source jars. You can tell eclipse while debugging to use the source jar.
Add the jar to build path: right click on jar -> build path -> add to build path
Don't try to add Eclipse plugins directly to the build path of another plugin as it won't work.
Instead add the plugin to your target platform or import it in to your workspace.
Then add the plugin to your plugin's Dependencies. In the MANIFEST.MF editor you do this on the 'Dependencies' tab in the 'Required Plug-ins' list.
I am new to Eclipse and Java, and I know that .jar files I need to add into libs derectory so that compiler could recognize them. How I can add .jars not only in libs folder but also in other folder too. How can I configure Eclipse to do that?
It's easiest if you have the jar files visible in the package explorer to start with, i.e. within your project directory. At that point, you can just right-click on the jar file, go to the "Build path" section of the context menu, then select "Add to build path".
If the jar file is elsewhere and you don't want to move it, you can right-click on the project, and under the "Build path" part of the context menu, select "Add external archives...". Then find the jar file in the file browser, and hit OK.
All of this can also be done from the project properties dialog, in the Java Build Path section.
Right Click project
Select Properties
Select Java Build Path
Under Tab Libraries Click on add jars or add external jar to add the required jars
The Java build path is used while compiling a Java project to discover dependent classes . It is made up of the following items:
Code in the source folders
Jars and classes folder associated with the project
Classes and libraries exported by projects referenced by this
project
Our goal is to feed our classes with the dependent classes present in the jars during compile time. Eclipse provies with number of easy ways to do it .Here you can find a good article about how to add the jars in the projects with screenshorts attached to it http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-(Java)