I added the jar jsqlparser-0.7.0 to my Netbeans IDE (right clic on libraries / Add Jar file) but i still can't use its packages. what could be the reason . The library is created on 2011 it could be it is not supported by JDK7?
The JAR file "jsqlparser-0.7.0.jar" is not a regular Java library. It is a simple zipped file containing several artifacts: a source and a documentation directory, some testfiles, and - what you need - another JAR called "jsqlparser.jar" in a lib directory.
This JAR is the "real library" that you must add to your project. Additionally, all packages inside this library start with "net.sf.jsqlparser".
Just put this:
import jsqlparser.*;
Related
I got a jar file that is packaged with source code in it. I want to load it as a top-level project and start working on the source code. How can I do that in Eclipse?
For example: if I have helloworld.jar, when I import this jar. I want to have the project name as helloworld, with all the packages and src inside it.
I do not want that code on build path.but on my IDE to work with.
Create a directory named "helloworld" and unpack the JAR into that directory:
mkdir helloworld
cd helloworld
jar xvf ../helloworld.jar
You can then create a project from existing sources and start operating on that. I don't think Eclipse will let you create a project and change files directly in the JAR.
#eagertoLearn Yes. Eclipse does this in a very easy way than suggest by #Erik Gillespie.
Use Import from archive file feature in eclipse. Refer this post https://stackoverflow.com/a/11983201/1391924
Supported archive file types:
*.jar
*.zip
*.tar
*.tar.gz
*tgz
Right click on the .jar and choose open with -> winrar (or another archiver) and then click extract.
From there you can import the folder in Eclipse as a new project.
I was able to import the jar file contents using the following steps:
Create a new java project
Import jar file using file>import>general>archive file option
Move the folder containing source code into the src folder using drag and drop
Run the class containing the main method
Situation:
I intend to use a Java library and I only have an AAR file from a Maven repository but I need the JAR file.
Background story:
I tried to compile a library, but its Gradle structure was unstable. So I asked for a compiled jar file, and its developer handed me an aar file from some Maven repository (the developer couldn't compile his own project).
The Gradle configuration was a mess, it depended on multiple libraries and Gradle has thrown some exceptions.
I tried to use it in my IDEA IDE, but it couldn't see it. A library project should be able to be compiled into a jar file, right?
Question:
What should I do to convert that AAR file to a JAR file?
The AAR file consists of a JAR file and some resource files (it is basically a standard zip file with a custom file extension). Here are the steps to convert:
Extract the AAR file using standard zip extract (rename it to *.zip to make it easier)
Find the classes.jar file in the extracted files
Rename it as you like and use that jar file in your project
.aar is a standard zip archive, the same one used in .jar. Just change the extension and, assuming it's not corrupt or anything, it should be fine.
If you needed to, you could extract it to your filesystem and then repackage it as a jar.
1) Rename it to .jar
2) Extract: jar xf filename.jar
3) Repackage: jar cf output.jar input-file(s)
As many other people have pointed out, just extracting the .jar from the .aar file doesn't quite cut it as resources may be missing.
Here are the steps that worked for me (context of Android, your mileage may vary if you have other purposes):
Rename the .aar file to .zip and extract.
The extracted folder is an ADT project that you can import in Eclipse with some minor modifications (see below)!
In the extracted folder rename the contained file classes.jar to whatever you like (in this example myProjectLib.jar) and move it to the lib folder within the extracted folder.
Now in order for Eclipse to accept it you need to put two files into the extracted folder root:
.project
.classpath
To do that, create a new Android dummy project in Eclipse and copy over the files, or copy over from an existing Android project.
Open the .project file and look for the XML name tag and replace the contents of it with myProjectLib (or whatever you called your jar file above) and save.
Now in Eclipse you can File -> New -> Project -> Android Project from existing source.. and point to the extracted folder content.
After import right click on the newly created project, select Properties -> Android, and check Is Library.
In your main project that you want to use the library for, also go to Properties -> Android and add the newly added myProjectLib to the list of dependencies.
For those, who want to do it automatically, I have wrote a little two-lines bash script which does next two things:
Looks for all *.aar files and extracts classes.jar from them
Renames extracted classes.jar to be like the aar but with a new extension
find . -name '*.aar' -exec sh -c 'unzip -d `dirname {}` {} classes.jar' \;
find . -name '*.aar' -exec sh -c 'mv `dirname {}`/classes.jar `echo {} | sed s/aar/jar/g`' \;
That's it!
Android Studio (version: 1.3.2) allows you to seamlessly access the .jar inside a .aar.
Bonus: it automatically decompiles the classes!
Simply follow these steps:
File > New > New Module > Import .JAR/.AAR Package to import you .aar as a module
Add the newly created module as a dependency to your main project (not sure if needed)
Right click on "classes.jar" as shown in the capture below, and click "Show in explorer". Here is your .jar.
Resource based .aar-projects
Finding the classes.jar file inside the .aar file is pretty trivial. However, that approach does not work, if the .aar-project defined some resources (example: R.layout.xyz)
Therefore deaar from CommonsGuy helped me to get a valid
ADT-friendly project out of an .aar-file. In my case I converted
subsampling-scale-image-view. It took me about an hour to set up ruby on my PC.
Another approach is using android-maven-plugin for Eclipse/ADT as
CommonsGuy writes in his blog.
Yet another approach could be, just cloning the whole desired project
as source from git and import it as "Existing Android project"
The 'aar' bundle is the binary distribution of an Android Library Project. .aar file
consists a JAR file and some resource files. You can convert it
as .jar file using this steps
1) Copy the .aar file in a separate folder and Rename the .aar file to .zip file using
any winrar or zip Extractor software.
2) Now you will get a .zip file. Right click on the .zip file and select "Extract files".
Will get a folder which contains "classes.jar, resource, manifest, R.java,
proguard(optional), libs(optional), assets(optional)".
3) Rename the classes.jar file as yourjarfilename.jar and use this in your project.
Note: If you want to get only .jar file from your .aar file use the
above way.
Suppose If you want to include the manifest.xml and resources with your .jar file means
you can just right click on your .aar file and save it as .jar file directly instead of
saving it as a .zip. To view the .jar file which you have extracted, download JD-GUI(Java Decompiler). Then drag and drop your .jar file into this JD_GUI, you can see the .class file in readable formats like a .java file.
If you are using Gradle for your builds - there is a Gradle plugin which allows you to add aar dependency to your java|kotlin|scala|... modules.
https://github.com/stepango/aar2jar
plugins {
id 'java'
id 'com.stepango.aar2jar' version “0.6” // <- this one
}
dependencies {
compileOnlyAar "com.android.support:support-annotations:28.0.0" // <- Use any AAR dependencies
}
I have opened the jws file of StatelessAuthenticationSSOToken, sample code availabe in Oracle Repository.But even after importing all the libraries it says "Import org.apache.axis.message.* not found".I already have axis.jar in my classpath beside other Apache axis1.4 libraries.
Whic other library or jars are required to be imported
If you have the jars on your classpath, check the order. You might have to change it under the Order & Export tab.
I have two jar files - jar1 and jar2. Both of them are located in C:\Eclipse projects\ and I have added the paths to both of them to the Environment Variable CLASSPATH as follows
.;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;C:\Eclipse projects\stdlib.jar;C:\Eclipse projects\algs4.jar
the ".;" at the beginning were there so I left them. Then I added the jars to the project from their location C:\Eclipse projects\ and they showed up as Referenced Libraries. However, when I try to instantiate a class from the jars it does not recognize it. I am also not able to import the jar (import jar1).
After I tried adding a lib folder in the project and I added the jars there. After, I added them as references once again (so not they appear twice in the Referenced Libraries), however, I am still not able to use the inner classes. Any help will be much appreciated.
UPDATE:
Something must be wrong on my end. None of the suggestions worked for me. Here is a video with all the steps: screencast.com/t/gC81YzCsLY0e
RESOLUTION In my project I had a package called TestProject and it seems that those jars needed a default package. After deleting the TestProject package and using a defaultPackage everything worked correctly after adding external JARs as explained below.
I've got the same problem as you today, And no answer from the web can solve it. However, I fixed it at last.
In fact, there is nothing wrong with the setup, it is right to import those jars through "Add External JARs". The real problem is the location/package of you java code. I found that you have to put your .java file in the default package. For example, you will get errors if you put your java code in a package like com.xxx.yyy.ccc, below is an image which shows the right location/package you should use(see WTF.java). After doing that, you program will be able to run.
However, that is how i fixed my problem, i'm not sure that could work for everyone..
In eclipse, right click on a project->Propeties->Java Build Path->Add External JARs (Add JARs if the jar is inside the project's folder) and then choose your jar file.
From now you can use the inner classes of the jars you added. Eclipse will import them when you'll start using them.
Why don't you use these two JARs—— stdlib-package.jar and algs4-package.jar.
And below the code page(http://algs4.cs.princeton.edu/code/)
Q. If I use a named package to structure my code, the compiler can no longer access the libraries in stdlib.jar or algs4.jar. Why not?
A. The libraries in stdlib.jar and algs4.jar are in the "default" package. In Java, you can't access classes in the default package from a named package. If you need to use our libraries with a named package, you can use these package versions: stdlib-package.jar and algs4-package.jar.
Warning: if you are taking Princeton COS 226 or Coursera, Algorithms, Part I or II, you must use the default package verison of our libraries to facilitate grading.
Showing my test success:
If you have a folder with your JAR files into the project:
Right click on the project>Build Path>Configure Build Path;
At the tab "Libraries" click on Add JARs, search and select the JARs files you want to use.
If you have yours JAR files any other place outside the project:
Right click on the project>Build Path>Configure Build Path;
At the tab "Libraries" click on Add External JARs, search and select the JARs files you want to use.
I have added this jar file to my project's build path under "libraries":
http://sunet.dl.sourceforge.net/project/jeplite/jeplite/jeplite-0.8.7/jeplite-0.8.7a-src.jar
and cannot get Eclipse to resolve ANY of the included classes.
Packages are visible, but no classes.
Error message is:
"JEP cannot be resolved to a type"
In eclipse, it should be on the build path if its a source tree .... Remember , a jar is just a glorified zip file, so be sure that the binaries are actually in your jar file. The steps to test are
1) unzip the jar file
2) if its source : then either try adding it to your build path, or just directly import the source folders into your project
3) if you see class files in the jar, then it should be okay to add them to "libraries"
This is only a jar containing the source code. You need a jar with the compiled classes in it. Try the jeplite-0.8.7a-bin.jar.