I am using Eclipse and I have just started working on a project that needs another project (say pjkt) to function. The pjkt project files are stored in a specific folder. I would like to create a jar from pjkt and then add this jar to my project buildpath. How do I do this? Do I need create first in Eclipse a new project from the pjkt code, build it and then select the export command?
Yes create a new project and export as .jar.
To answer the question about the build path:
Create a project directory (in the using project) for library files - it's common to create it in parallel to /src and /bin and call it /lib;
Once you've created (by exporting) your jar from the used project, copy it into the /lib directory;
If you did any of this creating and copying outside of eclipse, refresh your project so everything will show up in the Project Explorer;
In the Project Explorer, right-click on the .jar in the /lib folder and do "Build Path | Add to Build Path".
Done!
If you need to work on both projects, and have them open in Eclipse at the same time, another approach is to open Properties -> Build Path for the new project, and add pjkt on the Project Dependencies tab. This will provide all the exported resources from pjkt to the master project.
Related
I have an Android project and a web application project.
I want to send an Object between them. I opened a new project with a class called SharedObj.
this class I exported to a jar file and I imported it to both project as external library's.
In the web application project it's recognized the class SharedObj and in the android project it's not.
what is the problem?
I had the same problem weeks ago. I created "libs" folder and placed the *.jar there with other external. It works for me.
I strongly suspect you put your jar into the wrong folder. The jar should go into the /libs folder, at the top level of your project directory.
If you are using Windows..
Copy your jar file by doing right click -> copy, then open eclipse and paste it in the libs folder. Then right click on the pasted file and click on Build Path -> Add to build path
I have create a simple program using Eclipse 4.1.. I wanted to build or deploy my project into a .jar. I also added external libraries in my project. I wanted the output same as in Netbeans with the .jar file and lib folder in the dist folder, but there should be also a folder named help and lang.. How can I do this with eclipse?!
Follow the steps provided here.
Or if you don't want to complex things up, select Runnable JAR file instead of JAR file set the directory where the .jar is to be written then click Finish.
Eclipse will create the [Project Name]_lib directory for the external libraries included in the project.
I am done with the project which connects to database (MySQL). Now I want to export the project as jar. But I don't know how to include its external dependencies? Is there any way of doing it in Eclipse or should I use any scripts for that?.
When you export your project as a 'Runnable jar' (Right mouse on project -> Export -> Runnable jar) you have the option to package all dependencies into the generated jar. It also has two other ways (see screenshot) to export your libraries, be aware of the licences when deciding which packaging method you will use.
The 'launch configuration' dropdown is populated with classes containing a main(String[]) method. The selected class is started when you 'run' the jar.
Exporting as a runnable jar uses the dependencies on your build path (Right mouse on project -> Build Path -> Configure Build Path...). When you export as a 'regular' (non-runnable) jar you can select any file in your project(s). If you have the libraries in your project folder you can include them but external dependencies, for example maven, cannot be included (for maven projects, search here).
You could use the Export->Java->Runnable Jar to create a jar that includes its dependencies
Alternatively, you could use the fatjar eclipse plugin as well to bundle jars together
You can right-click on the project, click on export, type 'jar', choose 'Runnable JAR File Export'. There you have the option 'Extract required libraries into generated JAR'.
Personally,
None of the answers above worked for me, I still kept getting NoClassDefFound errors (I am using Maven for dependencies). My solution was to build using "mvn clean install" and use the "[project]-jar-with-dependencies.jar" that that command creates. Similarly in Eclipse you can right click the project -> Run As -> Maven Install and it will place the jars in the target folder.
If you want to export all JAR-files of a Java web-project, open the latest generated WAR-file with a ZIP-tool (e.g. 7-Zip), navigate to the /WEB-INF/lib/ folder. Here you will find all JAR-files you need for this project (as listed in "Referenced Libraries").
While exporting your source into a jar, make sure you select runnable jar option from the options. Then select if you want to package all the dependency jars or just include them directly in the jar file. It depends on the project that you are working on.
You then run the jar directly by java -jar example.jar.
To generate jar file in eclipse right click on the project for which you want to generate, Select Export>Java>Runnable Jar File,
Its create jar which includes all the dependencies from Pom.xml, But please make sure license issue if you are using third-party dependency for your application.
If it is a standalone (Main method) java project then Not any specific path put all the jars inside the project not any specific path then right click on the project - > export - > Runnable jar --> Select the lunch configuration and Library handeling then choose the radio button option "Package required libraries into generated jar" -- > Finish.
Or
If you have a web project then put all the jars in web-inf/lib folder and do the same step.
Before exporting, click on Buildpath and configure java buildpath and add external jars inside the library. Then try to export as a runnable jar.
I have a project A (for example an Ant based Java Application project) and a second project B (a Java Class Library project or another Java Application project, both Ant build based.)
Project B has some additional Java library dependencies (.jar files in the Libraries folder).
A depends on B. A can use classes which are written by myself in B but it can not see classes in the additional libraries of B unless I add those libraries/jar files to A.
Is there a way to get NetBeans to automatically manage the library dependencies in A by including the dependencies of B in addition to B's own jar file? In eclipse when you add .jar files to project B, it is not necessary to add them to A again.
Thanks.
In your project folder you should see a folder called Dependencies, right click on that folder and choose Add Dependency.... Open the Open Projects tab; from there you can select your project from the list. Click Add.
This works for NetBeans IDE 7.2.1.
The simpler NetBeans Ant project Libraries folder is used for compile time and run time dependencies of each individual project. If your "Java Class Library" type Ant based project B has additional library dependencies, they are not automatically forwarded or updated in Project A when you include B as a library of A.
When project A is built, it's .jar file will only contain Project A code and the lib/ folder will only include .jar files from it's Libraries folder. This can cause confusion when you upgrade the dependent library versions and possibly forget to upgrade them everywhere you depend on project B.
You will need to manually manage the dependencies unless you switch to a project management and build system that handles this, like Maven.
A NetBeans Maven project will have a Dependencies folder instead of a Libraries folder and if project B is properly setup and registered as a Maven project and project A is also created as a Maven project, you could Add Dependency on B to A and B would forward it's dependency information to Maven project A.
If you want to add another project as a library in netbeans right click on the libraries directory and select "Add Project", select the project you want to add. When you do this the jar file(in the dist dir) that has been built for the project you are adding will be selected and then click the "Add Project jar files" and that should add the jar file to your project. Alternatively you could select "Add Jar" instead and add the jar file yourself the way that Ravi described.
In your project folder you see a folder called Libraries , right click on that folder from there you can select your .jar file. You need not to add .jar files repeatedly after adding once to your project. You just need to Clean and Build your project whenever new files are added to .jar file.
I've a java project that use some external jar library, when i export my project with eclipse (File-Export-Runnable Jar File), i select the option for "copy external libraries into a subfolder next to the main jar" and eclipse automatically create for me a folder named :
myjarname_lib
I want to export the library in a folder named only lib , is it possible ?
I've tried to rename the folder in lib but don't work, because the executable jar don't recognize the library in that folder.
How can i change the name of the external lib ?
Here is a workaround: When you run the Export wizard, there is a checkbox to create an Ant buildfile. Choose a location for the buildfile inside your project somewhere, then finish the export. Open the buildfile that was created (you might need to hit "F5" to refresh the project). Then just replace all "myprojectname_lib" with "lib". From then on, use "Run As -> Ant Build" for your exports instead of the Eclipse built-in.
The drawbacks are that this buildfile is completely independent of your project and it seems to manage copying each dependency individually. If you change the dependencies of your project, you will have to manually update this file to get the correct exports.