I have a Android project with some classes that I would like to compress to a JAR.
I create the JAR by right clicking my project - export - JAR - and the JAR gets created without any warnings.
I can access all classes from the JAR in my code but when I try to build the project get this exception :
java.lang.NoClassDefFoundError: name.of.class.in.package
Does anyone know what resources should be exported with the JAR? The options you get is
.class path
.prject
AndroidManifest.xml
proguard.cfg
project.properties
Right now I have included all of the above.
Making the JAR into a library project is not an option. And just to make it clear I don't have anything in the RES folder of my JAR project.
Open the project properties -> Java Build Path -> Order and Export and check item Android Dependencies are checked to be exported to the result APK.
And if .jar exist in Library tab under Android Dependencies item.
If you have .jar in the "libs" folder it should be included by default.
Just add your JAR to classpath or build your project with Maven and include dependencies
Try generating the jar in a different way. Basically jar is a zipped file of all class files with an extension of .jar.
Select all your class files that needs to be included in a jar file.
Right click and send to compressed (Zip File).
you will have a zipped file which will contain all the class files.
Rename this zipped file with having an extension .jar
Now include this jar file into your project whichever you want to use.
Or if you want to zip all the files by a different method then make sure all the files are zipped together without a folder. So when you unzip the files you should get all the files without contained in a folder.
It looks similar with this topic. Follow the very clear instructions written by Russ Bateman.
Related
I am trying to add external jars to my Java (without Maven) Project.
But I don't get it to work at all.
The official documentation: https://code.visualstudio.com/docs/java/java-project
says there are 2 ways to do it:
1."You can use the Java Dependency Viewer to add any JAR file to your project."
https://code.visualstudio.com/assets/docs/java/java-project/manage-dependencies.gif
As you can seee in the gif, the dev opens a "referenced libraries" folder.
This folder DOES NOT EXIST for me.
or 2."The other easy way to bring additional JAR files as dependencies is to create a lib/ folder in the root directory of the standalone files and place your JAR files there. Source for foo.jar is automatically detected if there is a foo-sources.jar in the lib/ folder."
https://code.visualstudio.com/docs/java/java-project/lib.mp4
I have the Jar file in the lib\ folder but it still shows me he same error messages.
Are there any steps I am missing?
As it says, place the external jar files in the ...\JAVArpg\lib folder.
So copy them from wherever you have them now. cp ../lib/*.jar lib/ is just an example.
You can use the Windows Explorer. You don't have to copy the files using a command-line.
I created a new project in Eclipse in which I want to use the JTS library.
I imported the library during the creation of the project but I can't find the classes in the package explorer.
Since I am not experienced in Java and Eclipse, I'll explain what I did from the start.
I download the JTS library from GitHub: https://github.com/locationtech/jts
I create jts-core.jar using jar in the command line. I place it in workspace/Libraries
In Eclipse I create a new project in workspace/Projects/JTS-test. In the "build settings" I go to "Libraries" and "Add external JARs..." and select my jar.
This is what my package explorer in Eclipse looks like after step 3 :
However, when I browse in jts-core.jar outside Eclipse, org/locationtech/jts/algorithm/ is full of .java files and contains directories themselves containing other .java files.
What did I do wrong?
The JAR file referenced as a library must contain the *.class files (bytecode). In the JAR, the *.java files (source code) are only to see the source code and the Javadoc, but are not required.
Before jar, you missed compiling the *.java files (javac). Instead of creating a JAR yourself, you can download a ZIP file with all required JARs from the release page of the jts project. This ZIP file contains also the JARs that are required by jts.
Alternatively, you can copy the *.java files into the source folder (src by default) of your project or create add a new source folder for these *.java files. In contrast to classes in JARs, *.java files in source folders can be edited.
I have a project with JNI libraries inside it not in resources folder. I need to create one exetutable jar file.
How to teach maven copy needed files inside jar and put in needed folders?
Please explain how to add my files from lib directory near my project to a jar file using maven. Or how to copy my files and directories to jar using maven?
I am new to project environment setup. Below is my project structure in eclipse
Project Name
--> .settings
--> .bin
--> lib
--> resources
--> src
--> .classpath
--> .project
I am attempting to export src folder as jar.
When i export to jar, all the above folders & files are created in jar. But i need to convert only src folder as.
Also when i export to executable jar, all the third party libraries are exported as class files in jar. is it right.
What is the best practice to export project. Only src folder or everything.
Which i need to use jar/runnable jar. My requirement is to write start/stop bat file to call jar and execute java program.
Please advice me. Thanks in advance.
First it's important to know what these folders actually do. Following are the workings of several of these files.
.settings -> This file records project specific settings and workspace preferences.
.bin -> folder is usually where the compiled files are copied to.
lib -> contains external libraries that are used in your project (like Apache Commons)
resources -> the resources like images, text, pdf, audio, video are usually copied here
src -> the folder where the project's source files are located.
.classpath -> It contains information that the JDT feature needs in order to properly compile the project: the project's source folders, the output folders , and classpath entries.
.project -> This file is maintained by the core Eclipse platform, and its goal is to describe the project from a generic, plugin-independent Eclipse view.
So you can see that if you exclude some of the files like lib, resources, bin etc... Your jar file will probably stop working. Your jar file needs compiled files and their dependencies.
For example: All your compiled .class files are in bin folder. And your jar works because of these .class files and NOT .java files that are in src. If you delete this bin folder then your jar will probably stop working.
Also, your project may be using some external library supplied by someone else. Like Apache Commons or google/guava and these are usually in lib folder. So you can't delete this folder as well.
However, if you no longer expect to use .java code, then you can exclude files that were created by eclipse to manage this project. See this post.
see also:
1. What's in an Eclipse .classpath/.project file?
2. exclude files from jar or war in eclipse
I am trying to create and use jar file in an Android project under Eclipse. I have tried various methods without any success. Here are the steps:
Create jar file from the source files jar -cf lib.jar *.java
Copy jar file to libs folder
Right click, Build Path->Add to Build path
Now, compiler gives unresolved symbols if I try to use a class from the jar file?
Can someone please let me know correct method to create and use an external jar file for the Android project under eclipse.
This worked fine for me:
1)Place Jars in assets folder.
2)Right click on project name.
3)Select properties.
4)Select Java build path.
5) Select Libraries.
6) Click Add Jars.