eclipse creating user library using variable to specify jars path - java

Is there a way to create user library in eclipse using class path variable to add relative path jars to the library

It's easy. Don't use User Libraries. Instead, use Variables. Example from my workspace:
Open image in a new tab to see full size
Further reference: Here and there

The approach suggested by GGrec is functional and I used it. But "User Libraries" allow some sort of grouping/structuring, for example "Jersey", or "Hibernate", etc.
I found an alternative way to get it working: Created the simplest Eclipse Project. Then inside it created "Linked Resource" Folder using an Eclipse Path Variable. Now I can create the necessary "User Libraries" and "Add JARs" to them, using this Linked resource folder.
In case the location of the jars is changed, the only thing that should be altered is the Eclipse Path Variable, pointing to them.
May be this approach can help someone else.

Related

Using $PROJECT_DIR$ in the path String in IntelliJ Idea

I have a simple question, but I can't find the answer anywhere. I would like to use $PROJECT_DIR$default path variable in IntelliJ.
I wanted to add an icon to the Stage:
stage.getIcons().add(new Image("$PROJECT_DIR$/src/main/resources/com/example/demo/money.png"));
But this doesn't work, unfortunately :(
I tried also using PROJECT_DIR or MODULE_DIR or $MODULE_DIR$, but nothing works. Maybe it's impossible to use those path variables in such way (?). Please, explain it to me.
Using Absolute Path to the image works, but I would like to share my project and that's why I decided to replace it with a path variable.
You don't have to use directory like this one. Intellij already know where is the project.
You have to check according to where will be located the file when it will be exported.
In you case, you have to use :
stage.getIcons().add(new Image("com/example/demo/money.png"));
Because resources are already consider as resources and so will be in main folder in exported jar.
If it failed, you can try with less package, for example put money.png directly in the resource folder

How can I add a shared library (set to use "isolated classloader") Websphere?

I have been getting some problems with my application because of library I used to JAX-WS. I found one solution but I have to add a share library in WAS 8.5 and I don't know how can I do it.
I'll leave you the link of the documentation I'm following.
http://mail-archives.apache.org/mod_mbox/cxf-issues/201207.mbox/%3C310771353.90819.1343048795043.JavaMail.jiratomcat#issues-vm%3E
Here's the documentation for managing shared libraries: https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.doc/ae/tcws_sharedlib.html
That document is for 8.5.5, but the procedure is the same on 7.0-9.0.
Quick summary: In the admin console, go to the "Environment" section, then "Shared libraries", then create one, name it whatever you want, and set the class path to either the specific jar files you need or the directory containing them (note that if you specify a directory, it'll pull in all the jars in that directory by default). To use an isolated class loader, just check the "Use an isolated class loader" checkbox.

Is it possible to mark files/folders in Eclipse as generated?

my project structure looks like this:
src/main/java
src/main/resources
src/main/generated
....
in the generated folder I place a files which are generated by external software (for example classes generated by JAXB).
In Eclipse all mentioned folders are marked as Source folders.
Is is somehow possible to mark the file in src/main/generated as 'generated' or lock them in another way so that the developer in eclipse is unable to change them?
I don't know if it is possible to do this via the Eclipse UI, but there are APIs that allow a plug-in to mark something as a "derived resource".
Reference:
http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2FresAdv_derived.htm
You can't prevent the user from editing a derived resource, but he / she does get a warning.
The right way of doing is to hide the folder in Eclipse, so that other developers cannot modify it.
Right-click on the project and select properties, then look for "Resource filter".
Click "Add" to add a new filter and fill in the form with all the information. Don't forget to write the name of the folder in "File and folders attributes". Also, select "Files and folders" and "Recursive".
Click ok.
Your folder should disappear from Eclipse, but not from the disk.

Adding external .jar file in Eclipse

I'm having trouble adding a .jar file I downloaded for my Java project. This is really the first time I've used eclipse, so please bear with me and for some reason (I have no clue why), I just find it somewhat confusing.
I know that in order reference different class files you simply need to create a class library and add it to the build path. From there, all which needs to be done (unless I'm misunderstanding this for whatever reason) is use the "import" keyword to import whatever .jar, .java, or .class/.interface file necessary into the project.
I've tried that with my .jar. I have it referenced in the build path (all I did was just copy the jar to the project directory, and then use the build path option to add it externally), but when ever try to call the object "Delegator", which obviously is a part of the .jar file, it won't read.
Am I missing something here? Seriously, anyone who knows the answer to this - you're relieving a mother of a headache. And before anyone asks - yes, I've searched this one to death. I've found similar questions, but nothing which quite hit what I was looking for. Either that, or I really just lack the common sense.
Right click on project->BuildPath->Libraries->Addexternaljar and then press ok and if it doesnot worked then you should go to the Order and Export tab and checked the jar you have just added in your project. It will solved your problem.
There are several possible reasons, for the question hasn't mentioned the specific failure, and where it has occurred. The following is a list of possible reasons I could think of, but this may not be exhaustive:
You can import a class, in a different package only if the class is public. The only exception is when you are using the class in the same package. If the class is an inner class marked as private, then you're well and truly out of luck. The Delegator class in question might not be public, and that's why you may be unable to use it. This issue ought to be caught by the compiler.
The directory structure within the JAR might not match your package import statements in your classes. This might not be necessary, for Eclipse ought to provide possible fixes, but it is better to verify that nevertheless. Again, the compiler should complain if this is the case.
If the issue is at runtime, then, it is most likely that the JAR is not available in the runtime classpath. You'll need to configure the Runtime configuration, to add the JAR to the runtime classpath. Refer to the Eclipse documentation on run configurations, if you need to know how to change the runtime classpath.
Note:
Exporting the build classpath entries would matter to other projects that depend on the pertinent project; unexported entries will have to be re-imported if required in other projects. This would not apply to a run configuration.
Update
Every Java application needs a main(String[] args] method to start execution. This is the entrypoint for the application. From the comment, it appears that the main method is in a different class. If so, the said class ought to be used to start the application. In Eclipse, a "Run configuration" might be used for the class that lacks this entrypoint, resulting in the described error. One can rectify this by creating a new Run configuration for the class with the said entrypoint. This may be done by one of the following:
editing the existing Run configuration to use the desired Class (the one with the main method). See the above link, in the third bullet point. Edit the value of the class to be launched.
creating a new Run configuration for the desired Class. Usually, you'll need to traverse to the desired class, and run your application (using the Alt+Shift+X+J shortcut) from the said class.
i was facing similar issue with spring jar files but then tried with different jar files and it work so I think , classes defined in jar files were private and not available outside of jar hence you were not able to access the file .
thanks ,
Raju Rathi
Right click on the project--->Build Path--->Configure Build Path...--->In left side you have to choose Java Build Path--->Libraries--->Add External JARs--->ok--->ok
Steps to add jar file in eclipse
1. right click on project
2. click on Bulid Path->configure path
3. click on java Build path
4. Click on libraries tab
5. click on add external jar tab
6. choose jar file
7 click on ok
Copy the .jar file in libs folder which you want to add in your project.
Right click on .jar file -> Add Build Path
Done.

Eclipse: Attach source/javadoc to a library via a local property

I have a third-party library in my SVN repository and I'd like to associate source/javadoc with it locally in Eclipse. I.e., there should be some local setting (for example, an entry in the local.properties file) that associates the source/javadoc with the JAR file, but which doesn't introduce local dependencies into the repository via .classpath. Ideally I'd have
lib_src_dir = /my/path/to/lib/src
in local.properties and then
<classpathentry kind="lib" path="lib.jar" sourcepath="${lib_src_dir}">
in .classpath. Can this be done?
[EDIT] #VonC's answer is helpful... Is there a way to load Path Variables from a text file (e.g., local.properties) instead of going through Window -> Preferences -> General -> Workspace -> Linked Resources?
I believe this would be better achieved through:
the creation of a linked folder combined with
the declaration of a linked resource
The linked resource defines a path variable which would be equals to /my/path/to/lib/src
The linked folder would refers to your linked resource
(you can use a variable and not a fixed path, with the "Variable" button)
The variable is actually always local (to one's workspace), and will be modified through the Linked Resources preference screen.
The linked folder can also be... a linked file, thus allowing the reference of an archive through a relative path (relative to the variable).
Then this linked file (here a linked archive) can be associated to your classpathentry in the "source" attribute.
The problem with Linked Resources is they are local to the workspace, in the preferences.
You can export the preferences in a [myPrefs.epf] file, and then trim the exported file in order to leave only the lines containing pathvariable:
/instance/org.eclipse.core.resources/pathvariable.MY_DIRECTORY=/my/path/to/lib/src
Anyone can then import this special preference file, which will only affect the "Linked Resources" part.
That solution is not very satisfying, since the .epf preference file can not be loaded automatically in the project.
When I setup a project with a linked resources defining a path, I always leave a big README.txt at the root of my project, in order to incite the user of said project to define that same linked resources with his/her own fixed local path.
Several bugs are in progress to enhance this situation or around the Linked Resources topic.
Especially:
Exporting a project with linked resources
Relative paths without variables
Have linked resources relative to workspace paths
Would like to use path relative to workspace root
DevByStarlight mentions in the comments the project (not very active since Oct. 2011) workspacemechanic.
The Workspace Mechanic automates maintenance of your Eclipse environment by tweaking preferences, adding extension locations, and so on. You can use it to:
Create a consistent environment among groups as large as the entire company, your local team, or even among your own many workspaces
Save time setting up new workspaces
Create tasks that ensure your favorite new preferences are applied to all your current and future workspaces. (This is one of our favorite features!)
The key to the Workspace Mechanic's behavior is the Task.
A task describes a simple test and an action that, when run, changes the environment so the test will subsequently pass.
Tasks can come in many forms: preference files, Java classes, Groovy scripts and Eclipse extensions. You can easily define your own Tasks.
It comes with a collection of scripts:
workspace-mechanic
workspacemechanic-settings
I just figured out a simple answer to this (in Indigo) after working on it in the background and free moments for a couple of days. The easiest way I've found is to expand your project in the Project Explorer, go into your Referenced Libraries, right-click the appropriate referenced JAR and click Properties. In there you have the options to designate a JavaDocs location. Enter the location of the folder that contains index.html and packages-list, files that are part of the Javadocs. Piece of cake!
The only problem I see so far is that I bet you need to do this in every projects that references that library.
You can do this with classpath variables.
Each developer creates a couple of new variables at Window -> Preferences -> Java -> Build Path -> Classpath Variables.
Define a variable (say, JAVA_LIB_DIR) that points to a directory containing the third-party JAR (or JARS). Define another variable that points to a directory containing the third-party source code (JAVA_SRC_DIR). You can set this up how you like, but we have a structure like this:
common/
lib/
java/ <-- JAVA_LIB_DIR variable points to this directory
axis/
bitronix/
1.0/bitronix.jar "extension" is "bitronix/1.0/bitronix.jar"
...
In your project's build path, use the "Add Variable..." option to add the library. Then you when "attach source," you'll be prompted for a variable and extension to the source code.
This way, a single, shared .classpath file can be checked-in, while allowing each developer to locate their own library and source directories where they like.

Categories