Parallelism in Java 8 - java

I tried to use new parallel feature JDK8, but unfortunately, I couldn't get it to work.
NetBeans 7.1 says that method "parallel" does not exist.
Does this method require special import?
Does anyone have sample code demonstrating Java 8 parallelism?

I have been playing with JDK8 Lambda Developer Preview for a few weeks now. The following is what I do to simplify compilation and testing of my code:
Configure JEdit to Compile JDK 8 Code
The following guide describes how to configure Apache Ant and JEdit to easily compile source code with JDK 8 Lambda Expressions and the new API features in the JDK 8 Lambda Developer Preview.
This is what I do, as of today, basically because no IDE supports these JDK 8 features yet.
Download the following:
JDK 8
JEdit
Apache Ant
Then create the following directory structure:
Sanbox
|-----jdk8
|-----ant
|-----projects
Place the uncompressed JDK build in the jdk8 directory.
Place the uncompressed Apache Ant in the ant directory.
The projects directory will be for JEdit projects.
Then install the following JEdit Plugins:
Ant Farm
Java Fold
Project Builder
Project Viewer
Project Wizard
SVN Plugin (I use this to synchronize my projects with my repo, you may not need it, though)
Now, configure your Apache Ant:
Create a file in your home folder named antrc_pre.bat (i.e. %USERPROFILE%\antrc_pre.bat).
(Note: if you are using Linux you can configure this in ~/.ant/ant.conf).
This file will be run by Apache Ant before running any tasks, therefore, this is a place to configure or override which JDK you want to use by defining the JAVA_HOME variable.
At the top of this file define the JAVA_HOME variable and make it point to the directory where the JDK8 is installed. Somewhat like this: SET JAVA_HOME=C:\Sanbox\jdk8
Make sure to comment it out once you're done with your JDK 8 session so that Ant continues to use the default configuration.
Time to configure JEdit Ant Plugin
In JEdit go to Plugins -> Plugin Options -> Ant Farm -> Build Options
In the dialog select the option: "Run Ant targets using an external script/build file"
Choose the ant.bat script (i.e. C:\Sandbox\ant\bin\ant.bat).
Note: If you are using Ant 1.8.x it is probable that you'll need to add a property in the properties section of the plugin: build.compiler=javac1.7, otherwise you would get an error at compiling with JDK 8. I did not have this problem with Ant 1.7, though.
Then create a new Java Project:
In JEdit go to Plugins -> Project Builder -> Create New Project
Choose Java Application and click Next
Choose your projects directory as the place to locate files (i.e. C:\Sanbox\projects).
Voila! At this point, JEdit will present four buttons in the tool bar: Build Application, Compile, Clean and Run Application. These are based on the build.xml file and are executed according to the corresponding Ant tasks. You're good to go, you may start writing lambda expressions and use the new APIs:-)
Parallelism Example
In the last developer preview (b50), there is little paralleism implemented yet. I can see they are doing more work in a seperate branch (if you want to download and build the OpenJDK8 source, though).
You can, however, use a method Arrays.parallell which creates a ParallelIterable wrapper over an array. This you can use to test some of the parallelism features.
I did an example to find primes in a large array. I could verify that all my four cores are used when I run this in parallel.
Integer[] source = new Integer[30000000];
for(int i=0; i<source.length; i++)
source[i] = i;
ParallelIterable<Integer> allIntegers = Arrays.parallel(source).filter(isPrime);
Iterable<Integer> primes = allIntegers.into(new LinkedList<Integer>());
This compiles and runs fine in my JEdit Project with Apache Ant 8.4.x and JDk8-b50.
I hope this helps.
PD:
I did not define the predicate isPrime in the code above in order not to obscure the simplicity of the example. I am pretty sure eveyone can easily define a primality predicate to try this code.

My suggestion would be to put Netbeans to one side, use a plain text editor to edit your Java code, and compile and run it from the command prompt, using the Java 8 toolchain. That way you can be sure that your problems are not due to a Netbeans issue.

Check if your netbeans is using jdk8 (i doubt it) . If it does not then make it point to your local copy of jdk8 instead of the inbuilt jdk.
Hope this helps.

You can use the nightly version of Netbeans which now has some experimental support for JDK8 features - I've given this a try and it seems to work well with lambdas (at least you don't get the red squiggles under them, auto-formatting and suggested corrections don't seem to work properly yet, but they're more in the way of minor niggles.) You'll need to make sure you add the Lambda enabled JDK8 as a Java Platform, and then set the source level to Java 8 for the project you want to experiment with.
You can grab the latest Lambda enabled build of the JDK here.
At the time of writing, there are 3 types of parallel methods on the static Arrays class which can be experimented with - parallelStream(), parallelPrefix(), and parallelSort(). Note however that this will likely change before the final release, the API at present is very much in flux.

Below example finds all directories in my documents directory:
List<File> directories = Arrays.asList(new File("/Users/sid/Documents")
.listFiles())
.parallelStream()
.filter(t -> t.isDirectory() == true)
.collect(Collectors.toList());
Java 8 provides stream support where a collection is transformed into a continuous stream of objects. If the size of the collection is small .stream() is alright. But if you have a big collections and want to exploit the parallelism feature then you can use .parallelStream() method.

Related

How to make Eclipse compile patched modules on JDK 9+ by passing the --patch-module javac option to my project compiler? (see pic)

Eclipse has to allow that, since javac from JDK allows it without requiring me to contact the CIA for clearance. If eclipse does not allow that, what other Java IDE would allow me. Worst-case scenario I'll just use emacs and terminal.
Screenshot:
Most of the relevant information has already been given in comments, I'm mostly summing it up with a little background and some links:
Firstly, Eclipse does not accept a folder named java.base within your source folder. Such layout is used by javac's multi-module mode, but in an IDE like Eclipse that mode is not needed, since we have projects for grouping the modules. In particular Eclipse requires that each project contains at most one module. Now you are free to either (a) define src/main/java/java.base as a source folder, or (b) move its content one level up (so that packages start directly in src/main/java as in the olden days).
Secondly, for setting up options like --patch-module the UI has been revamped in Eclipse 2019-06, so I suggest to upgrade Eclipse (if not already done). Then you will find a new tab in the Java Build Path configuration dialog called "Module Dependencies" where you can mark your project as patching java.base. (The method from older versions of Eclipse was: find a node "Is Modular" below the library you want to patch and edit (double click) its details. This mode is still supported for a migration period, but it is no longer recommended).
Thirdly, the Java Build Path, which is used for building/compiling (as the name suggests :) ), should also be respected for launching. To make sure that compile-time and runtime see the same set of options, both dialogs (Java Build Path and Run as ...) have a button for showing the textual form of the configured options (called JPMS options in the build path configuration).

Why is eclipse restricted from here [duplicate]

I'm attempting to compile Java 1.4 code that was created by IBM's WSDL2Java on Java5 without recreating the stubs and saw this error in Eclipse.
I'm under the assumption that the stubs generated should just compile as long as the runtime jars are available (they are).
Access restriction: The type QName is not accessible due to restriction on required library C:\Program Files\Java\jdk1.5.0_16\jre\lib\rt.jar
The full class name is javax.xml.namespace.QName
What exactly is going on here? Is this a case where I am trying to refactor a pig from sausage? Am I better off recreating the stubs?
There's another solution that also works.
Go to the Build Path settings in the project properties.
Remove the JRE System Library
Add it back; Select "Add Library" and select the JRE System Library. The default worked for me.
This works because you have multiple classes in different jar files. Removing and re-adding the JRE lib will make the right classes be first.
If you want a fundamental solution make sure you exclude the jar files with the same classes.
For me I have: javax.xml.soap.SOAPPart in three different jars: axis-saaj-1.4.jar, saaj-api-1.3.jar and the rt.jar
http://www.digizol.com/2008/09/eclipse-access-restriction-on-library.html worked best for me.
On Windows: Windows -> Preferences -> Java -> Compiler -> Errors/Warnings
-> Deprecated and restricted API -> Forbidden reference (access rules): -> change to warning
On Mac OS X/Linux: Eclipse -> Preferences -> Java -> Compiler -> Errors/Warnings
-> Deprecated and restricted API -> Forbidden reference (access rules): -> change to warning
I met the same problem. I found the answer on the website: http://www.17ext.com.
First, delete the JRE System Libraries. Then, import JRE System Libraries again.
My guess is that you are trying to replace a standard class which ships with Java 5 with one in a library you have.
This is not allowed under the terms of the license agreement, however AFAIK it wasn't enforced until Java 5.
I have seen this with QName before and I "fixed" it by removing the class from the jar I had.
EDIT
http://www.manpagez.com/man/1/java/ notes for the option "-Xbootclasspath:"
"Applications that use this option for the purpose of overriding a class in rt.jar should not be deployed as doing so would contravene the Java 2 Runtime Environment binary code license."
The http://www.idt.mdh.se/rc/sumo/aJile/Uppackat/jre/LICENSE
"Java Technology Restrictions. You may not modify the Java
Platform Interface ("JPI", identified as classes contained
within the "java" package or any subpackages of the "java"
package), by creating additional classes within the JPI or
otherwise causing the addition to or modification of the
classes in the JPI. In the event that you create an
additional class and associated API(s) which (i) extends
the functionality of the Java platform, and (ii) is exposed
to third party software developers for the purpose of
developing additional software which invokes such
additional API, you must promptly publish broadly an
accurate specification for such API for free use by all
developers. You may not create, or authorize your
licensees to create, additional classes, interfaces, or
subpackages that are in any way identified as "java",
"javax", "sun" or similar convention as specified by Sun in
any naming convention designation."
I have been getting this error too, but my project is built on the command line using Maven and the tycho compiler (it's a set of OSGi plugins). After masses of sifting through people having the same problem but fixing it in Eclipse rather than on the command line, I found a message on the Tycho developer forum that answered my question, using configuration in pom.xml to ignore the compiler warning about the access restriction:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<version>${tycho.version}</version>
<configuration>
<compilerArgument>-warn:+discouraged,forbidden</compilerArgument>
</configuration>
</plugin>
More information can be found in the Tycho FAQ. This took me AGES to work out, so I figured I would assist anyone else trying to fix these access restriction errors from the command line by posting this answer.
Go to the Build Path settings in the project properties.
Windows -> Preferences -> Java Compiler
Remove the JRE System Library
Add another JRE with a "perfect match"
clean and build your project again. It worked for me.
I just had this problem too. Apparently I had set the JRE to 1.5 instead of 1.6 in my build path.
In addition to Nels Beckman's solution, I have the following tips:
Under Configure Build Path, I had to rearrange the order of my entries under Order and Export.
Additionally, as an Eclipse PDE developer, I needed to rearrange the order of my dependencies in my MANIFEST.MF, adding the problematic package as first on the list.
Playing with these dials, along with running Project > Clean in between, I was able to resolve these warnings.
for me this how I solve it:
go to the build path of the current project
under Libraries
select the "JRE System Library [jdk1.8xxx]"
click edit
and select either "Workspace default JRE(jdk1.8xx)" OR Alternate JRE
Click finish
Click OK
Note: make sure that in Eclipse / Preferences (NOT the project) / Java / Installed JRE ,that the jdk points to the JDK folder not the JRE C:\Program Files\Java\jdk1.8.0_74
Sorry for updating an old POST. I got the reported problem and I solved it as said below.
Assuming you are using Eclipse + m2e maven plugin, if you get this access restriction error, right click on the project/module in which you have the error --> Properties --> Build Path --> Library --> Replace JDK/JRE to the one that is used in eclipse workspace.
I followed the above steps and the issue is resolved.
In the case you are sure that you should be able to access given class, than this can mean you added several jars to your project containing classes with identical names (or paths) but different content and they are overshadowing each other (typically an old custom build jar contains built-in older version of a 3rd party library).
For example when you add a jar implementing:
a.b.c.d1
a.b.c.d2
but also an older version implementing only:
a.b.c.d1
(d2 is missing altogether or has restricted access)
Everything works fine in the code editor but fails during the compilation if the "old" library overshadows the new one - d2 suddenly turns out "missing or inaccessible" even when it is there.
The solution is a to check the order of compile-time libraries and make sure that the one with correct implementation goes first.
Go to the Java Build Path in the project properties. Remove the existing JRE System Library
Then Add it again i.e. Add Library-->JRE Lib--select jre--->Finish.
Lastly select order and export tab select JRE Lib and move on top. That's it.
Just change the order of build path libraries of your project. Right click on project>Build Path> Configure Build Path>Select Order and Export(Tab)>Change the order of the entries. I hope moving the "JRE System library" to the bottom will work. It worked so for me. Easy and simple....!!!
In my case there was a mismatch between the build path JRE and installed JRE on execution environment. I moved into Project > Properties > Java compiler. There was a warning message at the bottom.
I clicked on the links 'Installed JRE', 'Execution environment', 'Java build path' and changed the JDK version to 1.7 and the warning disappeared.
Adding a right JRE System through build path is the solution but your eclipse still may have the error.
To solve that go to Java Build path --> Order and Export and move your JRE system library on the top. This has solved my problem.

How to get CachedRowSet implementation by Sun in my Java project? [duplicate]

I'm attempting to compile Java 1.4 code that was created by IBM's WSDL2Java on Java5 without recreating the stubs and saw this error in Eclipse.
I'm under the assumption that the stubs generated should just compile as long as the runtime jars are available (they are).
Access restriction: The type QName is not accessible due to restriction on required library C:\Program Files\Java\jdk1.5.0_16\jre\lib\rt.jar
The full class name is javax.xml.namespace.QName
What exactly is going on here? Is this a case where I am trying to refactor a pig from sausage? Am I better off recreating the stubs?
There's another solution that also works.
Go to the Build Path settings in the project properties.
Remove the JRE System Library
Add it back; Select "Add Library" and select the JRE System Library. The default worked for me.
This works because you have multiple classes in different jar files. Removing and re-adding the JRE lib will make the right classes be first.
If you want a fundamental solution make sure you exclude the jar files with the same classes.
For me I have: javax.xml.soap.SOAPPart in three different jars: axis-saaj-1.4.jar, saaj-api-1.3.jar and the rt.jar
http://www.digizol.com/2008/09/eclipse-access-restriction-on-library.html worked best for me.
On Windows: Windows -> Preferences -> Java -> Compiler -> Errors/Warnings
-> Deprecated and restricted API -> Forbidden reference (access rules): -> change to warning
On Mac OS X/Linux: Eclipse -> Preferences -> Java -> Compiler -> Errors/Warnings
-> Deprecated and restricted API -> Forbidden reference (access rules): -> change to warning
I met the same problem. I found the answer on the website: http://www.17ext.com.
First, delete the JRE System Libraries. Then, import JRE System Libraries again.
My guess is that you are trying to replace a standard class which ships with Java 5 with one in a library you have.
This is not allowed under the terms of the license agreement, however AFAIK it wasn't enforced until Java 5.
I have seen this with QName before and I "fixed" it by removing the class from the jar I had.
EDIT
http://www.manpagez.com/man/1/java/ notes for the option "-Xbootclasspath:"
"Applications that use this option for the purpose of overriding a class in rt.jar should not be deployed as doing so would contravene the Java 2 Runtime Environment binary code license."
The http://www.idt.mdh.se/rc/sumo/aJile/Uppackat/jre/LICENSE
"Java Technology Restrictions. You may not modify the Java
Platform Interface ("JPI", identified as classes contained
within the "java" package or any subpackages of the "java"
package), by creating additional classes within the JPI or
otherwise causing the addition to or modification of the
classes in the JPI. In the event that you create an
additional class and associated API(s) which (i) extends
the functionality of the Java platform, and (ii) is exposed
to third party software developers for the purpose of
developing additional software which invokes such
additional API, you must promptly publish broadly an
accurate specification for such API for free use by all
developers. You may not create, or authorize your
licensees to create, additional classes, interfaces, or
subpackages that are in any way identified as "java",
"javax", "sun" or similar convention as specified by Sun in
any naming convention designation."
I have been getting this error too, but my project is built on the command line using Maven and the tycho compiler (it's a set of OSGi plugins). After masses of sifting through people having the same problem but fixing it in Eclipse rather than on the command line, I found a message on the Tycho developer forum that answered my question, using configuration in pom.xml to ignore the compiler warning about the access restriction:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<version>${tycho.version}</version>
<configuration>
<compilerArgument>-warn:+discouraged,forbidden</compilerArgument>
</configuration>
</plugin>
More information can be found in the Tycho FAQ. This took me AGES to work out, so I figured I would assist anyone else trying to fix these access restriction errors from the command line by posting this answer.
Go to the Build Path settings in the project properties.
Windows -> Preferences -> Java Compiler
Remove the JRE System Library
Add another JRE with a "perfect match"
clean and build your project again. It worked for me.
I just had this problem too. Apparently I had set the JRE to 1.5 instead of 1.6 in my build path.
In addition to Nels Beckman's solution, I have the following tips:
Under Configure Build Path, I had to rearrange the order of my entries under Order and Export.
Additionally, as an Eclipse PDE developer, I needed to rearrange the order of my dependencies in my MANIFEST.MF, adding the problematic package as first on the list.
Playing with these dials, along with running Project > Clean in between, I was able to resolve these warnings.
for me this how I solve it:
go to the build path of the current project
under Libraries
select the "JRE System Library [jdk1.8xxx]"
click edit
and select either "Workspace default JRE(jdk1.8xx)" OR Alternate JRE
Click finish
Click OK
Note: make sure that in Eclipse / Preferences (NOT the project) / Java / Installed JRE ,that the jdk points to the JDK folder not the JRE C:\Program Files\Java\jdk1.8.0_74
Sorry for updating an old POST. I got the reported problem and I solved it as said below.
Assuming you are using Eclipse + m2e maven plugin, if you get this access restriction error, right click on the project/module in which you have the error --> Properties --> Build Path --> Library --> Replace JDK/JRE to the one that is used in eclipse workspace.
I followed the above steps and the issue is resolved.
In the case you are sure that you should be able to access given class, than this can mean you added several jars to your project containing classes with identical names (or paths) but different content and they are overshadowing each other (typically an old custom build jar contains built-in older version of a 3rd party library).
For example when you add a jar implementing:
a.b.c.d1
a.b.c.d2
but also an older version implementing only:
a.b.c.d1
(d2 is missing altogether or has restricted access)
Everything works fine in the code editor but fails during the compilation if the "old" library overshadows the new one - d2 suddenly turns out "missing or inaccessible" even when it is there.
The solution is a to check the order of compile-time libraries and make sure that the one with correct implementation goes first.
Go to the Java Build Path in the project properties. Remove the existing JRE System Library
Then Add it again i.e. Add Library-->JRE Lib--select jre--->Finish.
Lastly select order and export tab select JRE Lib and move on top. That's it.
Just change the order of build path libraries of your project. Right click on project>Build Path> Configure Build Path>Select Order and Export(Tab)>Change the order of the entries. I hope moving the "JRE System library" to the bottom will work. It worked so for me. Easy and simple....!!!
In my case there was a mismatch between the build path JRE and installed JRE on execution environment. I moved into Project > Properties > Java compiler. There was a warning message at the bottom.
I clicked on the links 'Installed JRE', 'Execution environment', 'Java build path' and changed the JDK version to 1.7 and the warning disappeared.
Adding a right JRE System through build path is the solution but your eclipse still may have the error.
To solve that go to Java Build path --> Order and Export and move your JRE system library on the top. This has solved my problem.

Why won't Eclipse let me use the JFrame class? [duplicate]

I'm attempting to compile Java 1.4 code that was created by IBM's WSDL2Java on Java5 without recreating the stubs and saw this error in Eclipse.
I'm under the assumption that the stubs generated should just compile as long as the runtime jars are available (they are).
Access restriction: The type QName is not accessible due to restriction on required library C:\Program Files\Java\jdk1.5.0_16\jre\lib\rt.jar
The full class name is javax.xml.namespace.QName
What exactly is going on here? Is this a case where I am trying to refactor a pig from sausage? Am I better off recreating the stubs?
There's another solution that also works.
Go to the Build Path settings in the project properties.
Remove the JRE System Library
Add it back; Select "Add Library" and select the JRE System Library. The default worked for me.
This works because you have multiple classes in different jar files. Removing and re-adding the JRE lib will make the right classes be first.
If you want a fundamental solution make sure you exclude the jar files with the same classes.
For me I have: javax.xml.soap.SOAPPart in three different jars: axis-saaj-1.4.jar, saaj-api-1.3.jar and the rt.jar
http://www.digizol.com/2008/09/eclipse-access-restriction-on-library.html worked best for me.
On Windows: Windows -> Preferences -> Java -> Compiler -> Errors/Warnings
-> Deprecated and restricted API -> Forbidden reference (access rules): -> change to warning
On Mac OS X/Linux: Eclipse -> Preferences -> Java -> Compiler -> Errors/Warnings
-> Deprecated and restricted API -> Forbidden reference (access rules): -> change to warning
I met the same problem. I found the answer on the website: http://www.17ext.com.
First, delete the JRE System Libraries. Then, import JRE System Libraries again.
My guess is that you are trying to replace a standard class which ships with Java 5 with one in a library you have.
This is not allowed under the terms of the license agreement, however AFAIK it wasn't enforced until Java 5.
I have seen this with QName before and I "fixed" it by removing the class from the jar I had.
EDIT
http://www.manpagez.com/man/1/java/ notes for the option "-Xbootclasspath:"
"Applications that use this option for the purpose of overriding a class in rt.jar should not be deployed as doing so would contravene the Java 2 Runtime Environment binary code license."
The http://www.idt.mdh.se/rc/sumo/aJile/Uppackat/jre/LICENSE
"Java Technology Restrictions. You may not modify the Java
Platform Interface ("JPI", identified as classes contained
within the "java" package or any subpackages of the "java"
package), by creating additional classes within the JPI or
otherwise causing the addition to or modification of the
classes in the JPI. In the event that you create an
additional class and associated API(s) which (i) extends
the functionality of the Java platform, and (ii) is exposed
to third party software developers for the purpose of
developing additional software which invokes such
additional API, you must promptly publish broadly an
accurate specification for such API for free use by all
developers. You may not create, or authorize your
licensees to create, additional classes, interfaces, or
subpackages that are in any way identified as "java",
"javax", "sun" or similar convention as specified by Sun in
any naming convention designation."
I have been getting this error too, but my project is built on the command line using Maven and the tycho compiler (it's a set of OSGi plugins). After masses of sifting through people having the same problem but fixing it in Eclipse rather than on the command line, I found a message on the Tycho developer forum that answered my question, using configuration in pom.xml to ignore the compiler warning about the access restriction:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<version>${tycho.version}</version>
<configuration>
<compilerArgument>-warn:+discouraged,forbidden</compilerArgument>
</configuration>
</plugin>
More information can be found in the Tycho FAQ. This took me AGES to work out, so I figured I would assist anyone else trying to fix these access restriction errors from the command line by posting this answer.
Go to the Build Path settings in the project properties.
Windows -> Preferences -> Java Compiler
Remove the JRE System Library
Add another JRE with a "perfect match"
clean and build your project again. It worked for me.
I just had this problem too. Apparently I had set the JRE to 1.5 instead of 1.6 in my build path.
In addition to Nels Beckman's solution, I have the following tips:
Under Configure Build Path, I had to rearrange the order of my entries under Order and Export.
Additionally, as an Eclipse PDE developer, I needed to rearrange the order of my dependencies in my MANIFEST.MF, adding the problematic package as first on the list.
Playing with these dials, along with running Project > Clean in between, I was able to resolve these warnings.
for me this how I solve it:
go to the build path of the current project
under Libraries
select the "JRE System Library [jdk1.8xxx]"
click edit
and select either "Workspace default JRE(jdk1.8xx)" OR Alternate JRE
Click finish
Click OK
Note: make sure that in Eclipse / Preferences (NOT the project) / Java / Installed JRE ,that the jdk points to the JDK folder not the JRE C:\Program Files\Java\jdk1.8.0_74
Sorry for updating an old POST. I got the reported problem and I solved it as said below.
Assuming you are using Eclipse + m2e maven plugin, if you get this access restriction error, right click on the project/module in which you have the error --> Properties --> Build Path --> Library --> Replace JDK/JRE to the one that is used in eclipse workspace.
I followed the above steps and the issue is resolved.
In the case you are sure that you should be able to access given class, than this can mean you added several jars to your project containing classes with identical names (or paths) but different content and they are overshadowing each other (typically an old custom build jar contains built-in older version of a 3rd party library).
For example when you add a jar implementing:
a.b.c.d1
a.b.c.d2
but also an older version implementing only:
a.b.c.d1
(d2 is missing altogether or has restricted access)
Everything works fine in the code editor but fails during the compilation if the "old" library overshadows the new one - d2 suddenly turns out "missing or inaccessible" even when it is there.
The solution is a to check the order of compile-time libraries and make sure that the one with correct implementation goes first.
Go to the Java Build Path in the project properties. Remove the existing JRE System Library
Then Add it again i.e. Add Library-->JRE Lib--select jre--->Finish.
Lastly select order and export tab select JRE Lib and move on top. That's it.
Just change the order of build path libraries of your project. Right click on project>Build Path> Configure Build Path>Select Order and Export(Tab)>Change the order of the entries. I hope moving the "JRE System library" to the bottom will work. It worked so for me. Easy and simple....!!!
In my case there was a mismatch between the build path JRE and installed JRE on execution environment. I moved into Project > Properties > Java compiler. There was a warning message at the bottom.
I clicked on the links 'Installed JRE', 'Execution environment', 'Java build path' and changed the JDK version to 1.7 and the warning disappeared.
Adding a right JRE System through build path is the solution but your eclipse still may have the error.
To solve that go to Java Build path --> Order and Export and move your JRE system library on the top. This has solved my problem.

Thinking in java library installation

Hi i've been trying to install the library on Thinking in Java book 4th edition and i hit a very thick brick wall. I've done everything that the guide from the website told me to do and i still can't get the library to work. From what i've read it seems that the problem is from the build.xml files. having no xml knowledge I am clueless about how I have to modify it in order for it to work. In both cmd and eclipse I am getting these error
c:\TIJ4\code\build.xml
Build Failed
c:\TIJ4\code\build.xml:59:J2SE5 required
Can anyone tell me what I should do ?
I am using eclipse if there is a simpler solution by using eclipse rather than ant please help me out. It's been a week now and I still can't make it work.
The important thing to do is to realize that your ant file has a specific java requirement.
Something to try that might fix this very easily : I believe you can remove any references to a specific JDK, and if you have a reasonably up to date JDK, the build will succeed.
The definete fix : Look into the exact (line 59) of your build file, and try to satisfy the java version that line requires. Java is generally backwords compatible -- something designed to run in J2SE5 should run in the latest JDK. Its not terribly difficult to update your JDK (just google for instructions on your OS).
The most common mistake I see is that people who have the java run time installed believe they also have the Java SDK as well.
Does this "install the library" means you want to look at the code and run them in your eclipse? If so I can share my experience with you.
First run the Eclipse.py script; this will add package info to the source code
Create a new Java project in Eclipse, and then just copy all the source code folders to the src source folder in eclipse, these folders will then be recognized as Java packages.
You should be able to run the classes with a main function.
You can also configure which java version to use for this project in Eclipse build path. 1.5 or higher will work.

Categories