How to organize jar files in a libraries folder in Eclipse? - java

I have a Java Project in Eclipse, and a Java Dynamic Web Project in Eclipse. In the former, all the jar files are shown individually under the top-level project folder. In the latter, the jar files are under a Libraries folder and the navigation is more convenient.
Is it possible to organize them in the same way in the Java Project also? If so, how?
Update: It is the Project Explorer View. For the Java Project, I see: "my_project_name" with the arrow expanded to point downwards, then I see: "package_icon src/main/java" and below that "package_icon src/main/resources" and then 20 jar files one below the other: "jar_icon activation-1.1.jar", ...
For the Java Dynamic Web Project I see: "my_project_name" as above, then I see: "JAX-WS Web Services" (unexpanded), then "Deployment Descriptor" (unexpanded), then "Java Resources" which I have expandeded, so I see the components of it below, of which the first is: "package_icon src/main/java", then below it, "package_icon src/main/resources", then below it "libraries_icon Libraries" instead of 20 jars! I have the option of expanding Libraries if I really need to see the 20 jars.

The only option I found to make things prettier in Eclipse Kepler is to:
In the Project Explorer window there is a down arrow in the upper right corner. Select that and then Customize View.
Select 'Libraries from external' and then OK.
Kind of cheesy...
EDIT: Of course I had to go and do some more digging...and it looks like I'll have to try this and see how it works.

Similar to M Miller's answer (but for Juno), click Show 'Referenced Libraries' Node in the dropdown of the Package Explorer window:
I'm using:
Eclipse IDE for Java Developers
Version: Juno Release
Build id: 20120614-1722

I noticed this "feature" on Eclipse Juno (latest version), when you have a jar file added to the build path it is not shown as a single file on the project.
Try removing one of the jars from the build path to see if it shows up again.
I couldn't find how to turn it off though.
BTW... the project layout for your "Java Project" is more akin to a "Maven Project", which is a bit more powerful.

You should change into the Package Explorer by Window > show View. It will display all the referenced libraries in a Referenced Libraries folder.

Related

Export wizard application in netbeans

I did a sample application mentioned in this link using Netbeans Wizard template https://platform.netbeans.org/tutorials/nbm-wizard.html
But how do I export as executable jar. I just want to execute the project independently with out IDE. Any suggestions.
I can't find it in the tutorial that you point to but in order to share your newly created Netbeans plugin you need to export it as a binary NetBeans Module or .nbm file. Right click on your project and select Create NBM. Check this old tutorial here: http://docs.huihoo.com/netbeans/6.0/kb/60/platform/nbm-google.html
For Netbeans 8.0: When the file is created you can then go Tools->Plugins , downloaded tab and then click add plugins
EDIT (based on your comments)
The tuturial you point to guides you to build a custom Netbeans module (in this case a Wizard). The module is packaged as a .nbm file which you can then distribute it so that it can be installed to any Netbeans IDE.
As it turns out you need something like a "Java swing wizard" application. By searching google you can find some results that fit your needs (these are from the first google results):
http://www.oracle.com/technetwork/articles/javase/wizard-136789.html
https://code.google.com/p/cjwizard/
http://www.javaworld.com/article/2077850/java-se/open-source-java-projects-the-wizard-api.html
http://sourceforge.net/projects/jwf/
Similar question (maybe you can post a comment asking for details there):
https://softwareengineering.stackexchange.com/questions/132723/is-there-a-java-library-to-create-assisted-wizard-flow-into-your-desktop-applica
Hope I am not leading you to the wrong way but another thing you can also have a look at, (haven't checked it myself but you might find it useful) is how to create OSGI modules and the posibility of converting Netbeans modules to OSGI modules.
Look here: http://wiki.netbeans.org/OSGiAndNetBeans.

How to configure/Run an Ant Java project in Eclipse

I have a working java project (in ubuntu 12.04LTS, configured and compiled using ant). Is there a way I can configure and run it in Eclipse? Every time I try to load it in eclipse it gives a bunch of errors because of packages not being where its expecting I guess. Also, it will help if you could tell whats build path. I'm using Eclipse Java EE IDE Kepler Release.
My project structure looks like this:
project
build.xml
build.properties
build.common
projFolder - proj code, 3rd party lib/bin/src,
commons - proj code, ui code, 3rd party lib and binaries
dist - has a bunch of scripts and jars and may be some binaries
And how I got my project in Eclipse (this is probably not the most efficient way to have the project running in Eclipse, not sure)
I did new->java project then enter project name, unchecked 'use default location' and provided the location of my project so it imported my project in eclipse. then in my classes i have all the errors (red cross at the display) and it says imports cannot be resolved, objects can't be resolved to a type and such.
import com.psid.codedata.projects.TProjectDRD;
import com.psid.codedata.projects.TProjectsDRD;
error on above imports:
The import cannot be resolved
It probably needs you to add all your source folders to the build path:
Right-click on your project and select Properties,
Along the left-hand side click "Java Build Path",
Click the "Source" tab if it isn't already selected,
Click the "Add Folder..." button on the right-hand side,
Select whatever your source folders are in projFolder and commons,
Click the "Libraries" tab,
Click the "Add JARs..." button on the right-hand side,
Select whatever your libraries are in projFolder, commons and dist,
Click the "OK" button.
Note that "New -> Java project" is for creating a brand new, empty project. Since you want to create an Eclipse project from an existing project with an Ant script, you should select the appropriate selection under the "Ant" subsection in the New Project dialog. See this answer to a related SO question for details.
add this line to nbproject/project.properties:
j2ee.server.home=http://localhost

Eclipse Open declaration in Java project

In an Eclipse SVN project I have a problem; when I tried to open a declaration of one class, I got this error:
Problems opening an editor Reason : projectname does not exist.
Also refactoring does not work.
I have searched the web and tried all found solutions but nothing helped.
I have downloaded different Eclipse and Java versions and switched to a clean workspace but I still have the problem.
How can I solve my problem or which solution can I try?
Right Click on the project -> Properties -> Project Facets -> Click on the Configuration Link -> Click on Apply Button -> Click on OK button.
The above steps should set your project as a Java project.
If the project is a multi-module Maven project, then you need to import the child/module projects in addition to the parent/pom project. Then ensure that you only open source files via the child project. Java files opened this way will have the Refactor right-click menu item, and F3 Open Declaration etc. work properly. However if the Java file is opened from the parent project, these Eclipse functions will be missing.
It's quite frustrating when opening a file via a Search result, as the file will be found and listed in both the parent and child project. You need to ensure you only work with the file accessed via the child project.
I can't explain precisely what's going on with Eclipse, but it appears that Eclipse does not recognize the parent project as being Java projects, although it will correctly syntax-highlight the Java files whether they are accessed via the parent or child project.
You needed to to check it out as a Java Project, or preferably, its creator should have committed the .project and .classpath files for it.
I had this problem, too.
It looks like after a search-in-workspace Eclipse opened a wrong file.
I pressed Ctrl + Shift + H (Open Type in Hierarchy), typed in the class name, and opened it. The file opened in a new tab, and everything was navigable again.
The difference in icons is:
you can solve the problem by create a new java project.
when you check out the project,you should select the default option,
[Check out as a project configured using the new project wizard].
It might lack a builder. Check your PROJ_HOME/.project that should be like:
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>the-one-user</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Ref:
FAQ How do I add a builder to a given project?
Are you importing a maven project? If you importing a maven project, a file will be viewed in few perspective, especially if you open the file via "Open Resource (Ctrl + Shift + R)".
Let's look at the example above, "servlet-filter" (mark as 1) imported as maven project, and maven perspective project created in 2. If you open a file in 1, your "Open Declaration F3" will no work, because it is not a valid maven project. It will work if you open the same file in 2.
Hope this helps.
You need to import it as a Java/Maven project. Once you are done importing the project do the following steps
Go to Project -> Select Properties -> Select Project References -> Select/Check all the
dependent/Child projects which you reference in the code base -> Apply
and Close
Once you are done, try to clean the whole project. This should solve the issue.
There is a bug in Eclipse (in Luna at least) for a very specific workflow, which might not be the answer to this specific question, but might be helpful for others.
If you perform an import into the src (meaning src folder has focus before performing import) folder from an extracted jar (as source code), and you place breakpoints in the nested *.java files in the nested packages, it won't hit those breakpoints. In order to get things to work, you must keep hitting F3 instead of using "Open Declaration" to get to the *.java file you want to set a breakpoint in, then add the breakpoint by double clicking in the far left margin. Then Run > Debug As > Java Application.
If the format of the project you checked out is of type Maven, you need to convert it to a Maven project first. It may be because the required classes haven't been generated yet. To do this, right-click on the project, click Configure, and then click Convert to Maven Project.
I had the same in Eclipse Luna on Debian 8.
I was missing the .classpath file when checking out from SVN.
I manually copied it and changed some path names, refreshed the project and it was working again.
It happens, when libraries are not available on class path of the project where F3 does not work.
Select any other project and try to use f3 for navigation. It will work.
The solution is to add JAR files in your libraries or add libraries in your project.
Try to use MAVEN project so that the problem can never occur.
I am using Eclipse Oxygen.2 (4.7.2). I don't see Project Facets after clicking project -> Properties. My solution is right click the project and click Configure, then select configure and detect nested projects, Eclipse will automatically generate the nested projects for you. May get some build errors in the new created projects, that should be easy to fix.
Go to Project properties,Select Project Facets then convert to project facets then click Ok then you will able to open editor.

Error in Eclipse: "The project cannot be built until build path errors are resolved"

I am a computer science student learning Java, so I do some work at home and at college on a mixture of Linux and Windows. I have a problem after copying a new project into the Eclipse workspace. The project shows up, but with a red exclamation mark and an error saying:
The project cannot be built until build path errors are resolved
How can I fix this? I tried the solution described here, but it didn't work.
Identify "project navigator" or "package explorer" view.
Right click on your project, select Build Path --> Configure build Path.
In the emerging window, you will find four tabs, select "Libraries".There, under "Web app libraries" (expand it), you will see the libraries added to the project's classpath. Check if all of them are available. If one or more are not (they'll have "missing" beside their name and a red mark on their icon), check if you need them (perhaps you don't); if you don't need them, remove it, if you need them, exit this window, look out for the missing jar and IMPORT it into your project.
Open the Problems view. You can open this view by clicking on the small + sign at the left hand bottom corner of eclipse. It's a very tiny plus with a rectangle around it. Click on it and select problems.
The problem view will show you the problems that need to be resolved.
If the message says "the project is missing the required libraries...", you need to configure your build path by right clicking on your project, selecting properties, then build path. Add the required jar files using the libraries tab.
-If there are other problems other than missing libraries, you need to post the exact problems here to get a precise solution.
If you can't find the build path error, sometimes menu Project → Clean... works like a charm.
In my case, all libraries in the build path were OK.
To solve it, I deleted all project metadata (.project, .classpath, .settings) and re-imported the project as a Maven project.
Right click your Project > Properties > Java Build Path > Libraries
Remove the file with red "X" (something like JRE...)
Add Library
That's how I solved my problem.
I also had this problem in my system, but after looking inside the project I saw the XML structure of the .classpath file in the project path was incorrect. After amending that file the problem was solved.
If not working in any case...then delete your project from the Eclipse workspace and again import as a Maven project if that is a Maven project. Else import as an existing project.
I tried all the previous given solutions, but they didn't work, but it works for me.
In Eclipse, go to Build Path, click "Add Library", select JRE System Library, click "Next", select option "Workspace default JRE(i)", and click "Finish".
This worked for me.
Go to Project > Properties > Java Compiler > Building
Look under Build Path Problems
Un-check "Abort build when build path error occurs"
It won't solve all your errors but at least it will let you run your program :)

Import source java project in Android project

Is it possible to import an existing Java project which is in my workspace, in an Android project which is also in my workspace? The Java project doesn't use stuff that is incompatible with Android. I could do it using a .JAR, but since I'm modifying the Java project a lot, I would like to import the whole source code and change it once in a while. Is it possible? Thanks
This is somewhat of a hack, but worked for my project:
Add both Android project and plain Java project to workspace
Go to properties for Android project -> Java Build Path -> Source
Click Link Source, in "Folder name", make sure to select the root directory of the plain Java project's src tree
Use a descriptive name for "Linked folder location", like "java_project_src".
Press Finish and compile
This setup will compile the plain-java code as Dalvik bytecode. In my case, I had pure java code with very limited dependencies, but wanted to share the pure java code with non-Android projects, instead of separately maintaining these files in every project.
I think you are talking about referencing other projects into the current project, if this is the case then you can do this by Right click on project, properties->Project Reference.
You can link another projects to your current project. Right click on your main project, choose Build Path -> Configure Build Path... In the dialog choose the Projects tab, then click Add.. button. Now choose the project you want to link and click OK. You'll now be able to use this project's sources inside your main project. Hope this helps.

Categories

Resources