Problems minifying Angular2 with Wro4j - java

I have a little web app using Spring Boot and Angular 1, Maven and Wro4j, and I want to give a try to Angular 2, which I am completely new in.
I use Maven/Wro4j 1.8.0 to minify at compile time and get a single js file for angular dependencies, which I then use in my index.html header. While it worked with my angular 1 app, minifying fails now. I use jsMin as a processor. It fails when handling webjar:angular__compiler/2.1.1/bundles/compiler.umd.js.
Digging in the wro4j doc, I found the ngAnnotate processor, which may be the solution to my problem. But I got two more issues there:
I added ng-annotate 1.2.1 to my pom.xml (wro4j dependencies) but it fails because of an unsatisfied transitive dependency to acorn (ng-annotate 1.2.1 pom depends on acorn [2.6.4,2.7), and there is no such version on Maven central). To circumvemt this, I edited the ng-annotate pom to use acorn 2.7.0, which may not be the best solution.
After getting my dependency OK and adding ngAnnotate to the processors list (before jsMin), I get this error message:
processor is not supported on this environment
It seems that it tries to run ng-annotate and does not find it. The Wro4j documentation states that "The implementation assume the required npm is installed". I thought (wrongly, it seems) that adding the ng-annotate webjar to the pom would be enough. What did I miss?
Note: I would really like to go on letting Maven handle all the configuration (Java and Js), which worked before, instead of switching to a js dependency solution. I never used any npm command, nor grunt, nor bower, and never needed it so far.

The way wro4j works with ng-annotate, it simply executes the command ng-annotate in the project folder.
So it is probably due to your PATH variable that is not configured correctly and that does not reference the folder that contains ng-annotate whether you install it through webjar or npm.
For example, if you use Eclipse Configurations, you can re-set the PATH variable in the "Environment" tab.
To figure out the right path:
For webjar, do a search on where the ng-annotate npm executable is extracted.
For NPM, open a terminal, see if ng-annotate works (it has to be installed globally with npm install -g ng-annotate) and then display env variable: echo $PATH or the path of the executable: which ng-annotate.
I had the same error and in my case, Maven did not have /usr/local/bin referenced in the PATH.

Related

new dependency not recognised by Maven

Using maven version 3.6.3 and JDK version "openjdk-17"
I've tried using Maven's dependencies so I could use the xstream library in my project. Following a guide I added com.thoughtworks.xstream to my pom.xml file:
I then tried to use xstream, but intellij couldn't resolve "XStream" even though it seems to work for JavaFX just fine. This code does not compile.
EDIT: I loaded a new project, where I used, what I believe to be, up to date versions. Maven 3.8.1, the latest intellij version, and everything else (JDK, openjfx) at version 17.0.2 yet when I try to use "XStream" in my project code (after reloading the maven project) it says "Cannot resolve symbol XStream"
Edit 2:
I added junit to the dependencies, it works. I add Gson to the dependencies. It doesn't work.
I figured out that in the "modules-info.java" file, "requires xstream" is needed. That is all
One of the following may solve your problem:
These are based on my previous experiences.
because may be auto import disabled. re Import maven project.(intellij: press Ctrl+Shift+A then actions - input "reload" find "Reload All Maven Projects").
in my experience, sometimes it does happen that the dependency is not fully received. remove xstream special version folder from .m2 (com->thoughtworks->xstream) and repeat step 1.
maybe repository not valid. check repository source in file settings.xml in .m2 (if exist) or replace to other source.
invalid cache and restart (intellij: file-> invalid caches/restart). This has solved my problem several times.
Your access to the site or repository may be closed. check network policy or use vpn (Poor probability)

A build scan was not published as you have not authenticated with server 'ge.spring.io'

I'm working on Windows 10 pro, Java 1_8 or Java 1_15. No corporate proxy,
connectivity to the internet works just fine.
I'm trying to build spring-boot from the source. I cloned the github repo, then checked out the tag that I needed.
git clone https://github.com/spring-projects/spring-boot.git
git checkout tags/v2.3.9.RELEASE
It failed to switch to that tag. It's actually the first time I saw an error while trying to switch to a tag. That's ok. I deleted that directory, switched to the tag in the browser and downloaded the zip.
I unzipped the directory and then attempted to build with gradle from source.
gradlew build
I got the following error
A build scan was not published as you have not authenticated with server 'ge.spring.io'
I originally tried with JDK 1.8 then switched to JDK 15. Same error both times.
I noticed that spring boot page suggested gradle wrapper. So I googled on how to do that and found that I needed to run
gradle wrapper
That produced the same error message.
So I thought maybe I should register with ge.spring.io. I actually looked into that when I first got the error. I didn't see any method to register. So now I looked even deeper and still could not find out how to register. I googled on how to register, nothing. I cannot be the only this has ever happened to. I also find it extremely odd that I cannot register, unless this repo is only for paying customers. If that is the case it's not really open source. Just putting the source out there with no way to build the actual binaries, while the source is open is absurd. So I know this cannot be a paid for sight that I need to register with just to build the source.
I looked through configuration files for where it might be referencing this site, I could not find it.
I thought, maybe the jars had built and it just could not push them to the site. That's fine I just need to jar files. However, I cannot find the jar files either.
By now I'm sure you surmised I'm not familiar with gradle, you would be correct. I can follow instructions on how to run it, but I have never used it n a project. I've used maven, ant, make and others.
If this error can be ignored, and I should look somewhere for the built jars, that would be the solution I'm looking for. If I need to register for the site in order to finish the build, then how do I do that?
The message about the build scan can be ignored. A build scan describes what happened during the build and isn’t needed to access the build’s output.
When you run build, each module’s jar is written to its build/libs directory. For example, you’ll find the jar for the spring-boot module in spring-boot-project/spring-boot/build/libs. Alternatively, you may want to run publishToMavenLocal. It will publish each module to your local Maven cache from where you can consume it in a Maven build, or a Gradle build configured with mavenLocal() as a repository.

IntelliJ Compilation Error zip END header not found

The Issue
I am unable to compile Java code for an imported Eclipse project on IntelliJ build 182.4505.22 on Java 9 and 10. The following error is displayed when compiling the module, or any individual file:
Error:(1, 1) java: cannot access edu.wit.cs.comp2000
zip END header not found
Details
The structure of the project is as follows:
The full compile-time output is as follows:
Already Attempted
I have reviewed posts here and here, which do not provide any relevant details.
I have attempted compiling on both Java 9 and 10, which makes no difference.
I have written a main method into LinkedBag and attempted to run that independent of JUnit, which results in the same error.
IntelliJ is not correctly displaying the testing icons in my test class, so I suspect that JUnit (or lack of JUnit) is the cause of the issue, however I am unsure how to proceed. Compiling works for other projects (without JUnit tests) just fine.
Updates
The code seems to compile and test as expected on Java 1.8 without issue. Switching to Java 9 or 10 causes the above issue every time. I am beginning to suspect that one of my instructor's dependencies requires Java 1.8 specifically, however I would still like to use newer versions of Java if anyone might have a solution.
As mentioned above, just delete the corrupted cache and restart Intellij.
Running gradle in the commandline can help knowing what you should delete. For instance:
$ ./gradlew --version
Could not unzip /home/cesarc/.gradle/wrapper/dists/gradle-5.6.2-all/9st6wgf78h16so49nn74lgtbb/gradle-5.6.2-all.zip to /home/cesarc/.gradle/wrapper/dists/gradle-5.6.2-all/9st6wgf78h16so49nn74lgtbb.
Reason: error in opening zip file
and after deleting the folder /home/cesarc/.gradle/wrapper/dists/gradle-5.6.2-all/9st6wgf78h16so49nn74lgtbb the problem was solved:
$ ./gradlew --version
Downloading https://services.gradle.org/distributions/gradle-5.6.2-all.zip
......
We had this issue when internet connection dropped while Idea was downloading project dependencies. We solved it by deleting the corrupted file from cache. Cache location depends on your build tool, e. g. for Maven it's in ~/.mvn, for Gradle it's in ~/.gradle.
In my case, it was: /.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.41/tomcat-embed-core-9.0.41.jar
I just removed it and I was able to compile my code.
Just pay attention to the .jar file in your case it's giving an error. Just remove it and you are good to go.
I Had Similar issue in my mac.I just deleted .m2 repository and did maven clean install again worked.
Instead of deleting your whole maven repository you can scan through it locally to find the bad jar file using GNU utils
find <maven-repository-dir> -type f -name "*.jar" -exec zip -T {} \; grep -v OK
I got this error
[ERROR] error reading /Users/username/.m2/repository/io/confluent/common-config/5.5.1/common-config-5.5.1.jar; zip END header not found
I don't know why the jar was corrupted but the error went away when I replaced the jar with my colleagues jar file. Fixing the error temporarily.
In my case, the gradle version of the project was 6.2.2 and the 6.4.1(system default gradle) path was provided in the Intellij gradle settings.
This issue appeared suddenly though. I was working on this project for a long time without any issues. I am not quite sure as to what triggered this issue. The gradle default version package was fine as the gradle build was fine from command line. :)
Referred to suggestions from here
Any one of the below solved the issue on my system:
Provide the path to project gradle version, in gradle settings.
or
Change the 'distributionUrl' value in your gradle-wrapper.properties to have 'all' instead of 'bin'. And also make sure you have gradle-wrapper.properties configured in your intellij gradle settings.
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip
This can also occurs when you use a dependency that requires to be of type pom (to transitively add all dependencies, useful for BOMs) but without specifying it.
For example if you have a Spring Boot project and use that starter :
<dependency>
<groupId>org.zkoss.zkspringboot</groupId>
<artifactId>zkspringboot-starter</artifactId>
<version>${zkspringboot.version}</version>
</dependency>
Then mvn clean package will give you the following error :
Error: java: cannot access com.example.myproject
And running the app will result in the following error :
java: error reading ...\.m2\repository\org\zkoss\zkspringboot\zkspringboot-starter\2.3.0\zkspringboot-starter-2.3.0.jar;
zip END header not found
because it should not perform any packaging.
Adding the pom packaging type fixes the problem, so that it keeps the artifact simply as a descriptor of dependency versions :
<dependency>
<groupId>org.zkoss.zkspringboot</groupId>
<artifactId>zkspringboot-starter</artifactId>
<version>${zkspringboot.version}</version>
<type>pom</type>
</dependency>
Tweak file watching settings did the trick for me.
For Ubuntu/Mac Run these 2 commands.
sudo echo "fs.inotify.max_user_watches = 524288" | sudo tee /etc/sysctl.d/40-idea.conf
sudo sysctl -p --system
I had a similar issue when I used the dependency thymeleaf-extras-springsecurity4 from org.thymeleaf.extras in a spring boot application.
Updating the dependency to the latest version helped.

Maven Issue SurefireReportParameters

I've been trying to build an app but when I run maven, I catch this exception:
java.lang.ClassNotFoundException: org.apache.maven.plugin.surefire.SurefireReportParameters
I installed the maven-plugin manually, but the issue still continues. Any suggestion will be appreciated.
There are a few things that you should check about this problem.
I will enumarate then here so you could check.
Check if you defined the JDK instead of the JRE on your path enviroment variables. Maven does not work properly only with the JRE. To check that go to your console and se if the javac -version command works.
Check if you have the M2_HOME variable defined on your enviroment variables with the path where you installed maven.
Since you are having a ClassNotFoundException on the SurefireReportParameters class check if the correspondent jar is on your local repository. It normally is on maven_path\repository\org\apache\maven\plugins\maven-surefire-plugin there it should have folder with versions and inside it a JAR file with the name: maven-surefire-plugin-x.xx.jar.
Sometimes it happens that JAR files get corrupted from outside events of the O.S. or the IDE leading to the ClassNotFoundException as it would be very difficult to find all corrupted JARs I usually recomend to redownload the entiry repository again. Note that depending on the size of your project and number of dependencies you have on it this operation will take some time to complete. In order to do that you go to your repository folder (e.g. c:\maven\repository) and rename it (just the repository folder e.g. c:\maven\repository_) or delete it (just repository folder) then go to your project and run mvn install
One of this options should solve your problem. And as we discussed on the comments we already know which one it was. ;)
There are solutions posted for a similar question, but in the context of the Spring Framework.
Spring Boot fails to run maven-surefire-plugin ClassNotFoundException org.apache.maven.surefire.booter.ForkedBooter
One answer is to use version 3.0.0-M1 of the maven-surefire-plugin.

Why can I not access all plugins in my target definition?

I have a problem concerning target definitions in Eclipse. I want to use plugin version 1.0.0, which is in my target platform definition, while I have the plugin project in my workspace with version 1.0.2. For all other plugins in my target definition, everything works as expected (which I see because an error gets flagged if something's missing), but this specific one, Eclipse does not make available to my projects. Only the plugin version 1.0.2 is. The plugin is not set as a singleton.
Why is this and how can I resolve this problem?
I figured out that I can access the right version when I close the project that contains the wrong one - but this is awkward, is there another way?
It seems that it's actually not an eclipse-specific problem, it fails also when building on the command line through maven/tycho. Specifically, my target platform is the Juno Release. Are there plugins that, while part of a feature, are not made available to other bundles? I know the plugin is there, but neither tycho nor Eclipse want to make it available to me.
Maybe I should also say it fails at compile time.
While, as I said, there exist workarounds for the problem, I still would like to have a "nice" solution to this problem. You can check out the project together with the target definition at https://github.com/kutschkem/Jayes
You may also need to check out and build this project first:
git clone http://git.eclipse.org/gitroot/recommenders/org.eclipse.recommenders.git
After setting the target platform, try building something with Jayes 1.0.0 (which is in the target platform) instead of Jayes 1.0.2 (which is in your workspace). You can also try to build with maven, it doesn't work as well.
Known workarounds:
Close the Jayes 1.0.2 project. Then, eclipse lets you use Jayes 1.0.0
For running an (OSGi) application, you can choose which bundles are loaded. You can choose version 1.0.0 manually there
Using a product definition, you can access the same runtime configuration as for workaround 2
If someone finds a workaround for maven, I'd be happy to know about it.
Maybe you have set your plugin to be singleton, so there will only be one instance for the bundle with a specific id.
You can change this by remove the "singleton:=true" in your MANIFEST.MF.
Bundle-SymbolicName: org.eclipse.xxx; singleton:=true
Or, you could remove the 1.0.2 version plugin from the run configuration when start running. click run --> run configuration to open the run configuration dialgo, switch to 'plugins' tab, here you can select which of these plugins you want to use .
I think you have already tried the following, but a reload of the target platform might help.
Also, what does your feature.xml file specify for version of that plugin?

Categories

Resources