My project is using some jars which are dependent on the external jar httpclient-4.2.3.
In eclipse my project is running smoothly.
But when I am creating a Jar of my project it is showing error.
I found the error that it is picking httpclient from mahout jars which is an older version.
I know we can control classpath ordering of external jars through order and export in eclipse but it is not working properly.
Can someone tell me how I can force eclipse to prioritize some jars over another when I am creating jar of my projectc.
Related
Could anyone would be so kind and explain how to make a single jar file with all maven dependencies in Netbeans Maven Java Application? In Eclipse user can Export to Runnable jar file and select Package required libraries into generated JAR, so all dependencies within project comes in created jar file. In Netbeans there is no such option.
I have checked other answers, but the only thing i understand is that I have to add code to Build.xml file which is not even in the project.
The last time I had to do this I used the Maven Shade Plugin. It allows you to create a single JAR file and also handles dependency clashes.
A simpler solution (which doesn't handle dependency clashes) is to use the Maven Assembly Plugin.
Note that these are pure Maven solutions which should work in any IDE.
I use Eclipse Helios 3.2.2. I have a stand alone Java application that needs to be run from a batch file. So I need to export it as a JAR. The program uses some other JAR files such as log4j.jar, javamail.jar and 2 more. When I run the app in Eclipse, there are no issues. But when I export it as a JAR and try to run, I get a "NoclassDeffound error". The external JARs don't get exported in this version of Eclipse. Elsewhere, I read that FatJar or WinRun4J plugins can be used. When I try to install these plugins I get an error that the site is not found. Is there some other source for these plugins, or is there some other way to export in this version of Eclipse?
If you're using Eclipse 3.4 or greater, use the Runnable JAR file export option.
Export all resources required to run an application into a JAR file on
the local file system.
If you're using Eclipse 3.3 or lower, use an external plugin, for instance FatJar. Just follow the installation instructions and a simple tutorial on how to use it.
I m doing an eclipse plugin project to create an IDE. I need to create a jar file for the plugin project in which i have four plugin packages which was created by me. Now I need these to be created as a single jar file and the user should be able to download the jar file and run my plugin project without the eclipse software.
EDIT-
You cannot run Eclipse plugin outside of Eclipse, because you need the Equinox runtime container. you could run a plugin using the eclipse executable, and as an application, see:
http://wiki.eclipse.org/FAQ_How_do_I_create_an_application%3F
You're effectively creating an an org.eclipse.core.runtime.applications extension point.
You could also publish a plugin as part of an Eclipse application and then export it as an executable so that it can be run aside from Eclipse. This still bundles the Equinox runtime and plugin together though.
Also, check out "Running it outside of Eclipse" section here.
-END of EDIT
Generally, all you need to run an executable jar file is the jvm (java) and your code with all the classpath dependencies. You can use "Runnable Jar Export Wizard" available in Eclipse IDE when you right-click your project.
You can put all the dependencies inside your jar (for example you can create a lib directory in your project and put all your dependency jars inside). Also you will need to specify the dependecy location in the MANIFEST file that will be generated for your executable jar (if you use the wizard the MANIFEST file will contain your dependencies).
To run your executable jar you will need to execute:
java -jar jar-file
Good Luck!
I am using Maven 2.2.1. I have an enterprise java maven project which I am trying to build. When I run mvn clean install the EAR is generated. No compilation errors are found. In the logs I get the message that 1980 source files are compiled to ApplicationWeb\target\classes directory. But I cannot find these class files in the location and they are not present in WAR. How to solve this ?
Edit: When built from Eclipse using Maven plugin, its working fine. It gives issue when run from Windows Command Prompt. Why the difference ?
That sort of thing usually happens when you're using a different version of Maven. I'm betting your Eclipse is using 3.x which is the in built version.
You have 2 choices:
Make Eclipse use the same version as your command line
Install a new version of Maven. (3.0.3 is the latest)
I'd recommend upgrading Maven to the latest and getting both your command line and Eclipse to use the same installed version.
as a first attempt to resolve this issue - try to go to your war module (you should have a module responsible for WAR generation) and see whether the files are there.
The ear module is just an "envelope" here - it just takes the war and puts it inside the ear.
So I believe if the issue really exists its in the WAR module's pom file and not in EAR's one.
Check the size of your generated war, check the war plugin configurations as well.
In general this situation shouldn't happen.
Hope this helps.
I use eclipse for Google Android development.
I've created a library project ([x] Is Library in the Android-settings), which includes an external jar-file (Referenced Libraries). This library project are referenced in another Project (the actual project which will use the library project). This is done by add the project under the Android-settings.
the source compiles but if I want to execute it on the device, I get the NoClassDefFoundError for a class which is inside the jar-file which is included in the library project.
Edit: The jar-file ist added to the exported entries ([x] my.jar on the Order and Export-Tab from the library project)
Is there a clean way to get this working?
It has been clearly stated in offcial API here:
A library project can include a JAR library
You can develop a library project that itself includes a JAR library, however you need to manually edit the dependent application project's build path and add a path to the JAR file
The jar lib must be manually added to the dependent application project's build path, not only the library project build path itself.
Update from SDK r17:
This is automatically handled by ADT now, check out new feature for ADT 17.0.0 release here:
Added feature to automatically setup JAR dependencies. Any .jar files in the /libs folder are added to the build configuration (similar to how the Ant build system works). Also, .jar files needed by library projects are also automatically added to projects that depend on those library projects. (more info)
For those who followed the steps(even check the projects in "Order and Export") and still have the java.lang.ClassNotFoundException in the API 17, the final step is to check that your compiler does not run with Java 1.7. If is 1.7 then you should change it to 1.6 for all your projects. After that it will ask to rebuild all the projects and successfully ran on my phone :)
To change the java compile version in eclipse, this is located in: Project properties > Java Compiler > Compiler Compliance level: 1.6
Go to project properties -> build path-> libraies
If you see your jar files like this
snmp4j.jar - e:\software\jars
Its may your problem
Add libs folder in your project and copy jar file in that folder. Right click jar file and go build path -> add to build path. Then you can see your jar as
snmp4j.jar - project_name/libs
Its worked for me.
I had two projects using the same library: one working, the other one crashing with java.lang.NoClassDefFoundError.
After nothing else helped me, I looked into the file project.properties in the root directory of my project.
The working project had the android.library.reference line (the last line below), the crashing one did not:
# Project target.
target=android-17
android.library.reference.1=../my-library-project
I manually added the line and it started working!
(Yes, I did try both (project) properties -- java build path -- projects and (project) properties -- java build path -- order and exports -- nothing helped.)
PS By the way, "project properties" has also the "project references" tab. No idea if it would work.
I had a minor issue when I upgraded to ADT17 where my libs weren't being imported properly. Turns out this is because my librarys were being linked as dependancies from my lib folder not libs!
Seems librarys have to be in the libs folder from now
I had a similar problem and non of the solutions out here fixed it.
Short version: the JAR was compiled in Java 1.7 and could not be found by Dalvik.
We build an internal JAR that we share across backend and mobile clients with Maven. The problem ended up being that the JAR was compiled with Java 1.7. Androids dalvik only supports Java 1.5 and 1.6. This is why everything works fine in Eclipse as it's not compiled to dalvik at this point.
We even specified the target and source version in the Maven compiler plugin to compile with Java 1.6. This did not work because only JDK 1.7 was installed on the build machine. A small note at the bottom of the Maven page gave us the hint: Note: Merely setting the target option does not guarantee that your code actually runs on a JRE with the specified version.
To see if you have this problem as well, rename your *.jar file to *.zip unpack it, and look in the MANIFEST.MF file for the Build-Jdk: parameter to see what Java version actually compiled your JAR.
Another thing to pay attention to is library package names.
If you are using ADT21 and you happen to have libraries that have the same package name, there will be error during compile but it will still compile and run in Eclipse, giving you an APK that is missing some of the resource classes. Hence the crash when you run the app.
If you compile it with ANT then you can see the compile error that says two or more libraries use the same package name.
To fix this, rename your library project by using Android Tools -> Rename Application Package. Then everything will go back to normal.
It took me almost entire day to figure this out...