Why isn't javax.activation in the java source zip? - java

elsewhere eg.[1] it is explained that when you install the java source in
ubuntu, it is put here: /usr/lib/jvm/java-6-sun-1.6.0.20/src.zip
The problem is that it does not contain the javax.activation package
and thus not classes like: javax.activation.DataSource
Why isn't it there?
Must I download the source manually to get that?
[1] Where to find Java JDK Source Code?

The package is javax.activation, not java.activation - and typically, source code for javax... packages isn't included.

The various components of javax use different licenses, so this could be the reason. I've taken the liberty to ask your platform of choice's maintainers here.
I will update this answer as soon as I get an answer.

Related

Source for sun.awt.AppContext and others?

I attached the src.zip that came with my JDK, but it seems to be missing a few files.
It's as if I don't have any of the sun.*; packages. I would understand if they maybe got changed out for java.awt.AppContext, but that doesn't exit.
I found AppContext in Container.java (been looking at how Oracle does things), but it shows me bytecode instead of actual code.
Where could I get these files? I looked around on google and found nothing /:
Another thing, when I manually import sun.awt, my IDE shows me that the package exists, but no files in it. Maybe I need to upgrade my JDK? (version 7u45, not too bad)
EDIT on December 30, 2014: Still looking for an answer, now using JDK 8u25
Often time the jar files that are eventually distributed out do not contain the source code of the library but only the built .class files, either aiming to reduce jar size or protect their source code. You may have to refer other resources in order to view the source code. I find www.codatlas.com to be a pretty good place to view some java open source projects. You can find the source code of java.awt.AppContext. It has a pretty IDE-like interface so you should be able to figure out how to use.
These types can be found via the OpenJDK's jdk GitHub Repository.
Here's the implementation for sun.awt.AppContext, which can be found under src > java.desktop > share > classes > sun > awt

Generating jaxb classes from a schema

I am trying to use the Jaxb classes generator in eclipse to generate jaxb classes from my schema.
I receive the following error:
"The classpath for this project does not appear to contain the necessary libraries to proceed with class generation.
Please insure that a JAXB implementation is available on the classpath."
How can i solve this problem?
After a lot of research here is what I have done to fix the issue.
Windows> Preferences> Java> InstalledJREs...make sure to point your jre to the jdk directory. I was pointing to JRE and as soon as I changed it to JDK, it started working.
Hope this will help you guys.
Make sure to include the jaxb-impl.jar library in your project. You can download one for example from here:
https://repo1.maven.org/maven2/com/sun/xml/bind/jaxb-impl/2.2.4/jaxb-impl-2.2.4.jar
If you're using Maven, you can include this as a dependency, otherwise download the file and add it as a library in your project.
If you need a different version of the library, move up one directory in the link that I added above, you can find other versions there as well.
If you want to automate the class generation, since you're changing the schema on a regular basis, you should automate the process, e.g through Maven.
Windows> Preferences> Java> InstalledJREs > Execution Environment. Select an environment JDK 1.8 and then try to create JAXB Classes.
Click on Below Image Link For Details.
Select the execution Environment
Put the tools.jar in the classpath of the projecct (where the generated code will reside).
I found an explanation here https://bugs.eclipse.org/bugs/show_bug.cgi?id=345617
It does not work because Eclipse only puts the JRE libraries in the classpath of the project. Since the xjc code is in tools.jar you need to provide this extra step.
Download com.springsource.com.sun.tools.xjc-2.1.7.jar
and configure the build path.
This solved the warning and the error for me. Hope this helps.

what library I need so I can access this com.sun.image.codec.jpeg in Java?

I'm creating an image watermarking program in java and I imported the followings:
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
but I get an error that says:
Access restriction: The type JPEGCodec is not accesible due to restriction on required library C:\Program Files\Java\jre6\lib\rt.jar
Does someone know a way to solve this, or what library should I add in order to access that and where I find that library?
Take a look here Link
1. Open project properties.
2. Select Java Build Path node.
3. Select Libraries tab.
4. Remove JRE System Library.
5. Add Library JRE System Library.
As Milad suggested
Even though this WILL work, this goes against all recommended Java Runtime policies. The best practice is to avoid using rt.jar (or any other Sun supplied runtime library for that matter, like tools.jar)
These are in rt.jar, the jar file used as run-time facilities by the JVM, and I would strongly recommend you against adding it as a dependency to your project.
See why here.
The correct way to do what you want to do is described here.
The problem is, that you're importing libraries from the sun.com.* package. Oracle actually discourages the use of these packages, since they could be removed in future releases or may not be available in all JVM implementations.
It's possible that your IDE (which one are you using?) is configured for generating errors if you try to import sun.com.* libraries, in that case a configuration change will allow you to use those libraries, but it wouldn't be a good idea anyway. You should look for other alternatives to the functionality you seek, using libraries with no access restrictions.
Also, if what you want is to simply read or write a JPEG file, take a look at the ImageIO class, there are plenty of useful methods in there.
Maybe your jre system library is 1.8
or eclipse: Project Properties > java compiler > Errors/Warnings > Deprecated API
change Error to ignore/warning

com.sun.mirror.apt API

I'm new to Java and I am getting an error via Eclipse on the following lines:
import com.sun.mirror.apt.AnnotationProcessorFactory;
import com.sun.mirror.apt.AnnotationProcessor;
import com.sun.mirror.apt.AnnotationProcessorEnvironment;
The error is "The import com.sun.mirror cannot be resolved".
How do I fix this error?
To the point: just put it in the classpath (buildpath, in Eclipse). You can download it here.
However, this use is not really recommended. Rather use the standard API classes and methods in the javax.annotation.processing API which are already inside the standard Java SE API. It will "behind the scenes" use the right classes for the desired tasks.
Deprecated
apt tool and API have been deprecated as of JDK 7.
Mention on: https://blogs.oracle.com/darcy/entry/apt_api_files
To resolve you can import tools.jar %JDK JAVA%\lib\tools.jar.
In my case "C:\Program Files\Java\jdk1.7.0_01\lib\tools.jar"
also the answer by BalusC is correct but the link is dead and there is simpler solution
in Sun JDK both 1.5 and 1.5 there is tools.jar in the /lib/ add it to the class path it all there.
Though it's deprecated ,if you want to give it a try like dealing with a sample of a book,you may download the zip file of apt-mirror-api-0.1.jar here, and then just build path in your IDE. For eclipse,just right click the JRE System Library-->Build Path-->Configure Build Path-->Add External JARs and finally find your downloaded jar file and apply it.

How do you drop in substitute JRE classes?

java.util.zip has well-known problems with native memory usage, so i'm trying to use a drop-in replacement called "jazzlib". unfortunately as is typical for sourceforge projects there is no documentation. If I add the jar to my classpath then Java freaks out and gives me "prohibited package name" errors because it replaced java.util.zip. How do I tell Java that this is what I want it to do?
Either add it to the boot class path or add it as an endorsed jar.
Perhaps better, use shade to rename the classes back out of the protected packages, and use them that way. The maven-shade-plugin is convenient if you use maven.
For the latest source, see the classpath CVS repository. On this page you'll find source and binary releases of the code in both the net.sf.jazzlib and java.util.zip namespaces.
Just use the one in net.sf.jazzlib namespace so that you can avoid conflicts.
You can specify overrides for classes provided in the JRE by using the commandline arg -Xbootclasspath. Check this link for more details.
I wouldn't install some random (undocumented) library replacement into my JRE, and certainly I would not do it for a production system, or an application that I intended to provide to someone else. Production support folks will (rightly) have a fit if they are asked to do this sort of thing.
But if you really want to do this, the answers from #bmargulies and #akf are helpful.

Categories

Resources