This is getting to me a bit.
What should be a straightforward and well worn procedure to do something all users need to do is anything but straightforward.
I made the Java class I want to add to all new Java projects into a JAR file.
And I got it into the JRE folder using Window > Prefs > Java > Installed JREs, etc.
But come runtime, the Java interpreter just doesn't see this class as attached to my projects.
Anyone know how this pesky one is fixed ?
I'm using Eclipse 3.6.2 Helios and JRE 7.
The JRE isn't really intended to be extended in this way. If you must store your shared libraries in the JRE, the ext folder should be used, rather than the top-level JRE folder. However, even this is usually a bad practice: Is putting external jars in the JAVA_HOME/lib/ext directory a bad thing?.
To add dependencies to your Eclipse projects, use the project's build path. To add dependencies at run-time, use the Java class path.
I would create a userlibrary and add the lib to the project setup. http://goo.gl/pEoto
Consider to use Maven to manage your dependencies.
Related
I'm trying out Java 9 Jigsaw module system (no module experience yet) and would like to use it for capsuling the classes within my project, but it's confusing.
According to this article it should be possible to have multiple modules within ONE project. I made a new project in Eclipse Oxygen (Java 9 is supported) with the same structure as shown in the article. But Eclipse keeps telling me that I must not have more than one module-info.java in a project.
I really don't know how to tell Eclipse that it should use the "multi-module-mode". And I really would appreciate not having to create a new project for every single module.
This works:
This not:
But according to this article something like that should work:
And how about deployment of a modularized project with Eclipse? There is nothing to see about the new jmod extension. Do I still export it as a runnable JAR file like before?
Notice that my questions refer to working with the IDE (no command line, I mean with an IDE that should be possible, right?) Thank you for enlightening me.
Currently, Eclipse requires you to create a separate project for each module (e. g. because each module has its own Java Build Path).
To understand this design decision, consider that Java modules correspond to OSGi bundles / Eclipse plug-ins and it has always been to have a separate project for each bundle/plug-in. If you come from the Maven world, you would probably expect a deeper folder structure instead. But modules are self-contained and combining several modules into one project would only add an additional folder level without meaning. However, Eclipse supports nested projects and so-called working sets if you need an additional folder level.
Exporting modules as images is planned for Eclipse 2019-03 (4.11), on March 20, 2019 (see Eclipse bug 518445). Exporting modules as JARs that can be used on the modulepath (-m) already works (see my video).
I don't know if this question is still open for an answer, but you can solve this problem by simply removing all source folders on the build path. At least this works for Eclipse 2021-12 version.
As you can see this is a demo project from the Official Gradle Guide Book and it has multiple modules. Each module has its own module-info.java.
project structure in IntelliJ IDEA
If I open this project in Eclipse it will give me the 'duplicated entries on module-info.java' error.
Eclipse shows the error
But if I delete all the source folders on the build path, the error is gone and the project can be built and run without problem.
project properties: Java build path
The only problem is that you have to build the project with Gradle so that it will produce the .jar of each module and you have to include them in the libraries later.
include all the .jar in libraries
I think this is probably the same solution mentioned by howlger above.
Below is my project structure.
-project
-sources
-my.package
-MyClass.java
-test
-my.package
-MyClassTest.java
I want to use JDK version less than 1.5 for my source.
Where as my junit test classes needs latest JDK.
Is there any possibility to use two different JDKs for same project.
Current solution: I can configure latest JDK for the project and can compile using different targets one for source and one for test. javac -target.
Is that correct way to do? or Please suggest any correct solution.
Thanks in advance.
In an Ant build, you can freely specify different JDK and compiler settings for different source folders.
But for Eclipse compilation, I think you will be restricted to using one JDK and compiler settings per-project. I don't think you can specify separate compiler per folder in an Eclipse project.
Options:
Treat these folders as separate Eclipse projects. Or,
Implement Ant build for both folders, but Eclipse build only for one of them. For
example, your junit classes would be built by Ant only.
Netbeans 6.9.1, Enclojure (Netbeans's GUI question)
I want to use standard java libraries in my clojure code (e.g swing), but project's folder 'Libraries' contains clojure's dependencies only (3 jars). How I can add jdk to this dependencies if it wasn't added automatically?
UPD: my mistake, ok. i mean...
How I can view jdk structure (classes) in project tree? Or somewhere in netbeans?
Those are part of the JRE, and will be available from any Java program whether you like it or not. You don't have to do anything special to get them.
Responding to you comment to amalloy's answer, in the Project window, under Libraries, it will list the JDK version you are using. You can expand that to show the JARs included. You can then expand individual JARs to show the classes included. (I verified this with NetBeans 7, but recall that it worked the same way on 6.9.)
As I'm quite new to Java, I would like to know the proper procedure of installing new libraries (those that are no available in my linux dist repositories).
Where should I place them? and how to install them?
For instance, I downloaded openCsv (http://opencsv.sourceforge.net/), and I have no idea how to install it.
Java libraries don't really need to be 'installed' like other applications. All you need to do is put the jar file in a specific location, and add the jar file to your classpath. How you do that depends on the linux distro you are using. If you are making a web application in eclipse, you can drop the .jar file in the WebRoot/web-inf/lib folder, and it will be bundled in with your project.
Be sure that the path, which you place the libaries at, is set in the $CLASSPATH Environment Variable.
For Eclipse: Project -> Properties -> Java Build Path -> Add JARs...
It's up to you really - I use /opt/javalib, but you might consider a directory in /usr/local as well.
You can store them wherever you wish. You can store them within the JRE distribution directories, but I wouldn't recommend that.
Instead I would store them per-project (so you can have different versions for each project easily - some libraries have different names for each version, some don't) and adopt a standard such as a lib/ directory. That way you can have standard build scripts (Ant etc.) that can operate in the same way (if you're using Maven, then there's a standard place per-project - src/main/resources)
You could use Maven to manage any dependencies to those libraries.
Maven will automatically download all needed JAR files and put them in a local repository (the location is configurable).
This makes upgrading to new versions of various libraries very easy as you just declare the version you want and Maven does the rest.
Beware: Maven is something to get used to and the initial learning curve is steep.
The rewards come if you have everything set up properly and maven takes care of compiling, packaging, distribution, site creation, release management etc. etc. etc.
I'm a bit confused with NetBeans (versions 6.5 and 6.7). I have a NetBeans Module Suite application, which consists of several NetBeans Modules. I need to add some code in one of the modules. The new code is using a library, distributed as several jar files.
The problem is, that NetBeans does not allow me to add this library jars directly to the classpath. It wants to wrap all the jars in a new Library Wrapper Module, which is then added to the project and used from there. The effect is that all the original jars are combined into a single new jar automatically by NetBeans. This is a problem, because I can't just replace the jars later, without rebuilding this "Library Wrapper Module" and the original library is updated nightly.
I read some NetBeans forums, but I found nothing... I tried with simple java application, where it is possible to simply add jar(s) to the classpath using Project Properties -> Libraries -> Add JAR/Folder. If you use a NetBeans module instead of a simple application, the Libraries dialog looks different and does not have the "Add JAR/Folder" button.
Is it possible to add a plain normal jar in a NetBeans module and how?
It looks like the way a user can wrap a jar has changed in NetBeans 6.8.
Since this has been integrated into a property dialog of a project, the build process might be smarter, too. And it seems like that was your primary concern....