I am a novice and don't have much idea. So I have a library that is built with Maven and I want to include this library in my java project in Eclipse, how do I do this? I am using Eclipse juno on MacOSx. I want to run one of the modules in this library, so the source code is provided for this module but how do i run this?
If you are not using maven, you have to download the jar and the sources of that jar (In your case, you can download the zip file provided on the website you mention : http://code.google.com/p/cleartk/downloads/list ) and put it somewhere on your computer.
Then you have to set the build path of your project in Eclipse :
Right-click on your project -> Properties -> Java Build Path
Then you can click on the Libraries tab and Add External Jars so you can point to the jar you downloaded.
In this tab, you can attach the sources of this jar to have access to the source code in Eclipse (and eventually set breakpoint).
Related
I'll start this off by saying that I'm not a Java dev, I work in a .NET software house, but somehow we have ended up needing to modify some legacy java code.
So I have a project which I've opened up with IntelliJ IDEA Ultimate 2016.2. As far as I can tell this doesn't use Maven or Gradle or any other dependency management tool, and as I have no idea what I'm doing with Java projects I'm not going to start trying to understand that now.
I'm trying to add the Amazon AWS SDK to my project so I can upload some files to an S3 bucket. I've downloaded the SDK from the AWS site, and extracted the jar files into the lib folder of my project root. I've tried numerous ways of adding these as dependencies, right click the jar files and add as library, go into settings, modules, dependencies, click the plus and add the jars etc. When I build the project it builds fine, and intellisense if picking up the classes and methods when writing the code to utilise the SDK.
However, as soon as I run the app, I get a "java.lang.NoClassDefFound" for the com/amazonaws/AmazonServiceException package as the containing class is instantiated.
This could well be something to do with the "CLASSPATH" that I hear so much about (but don't fully understand), but my understanding was that IntelliJ handled this when adding the jars as a dependency. I've also tried adding all the jars from the "third-party" directory from the downloaded AWS zip file, and adding those as dependencies as well, but it still doesn't want to work.
Incidentally, I'm adding the jars to the lib folder so they are included in source control.
Any suggestions on how to use the AWS SDK without using Maven or Gradle?
Cheers
What I've done is to manually add all the jar files into the External Libraries.
Go to File > Project Structure
In the left window pane, choose Modules under Project Settings
Click on the Dependencies tab
Click on the + sign and select 1 JARs or Directories
Navigate to the folders containing the jar files (include third-party dependecies also) and click OK
See My IntelliJ screenshot
I am working on a specific maven module. I have it imported into eclipse by m2eclipse plugin. The module uses our internal plugin to generate java files from some csv files. During install goal those files are being generated and put to target/generated-sources/folder_name.
Can you tell me how I can import these java files into eclipse so it stops showing me compilation errors saying that 'x' cannot be resolved to a type?
Now every module which uses those files has compilations errors in eclipse, everything works fine when I try to build from command line.
Thanks in advance.
UPDATE: Thanks a lot guys, I was trying similar solution but instead of adding source folder I was trying to add external classes :|
project -> properties -> java build path -> source -> add folder -> (search for target/generated-sources/folder_name, create it if deleted by maven) -> ok
now eclipse will only complain when you'll use mvn clean deleting target folder.
Eclipse refreshes file content on request, so any change made external to eclipse, eclipse doesn't know about that
You can make eclipse to use native hooks to detect external changes
preference > workspace > check refresh using native hooks
and add that directory to source path
You probably need to add the folder of the generated files as a Source folder in the project. Look in the Project Properties > Java Build Path > Source tab and add the folder.
So I am using
Eclipse IDE for Java EE Developers
http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/keplerrc3
and I am trying to add the jasypt - 1.9.0 plugin to eclipse
Since I am not experienced in this, I only tried one way which is
1- Download the zip file form the following url
http://sourceforge.net/projects/jasypt/files/
2- Unzip the file into the eclipse subdirectory plugins
3- Restart eclipse
However it seems that there is something missing
Go to your downloaded file and go to the lib folder. In there, you have a whole host of jar files. It is most likely the jasypt-1.9.0 jar you want.
In Eclipse: go to: Properties > Java Build Path > Libraries
Choose to add an External Jar and navigate to the location of the jasypt-1.9.0.jar
This will add the jar and its libraries to your project. Note: Look at the API for what you are using if this doesn't work - you may require a different jar to be imported instead/as well.
This is the standard way to add any third-party libraries to your project.
I have created a java project using eclipse and in that project I have included a few jar files such as sqljdbc4.jar, jtds-1.2.4.jar, and log4j-1.2.17.jar. I have also included a dll for windows authentication in this project. I'm attempting to export this project as either a .zip .tar etc so the project can later be imported by someone else and work with the project.
I want to export the file in a way that the other developer can import the project and instantly begin working without having to download the jar files that the project is dependent on. Is this possible at all
I have already tried what i have thought would have worked going to export -> Archive file -> save in .zip format. I was unsuccessful with this I also figured going to properties -> Order and Export tab and selecting the needed jars would work and then exporting still unsuccessful.
Once the other developer imports the project the jars are not there for him...
I would use Ant. It is integrated right into eclipse and takes an .xml file called build.xml. It works by specifying "targets" in the xml file that each perform some action such as "build" (i.e. run javac), "deploy" (i.e. run the jar command), etc. There is a command that can be called from within the jar target called zipgroupfileset which you can use to package all of the jars within your main jar file.
More info about ant can be found here
There are many variations on the following but the basic idea is to
use a code library and share the project. The repository
can be local to you or even better put it on an http server
( ala VisualSVN or google or the like ).
1st (local) solution:
Install SVN ( http://subversion.apache.org/ )
Install SubVersion
Create a repo on your local file system
Share the project
Dump the repo
Send the repo
Load the repo (Other developer)
2nd (network) solution (using google code as your library)
Install SVN ( http://subversion.apache.org/ )
Install SubVersion
Put your project on GoogleCode (http://code.google.com/)
Other developer gets 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.