I had a question that was answered with adding jfxrt.jar to standard Eclipse build path.
I followed the suggestion, adding the jfxft.jar as an External Jar on the jdk1.7.0_10.jdk JRE i have installed (under Eclipse > Preferences > Java > Installed JREs).
But when I import "javafx.application.Application"
It errors with:
Access Restriction: The type Application is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/jdk1.7.0_10.jdk/Contents/Home/jre/lib/jfxrt.jar
There are posts on this such as Access restriction: Is not accessible due to restriction on required library ..\jre\lib\rt.jar
I can fix this possibly by the suggestions in that thread (though I'm not convinced they are good solutions).
Or I found a better solution of adding the External Jar directly to the project:
- go to the JRE and remove the External Jar as setup above
- Open project properties and go to Java Build Path
- Go to Libraries tab
- Add External JARS... and choose exactly the same jfxrt.jar
No access restrictions now!
Why does it work one way but not the other? The advantage of adding directly to the JRE configuration is that it only needs to be done once.
Thanks,
Hank
I would not recommend adding JARs to the JRE configuration like that, it's just too easy to forget they are there and that can lead to confusing behavior if you don't expect that particular JAR to be on the build path for a particular project. Also, what happens if one project wants to use a different version of the library?
There are at least 2 other options that I would consider:
Define a User Library for JavaFX and then include the User Library on the projects that need it. You still would have to add the User Library to each project that needs it, but that's not such a big deal IMO, as it only has to be done once for each project.
Create a separate project to contain the JAR(s), call it something like "JavaFX Libs." Add the JARs to its build path and make sure to export them on the Order and Export tab; then add "JavaFx Libs" project as a dependency for whatever projects need it.
Related
I'm using Netbeans 12 with Ant to build my apps. The default folder for libraries is 'lib'. Is there any simple and straightforward way to change it? For example I need to put my libraries in the same folder together with my main .jar when building.
I've checked some older related questions here, but answers were either too complicated or not actual anymore (provided links not working etc.)
Using the NetBeans Project Wizard, select File > New Project > Java with Ant > Java Application, and click Next>.
The wizard screen will include a checkbox labeled Use Dedicated Folder for Storing Libraries. To change the default folder for libraries check that box, and then the following field labelled Libraries Folder will become enabled. You can replace the default value of .\lib with your own directory. For example:
You can use the same approach when creating web applications and enterprise applications. The field settings are sticky, so be sure to check that the values remain appropriate when creating subsequent projects.
I couldn't find any NetBeans 12 documentation on this, but the NetBeans 8.2 documentation remains valid. See section 6.6 Sharing a Library with Other Users for details:
You can configure most standard Java SE, Web, and Enterprise projects
in a way that makes it easy to share libraries with other users. You
can specify a location for libraries on which the project relies. You
can also specify how the libraries are referenced from your project...
Note that this approach will not put (what you called) main.jar in the specified libraries folder. That will still be placed directly under the dist directory. If you want to change that behavior I think you might need to modify some NetBeans Ant script(s).
I want to create a basic java application where I send and receive an email, but my Eclipse doesn't recognize the javax.mail package which I need for the code.
I've downloaded the package, but I can't figure out how to add it to my Eclipse.
I also would prefer that it gets added to my Eclipse workspace and not just to the one project that I am doing, as I will need the package later for other projects.
How do I install the package? I don't know how to properly use things like class paths and command prompts etc, so I need a step by step help if it requires that.
If that's really what you want to do, go to Preferences -> Java -> Build Path -> User Libraries.
Then press new... give it a name and add the jars, which should be ideally located in an appropriate place that makes sense to you and especially not in the JRE directory.
Then you can use those libraries in any new project. For that go to properties of the project, Java Build Path and add the libraries in the (surprise) Libraries tab.
But I think you would be better off using Maven, Gradle or any other build tool in your projects. However if a library is not publicly available in a repository, and you must download the jars, then this a reasonable option.
Here are some images illustrating the process:
1. How to add new libraries to Eclipse
2. Edit library settings (adding source, javadoc and so on)
3. Add your user library to a project
I am Java developer, recently working on Xpages project. we are using Notes 9.0.1. I created Java agent to send email and I want to use some third party jar, something like org.apache.commons.lang3 , end up this issue. how to add third party jar, like commons-lang3-3.4.jar, in my Xpages project?
I tried different ways
add jar under /jvm/lib/ext folder, restart DDE.the I can see it in
my project JRE system libray, but could not import in my Java code.
Maybe this is the way for server deployment.
add jar under /Code/Jars and then DDE generated with new name added in /Webcontent/WEB-INF/lib, but...
Add jar directly under /Webcontent/WEB-INF/lib, but not appeared /Code/Jars in Application view
add jar under the Java agent Archive folder, but...
None of them allows me import the package in my Java code.
Anything I did wrong, or is there any good way to add third party jar in XPages project.
Thanks
If you add a JAR to your project by importing it into /Code/JARs, it should be added so as to be accessible by your build path(2,3). The same is true of your /WebContent/WEB-INF/lib, but that may not be automatically defined in your version of DDE; for example, Domino Designer 9 has the design elements of /Code/Java and /Code/JARs, which didn't previously exist (these are separate folders/paths from /WebContent/WEB-INF/src or /WebContent/WEB-INF/lib, either can be in the build path). In either case, if your approach is to have the JAR in your NSF, make sure your build path has the path with your JARs. Separately you could add each JAR individually.
You can get to the Build Path via Project > Properties, then for the part of your build path concerning JARs, go to "libraries":
individual JARs in Project Build Path
JAR class path in Build Path (ex- /WebContent/WEB-INF/lib)
As for the path of using the /jvm/lib/ext folder approach, I've covered that in a blog post and it's important to remember to have the JARs in the appropriate relative path both on the server and in your Designer/local path (otherwise your local, DDE, may not pick up the change).(1)
For both, if you keep build automatically turned off, you'll want to make sure you perform another build to see the changes.
As for a Java Agent archive, this should just work and again I'm wondering whether your build automatically setting is enabled/disabled. The /jvm/ext/lib path ought to work for this as well (shown in my linked blog post).(4) *Note: as Paul Withers points out in the comments, importing a JAR to a Java Agent can introduce memory leak issues, making the /jvm/ext/lib/ path preferable.
I saw that in Eclipse I can define User Libraries - to make setting the classpath easier (and probably for other reasons as well).
The problem is, that these libraries are only available in the workspace, and if I want other people using the same project to use them - I need to export my user library and they need to import it.
Is there any functionality like this on the project level? I basically need to have a 'classpath group' - can it be done?
If not, is there an automatic way to auto import the user library to the workspace when importing the project?
I'm using Eclipse 3.6.
JDT has the 2 concepts, user libraries and classpath variables. In the classpath variable, you can add jars to your project. Other team members have to fill in the variables in their workspace so their classpath is complete. This is useful when external jars might be in different locations on each team members local file system.
The USER_LIBRARY is a container for adding a logical group of local jars all at once. For example, the JRE_LIB container represents a number of local jars. But as you've seen, it points to a local set of jars meant to be used in multiple projects (as the JRE is added to multiple projects).
Aside from export/import (which you're already doing), I don't believe you can check CLASS_LIBRARIES into a project's SCM. If there was, the preference page would have a "Configure Project specific settings" link at the top.
Your best bet is to simply add the jars to the project, so they'll be included in the SCM. If they can be in different locations depending on the rest of your team, then use a classpath variable so it can be set in each workspace. That's the least amount of hassle as far as team members checking out the project and being ready to go.
The best way IMO is to use m2eclipse - Maven plugin for eclipse. In Maven all the dependencies are defined in pom.xml and downloaded automatically as needed. This means that the only thing you share with your team is pom.xml - your project definition.
There is a lot more advantages when using m2eclipse vs standard eclipse approch. More information is at http://www.sonatype.com/books/m2eclipse-book/reference/
The way I have used user libraries is for something like Ant. Define a user library "ant" for all the jars in ANT_HOME/lib. If including this in your Eclipse .classpath and then sharing with other users, they will get a build problem report until they create that "ant" user library themselves. It's useful, but you need to share knowledge on how to create the library. If you're using it for simple cases like above, then instructions for adding the right jars to the library are straightforward.
Another approach I've used is to build classpaths pointing into a folder (or folders) defined as a variable in Eclipse. See File -> New Folder -> Advanced -> Link to folder in the file system -> Variables. This lets you setup (again at workspace level) variable references to one or more folders. You can then build your Eclipse classpath/s with reference to the folder/s.
So say in your development environment, everyone needs to have a directory called "thirdparty" containing all the external jars dependencies (probably in hierarchy within that dir: thirdparty/apache; thirdparty/sun; ...). You define "thirdparty" as a variable pointing to wherever that dir is on your current system, you create a folder in your project/s using the variable. You can then setup (and share) classpath using paths into that folder.
It's similar to User Library and with similar limitations. The limitation is that the other users you share your project with must create variable folder/s as you have. But it's more flexible in that they don't have to add the jars explicitly as they do with a library; rather, your classpath/s in Eclipse point into the folder, as required for each project.
Note that although the folder variable is defined at workspace level, it can be reused in multiple projects, each of which builds their classpaths (.classpath files) with different references into the folder).
This is maybe something easier to show than to describe with words, but I hope it makes sense.
I have a Red5 application that i want to work on using NetBeans 6.8.
I know I can use a web Free-Form Application, the only problem that I'm having is to add external jar files.
When I go to the project's properties, Where exactly do I add the external jars that I need in order to properly compile the application?
update
i think that the following URL addresses my problem but i can't really understand the solution.
http://www.bradmcevoy.com/blogs/netbeans_ant_ivy.html
You can add the external libraries to your project's Libraries folder, or you can add them in the NetBeans' Tools > Libraries dialog. The latter can be shared among several projects. This answer includes illustrations.
Addendum: For free-form type projects, the Projects > Properties mentions, "Any settings modified on this panel are for IDE purpose only and do not change the build script. If you want to make changes in build process, please modify your build script manually."
found a solution here but it's probably for a lower version of netbeans:
http://forums.netbeans.org/viewtopic.php?p=5329
i get an error on the tag.
Since it is a free-form project, you have to make sure that your build script puts the correct jars into the compile-time classpath. You also want to make your Netbeans project libraries match for auto-complete purposes and error highlighting and such (ie when you view Project Properties->Java Sources ClassPath).
Ok I finally resolved the issue by re-creating the project using the step by step tutorial in the following URL : http://blogs.oracle.com/coreqa/entry/setting_up_freeform_project_correctly