Is there a way for JDK 11 to help me to strip unused code from a jar file? - optimization

Does JDK 11 include any way of either A) reducing the size of a application jar file by removing unreachable code, or B) producing some sort of report that identifies unreachable code?
I've been stuck on Java 1.8 until recently, and I've had the idea for a year or more that there was some sort of mechanism in JDK 11 like what I describe that I could make use of once I got my code to that version. But now that I'm here, I'm Googling and looking through the JDK docs, and I can't find any such functionality. Am I missing something? I was so sure that there was a new linker, or something else that would do this for me.

Related

Mule4 with Open JRE 11 - Adding additional file module-info.java?

I have downloaded fresh Mulesoft studio and changed configuration to point Open JRE- 11 and compiler to point 11.
Studio version - 7.8
When I try creating the mule project it is now also adding module-info.java along with mule.xml files.
Wonder why it is creating module-info.java I don't used to see when i was working with 1.8 version or before.
Any Idea ?? Thanks in advance.
Java 9 introduced a whole new level of encapsulation. Larger than packages, and more robust too. These are modules.
Chances are you should in the long term, migrate your project to use modules (for additional security, and for better code organization). However, the chances are also high that you won't want to do it right now, just because.
In that latter case, it would be reasonable to simply delete the module-info.java file. Provided you don't have any other module-info.java files in the system, and provided you run with everything on the classpath rather than module path (there's a good chance that's your default anyway) you should not have any problem.
Meanwhile, you have some homework to do, so you can decide if you will migrate to modules, and if so, how to do it.

Code obfuscation in IntellIJ 14

I'm working on developing a Jar artifact on IntellIJ 14, and I'd like to know if there is an easy way of obfuscating the code prior to sending it to my clients. So far, everybody talks about IntelliGuard, but the plugin was only maintained up to IntellIJ12, and it throws an exception when trying it on the newest versions.
Another option that I have read about is ProGuard, but I cannot find an step to step manual on how to make it work with IntellIJ.
I'm very curious if someone knows how to make any of the two work on the new version of the IDE, or if the know of any other method of obfuscating my code.
Thanks,
Cris.

IntelliJ: cannot find java.util.Optional

In a new project in IntelliJ I have set up a Java 8 JRE/JDK and language level 8.0.
But for some reason, the IDE cannot find java.util.Optional. The project compiles and works just fine (from within the IDE, too) but code completion does not work.
Any ideas? I'd like to ask a few other users before creating a ticket on their bugtracker...
I finally figured this out. For whatever reason, there was an entry for java.util.Optional in the exlusions under Editor, General, and Auto Import.
Removing that did the trick. No idea how or why it ended up being there. Doesn't sound like anything I would want to do.
Stupid IntelliJ.
I have a SpringBoot project which worked just fine. Then, the next day, when I want to run it, I got this error:
Caused by: java.lang.Error: Unresolved compilation problem:
The type java.util.Optional cannot be resolved. It is indirectly referenced from required .class files without changing anything!
I cleared IntelliJ cache.
Although it was a maven project it was already using JDK8,
I have changed the Project Settings, and said (again) to use JDK8,
Maven re-import, Cleaned the project, Build->Rebuild project, and it magically worked again
I had a similar problem in ubuntu. For me the problem was that I used JDK1.7 and when I changed it to JDK1.8 everything worked just fine.
Now, that makes sense, as Optional is something that was introduced in JDK1.8, before that the concept was exists only in Guava: http://onelineatatime.io/optional-guava-and-java-8/
Ran into the same problem (in IntelliJ 2017.2.7) and solved it like this:
Project Structure->Modules->Module SDK and there change it to 1.8
I've also first set Java compiler to 8 and Project Structure->Project->Project SDK and Project language level also set to 8 without success. In the end, the step I described finally fixed it.
I ran into this recently. The issue was related to my Project SDK setting. Didn't have to clear any caches.
The issue shows with my Project SDK set to 1.8 (1.8.0_202). The issue was fixed by changing it to 11 (11.0.6). Also confirmed that the issue reappears when I switched it back to 1.8.
In java 8 some functions of Optional class not supported such as isEmpty, ifPresentOrElse, or, stream, orElseThrow. You should check whether you use them or not. If you want to use these functions you can use java 11.

Why does IntelliJ IDEA 13.1 show sbt files with so many lines in red?

I had a working sbt based project. After some small change that I can not specifically identify all the sbt files are having object resolution issues (see screenshots).
I tried the following:
sbt refresh
project rebuild
reimport project
These did not work.
Then I started going farther afield to resolve the issue. I copied the *.sbt files from another project on top of the ones in this project. Still no dice. Now I do not have time presently to actually completely destroy, rebuild the project from scratch - and in any case that does not lead to any insight on the root cause here.
Has anyone experienced this issue - and any suggestions on remedies/workarounds?
Update I finally tried
sbt gen-idea
even though this project was **not ** built that way.. It did make a difference: at least the crazy errors went away. But now a different set of problems arises: the assembly and packaging imports are not being resolved (see LAST screenshot). But this seems a bit more healthy at least .
Following screenshot is after running sbt gen-idea. Situation has improved but now get assembly/packaging import errors.
Another update
OK, I have quit and restarted IJ and things are finally back.
So the objective changes that I made:
sbt gen-idea
stop/restart IJ
This is feeling like magic incantations here .. Not a solid process.
A sort of a workaround could be to upgrade to the latest EAP of IntelliJ IDEA 13.1.3 build 135.909, released on May 23rd, 2014. It comes with more sophisticated Scala plugin that is much clever than the previous versions and hopefully could help here and there.

Can't find java.util.stream in java8

I have installed jdk-8-ea-bin-b82-windows-x64-21_mar_2013 and IntelliJ IDEA 12.0.4. The strange thing is that I can't find java.util.stream in the intellisense provided by the IDE. I tried to compile either using the IDE or using the notepad and the compiler but it gives an error complaining that java.util.stream cannot be found! I have already set the module settings to use Java8 jdk. Any ideas about this problem?
I had the same problem with Netbeans. It seams that older versions of JDK 8 are not correctly packaged.
I had the same problem with b84, but I installed the build b116 and it is working properly.
PS: I think this is what #rmuller said in his comment
To change the JDK version, go to File --> Project Structure, and make sure both Project SDK and Project Language Level are set to JDK 8.
(I know you said you set the JDK level in the modules already, but I'm posting this here because there is relatively little information online on how to do that. Even the IDEA documentation on this issue doesn't mention it!)
Try to download from: http://jdk8.java.net/lambda/ to have lambda and stream support
As #rmuller pointed out there was no streams in the early release version that I have downloaded 5 years ago when I asked the question. Short while after I asked the question a new release was available and it contained the streams support.
YOU CAN SET PROJECT SETTING IN MODULES
THE LANGUAGE LEVEL SET 8-LAMBDAS
enter image description here
BEACUSE THE DEFAULT LANGUAGE LEVEL IS 7 -Diamonds