IntelliJ IDEA can't compile with big size library - java

I have a library with huge amount of classes. This jar size = 276MB. When I include this jar to module dependencies, all seems fine. I can use import classes in editor. Navigate to classes and decompile them (Ctrl+N) and so on... All working fine.
But when I try compile this project, compiler tells me: "Can't find symbol class ....", "package ... does not exist".
Gradle compiles fine with this lib. Can JAR size provide problems like this?

To me It looks like IDE bug.
Try the following things:
Try File->Invalidate Caches
Try putting the the jar project correctly
Try recompiling the jar in the IDE (if you have the jav code) and relate to your main project.
If the above don't work, you need to report a bug.

Solved. This is not IDEA bug. This jar was a ZIP64 format... so, and java compiler bellow version 1.7_55 can't operate with it https://blogs.oracle.com/xuemingshen/entry/zip64_support_for_4g_zipfile. In my project i use 1.6 java, gradle use latest, so.
When i change project SDK problems is gone.

Related

Scala IDE Error -could not find/load main class

I am using Scala IDE 4.4.1.,using the jdk 8.When I try to run a scala program ,getting the error "Error: Could not find or load main class example.Credit" .
I was stuck with the same error a few days ago. In my case, it was an incompatibility of my JDK and the selected target JVM for my Scala project.
To check your current Java version, run java -version on the command line. To check your project JVM target in Eclipse, go to "Project > Properties > Scala Compiler" and check the target JVM (choose the same version as your current Java).
Hope it helps.
You should write object instead of class
I was having the same problem so that is how I came to this link & would like to share my findings. In my case I found that incompatible jars where present due to it was throwing error. After providing correct jar issue was resolved.
I used Scala for Eclipse IDE,
The solution for this could be right click on project and select scala -> Set the Scala Installation, will set the scala path to this project and rebuild the same.
Hope this helps you.
If the above mentioned solutions are already configured in your system and still getting this error then consider reading my answer. When incompatible scala jars are referenced by projects, a red cross mark is shown at project level and no errors are shown in scala files. In this situation scala code doesnt compile and when executed shows the message "error could not find or load main class scala". Best solution is to go to the scala installation folder and to check if the jar is present there, if present then reference it else reference jar files that do not show error (red mark) at project level or at source code.

Command works in terminal but not with java [duplicate]

What are the possible causes of a "java.lang.Error: Unresolved compilation problem"?
Additional information:
I have seen this after copying a set of updated JAR files from a build on top of the existing JARs and restarting the application. The JARs are built using a Maven build process.
I would expect to see LinkageErrors or ClassNotFound errors if interfaces changed. The above error hints at some lower level problem.
A clean rebuild and redeployment fixed the problem. Could this error indicate a corrupted JAR?
(rewritten 2015-07-28)
Summary: Eclipse had compiled some or all of the classes, and its compiler is more tolerant of errors.
Long explanation:
The default behavior of Eclipse when compiling code with errors in it, is to generate byte code throwing the exception you see, allowing the program to be run. This is possible as Eclipse uses its own built-in compiler, instead of javac from the JDK which Apache Maven uses, and which fails the compilation completely for errors. If you use Eclipse on a Maven project which you are also working with using the command line mvn command, this may happen.
The cure is to fix the errors and recompile, before running again.
The setting is marked with a red box in this screendump:
try to clean the eclipse project
you just try to clean maven by command
mvn clean
and after that following command
mvn eclipse:clean eclipse:eclipse
and rebuild your project....
Your compiled classes may need to be recompiled from the source with the new jars.
Try running "mvn clean" and then rebuild
The major part is correctly answered by Thorbjørn Ravn Andersen.
This answer tries to shed light on the remaining question: how could the class file with errors end up in the jar?
Each build (Maven & javac or Eclipse) signals in its specific way when it hits a compile error, and will refuse to create a Jar file from it (or at least prominently alert you). The most likely cause for silently getting class files with errors into a jar is by concurrent operation of Maven and Eclipse.
If you have Eclipse open while running a mvn build, you should disable Project > Build Automatically until mvn completes.
EDIT:
Let's try to split the riddle into three parts:
(1) What is the meaning of "java.lang.Error: Unresolved compilation
problem"
This has been explained by Thorbjørn Ravn Andersen. There is no doubt that Eclipse found an error at compile time.
(2) How can an eclipse-compiled class file end up in jar file created
by maven (assuming maven is not configured to used ecj for
compilation)?
This could happen either by invoking Maven with no or incomplete cleaning. Or, an automatic Eclipse build could react to changes in the filesystem (done by Maven) and re-compile a class, before Maven proceeds to collect class files into the jar (this is what I meant by "concurrent operation" in my original answer).
(3) How come there is a compile error, but mvn clean succeeds?
Again several possibilities: (a) compilers don't agree whether or not the source code is legal, or (b) Eclipse compiles with broken settings like incomplete classpath, wrong Java compliance etc. Either way a sequence of refresh and clean build in Eclipse should surface the problem.
I had this error when I used a launch configuration that had an invalid classpath. In my case, I had a project that initially used Maven and thus a launch configuration had a Maven classpath element in it. I had later changed the project to use Gradle and removed the Maven classpath from the project's classpath, but the launch configuration still used it. I got this error trying to run it. Cleaning and rebuilding the project did not resolve this error. Instead, edit the launch configuration, remove the project classpath element, then add the project back to the User Entries in the classpath.
I got this error multiple times and struggled to work out. Finally, I removed the run configuration and re-added the default entries. It worked beautifully.
Just try to include package name in eclipse in case if you forgot it
Import all packages before using it, EX: import java.util.Scanner before using Scanner class.
These improvements might work and it will not give Java: Unresolved compilation problem anymore.
Also make sure to check compiler compliance level and selected jdk version is same
As a weird case, I encountered such an exception where the exception message (unresolved compilation bla bla) was hardcoded inside of generated class' itself. Decompiling the class revealed this.
I had the same issue using the visual studio Code. The root cause was backup java file was left in the same directory.
Removed the backup java file
When the build failed, selected the Fix it, it cleaned up the cache and restarted the workSpace.

Intellij not able to run Scala Code

I have a project that uses both Java and Scala code. When I am trying to run a main function from Scala on Intellij 13.1.4 with Scala Plugin 0.38.441 installed I get the following error
Error:scalac: Error: Scala instance doesn't exist or is invalid:
version unknown, library jar: /home/arpit/.m2/repository/org/scala-lang/scala-library/2.11/scala-library-2.11.jar, compiler jar: /home/arpit/.m2/repository/org/scala-lang/scala-compiler/2.11/scala-compiler-2.11.jar
sbt.InvalidScalaInstance: Scala instance doesn't exist or is invalid:
version unknown, library jar: /home/arpit/.m2/repository/org/scala-lang/scala-library/2.11/scala-library-2.11.jar, compiler jar: /home/arpit/.m2/repository/org/scala-lang/scala-compiler/2.11/scala-compiler-2.11.jar
at sbt.ScalaInstance$.slowActualVersion(ScalaInstance.scala:122)
at sbt.ScalaInstance$.sbt$ScalaInstance$$actualVersion(ScalaInstance.scala:119)
at sbt.ScalaInstance$$anonfun$actualVersion$1.apply(ScalaInstance.scala:32)
at sbt.ScalaInstance$$anonfun$actualVersion$1.apply(ScalaInstance.scala:32)
at scala.Option.getOrElse(Option.scala:120)
at sbt.ScalaInstance.actualVersion$lzycompute(ScalaInstance.scala:32)
at sbt.ScalaInstance.actualVersion(ScalaInstance.scala:32)
at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl$.org$jetbrains$jps$incremental$scala$local$CompilerFactoryImpl$$getOrCompileInterfaceJar(CompilerFactoryImpl.scala:79)
at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl$$anonfun$getScalac$1.apply(CompilerFactoryImpl.scala:43)
at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl$$anonfun$getScalac$1.apply(CompilerFactoryImpl.scala:42)
at scala.Option.map(Option.scala:145)
at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl.getScalac(CompilerFactoryImpl.scala:42)
at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl.createCompiler(CompilerFactoryImpl.scala:21)
at org.jetbrains.jps.incremental.scala.local.CachingFactory$$anonfun$createCompiler$1.apply(CachingFactory.scala:23)
at org.jetbrains.jps.incremental.scala.local.CachingFactory$$anonfun$createCompiler$1.apply(CachingFactory.scala:23)
at org.jetbrains.jps.incremental.scala.local.Cache$$anonfun$getOrUpdate$2.apply(Cache.scala:20)
at scala.Option.getOrElse(Option.scala:120)
at org.jetbrains.jps.incremental.scala.local.Cache.getOrUpdate(Cache.scala:19)
I also checked for compiler settings under Project setting in IntelliJ and for Scala Compiler it says "Nothing to show here in external build mode". Can this be the problem?
It seems that the compiler cannot read the version of the scala-compiler jar. Maybe it is corrupted. Try to redownload it or to use another version. To set another compiler library go to Project Structure/Facets/Scala facet of your module and select a suitable library.
If it does not work please create a ticket on the bugtracker (with the attached compiler library):
http://youtrack.jetbrains.com/issues/SCL
Also you can try to change the type of the incremental compiler in Settings/IDE Settings/Scala
There is nothing wrong with the Compiler/Scala Compiler settings.
I had the same problem, that's what I've done:
(After installing IntelliJ and SBT) I downloaded Scala as well from this website and installed it.
Then I went to File -> Project Structure -> Libraries and I removed the existing library.
Afterwards, I clicked the "+" symbol and "Scala SDK" and found the Scala installation folder (C:\Program Files (x86)\scala\ in my case).
And followed the instructions. Then everything worked fine...
Hope it helps...
I had similar issue when run Idea under the root user. Idea was not able to find the scala library. I solved the issue by quitting the Idea and run it under my current user.
in my case i went into Compiler/Scala Compiler settings and deleted additional compiler options (make -transitive)

Netbeans compiles fine but show errors in editor

Netbeans is not importing a jar from another project. The classpath is fine, the project compiles fine but the editor show several errors in project because it cannot locate classes inside that jar. I've already rebuilded the projects and clean Netbeans' cache (~/.netbeans/7.1.1/var/cache/)
Netbeans version: 7.1.1 and also 7.0
OS version: MacOS 10.7.3
The problem lies with the Netbeans' code editor. My project compiles and it's packaged just fine. I have no problem on that. I have this annoying error messages (eg. red background) in the code editor with no reason.
A workaround I just found: Renaming the dependency project (with refactoring) and adding the new jar to my project do the trick. Still I don't know what happened.
I just had the same problem in NetBeans 7.2.1 today. I could build the project fine but got error markers in the source files and in the Projects tree listings. It seems as if the compiler when you build a project uses a different classpath from the compiler that works in the edit window.
In my case I found we had the same package and class names for different classes in different jars. I don't know if this is relevant or just a red herring.
I still had an error in one project that used these two jars. It seemed like it could only see the classes from the second jar listed in the pom.xml file (we use Maven). I commented out the second jar & rebuilt, then uncommented that second jar & rebuilt and suddenly all of my errors went away.
So I don't have a definite solution but removing and reintroducing a dependency worked for me.
How you import jar file ? You have to right click Libralies in Project Panel and click Add JAR/Folder. And select jar file which you want to import.
I think you have wrongly imported the jar file. Try out the below steps to add jar(s) to your classpath properly.
1. Select your project from the Projects explorer.
2. Right click -> Properties.
3. Select Libraries from Categories list.
4. Click on Add JAR/Folder button.
5. Add your jar(s) & click on OK to finish the process.
Now, it should resolve the reference issues
You mentioned, the editor shows errors because it cannot locate classes inside that jar. Well, are you sure you are using the right jar or right version of jar ? Eclipse is not able to locate any of the classes or only few classes ?
I wish my answer would help fixing the issue (even if too late :) )
Indeed, I have a maven project with two modules. Module1 that contains the class com.x.y.MyClass and Module2 where I'm trying to import com.x.y.MyClass.
It compiles fine, and I can run unit tests using netbeans, but the errors in the editor were embarrassing. So I add Module1 version and packaging type to the pom.xml of Module2 and that fixed my problem (I know, it's very bad to hard code a module version, but at least, I can work without worrying about the editor list of errors)
Cheers !
This is definitely too little too late, but I had this problem today with Netbeans 7.2. All jars were in place, the code was compiling from the build menu, but Netbeans was marking the files in error.
The same exact project was compiling fine with Netbeans 8.0.1.
The problem was with the "Source Root". I clicked on menu Window -> Debugging -> Sources (Alt+Shift+8) and I noticed that I had specified sources on some of the jar dependencies of the project that were no longer valid. Cleaning them up was a 2 step process:
Clean them up from the project files in nbproject dir
Clean them up from
%APPDATA%\NetBeans\7.2\config\Preferences\org\netbeans\modules\java\j2seplatform\Sources.properties
After clean up, I restarted Netbeans and everything was OK.
Hope this helps someone.
I had this issue with few jsf xhtml pages though there wasn't any error in the content of the page. So I opened each page and cut all content, saved the empty file then paste back all content and saved it. it solved the red marking error symbol for me.
I know this question is a bit old but for those who may be facing the same issue currently, hope this will help.
I faced the same challenge after moving my maven projects to a new directory. To fix the issue, I just simply
Renamed the new folder(the one containing my maven projects) just the same name as the previous folder.
Reimported the projects in Netbeans.

How to make javac squawk for incorrect package names in Java source files

Today, I ran into a java source file that had a typo in the 'package' statement at the top. The name of the package did not match the name of the directory the file was sitting in (one extra 's' at the end).
To my surprise, javac from 1.6, checkstyle, and pmd all passed the file as OK. The only tool that got around to complaining was javadoc, and only because it was the only file in the package, and a package with no classes in it is a fatal error to javadoc.
Is there some option to javac, or some other command-line tool (preferably with a maven plugin maven) that will squeal about this sort of goof?
I tested this with the latest version of Eclipse and it complains. Eclipse has Maven support.
Well, this seems like an interesting "feature". I fight with such errors regularly once a year. I would guess that PMD, FindBugs or a tool like that will find these errors. However if you say they do not, I can think of only three other options at the moment:
Use Eclipse compiler from Maven (to compile the sources and see the error). This should be possible although I have never tried it so far.
Create a custom PMD rule that will check the Java package name and compare it with the directory name.
Create your own Maven plug-in that will check it. This may not be very easy if you have not develop a Maven plug-in so far.
These are just ideas and should be treated as such.

Categories

Resources