I have a JavaScript project in Netbeans with the following file structure:
src/main/javascript
src/main/resources (containing my index.html)
src/main/webapp
Doing the mvn build, the target folder contains my "project" folder with my index.html and the javascript files.
When I edit a JavaScript file or my index.html in the src folder, I want jetty to recognize this (I thought this is the idea of the jetty scanner). But this is not the case.
Here my jetty plugin configuration in the POM:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.4.2.v20110526</version>
<configuration>
<scanTargets>
<scanTarget>${basedir}/src/main/resources/</scanTarget>
<scanTarget>${basedir}/src/main/javascript/</scanTarget>
</scanTargets>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
<classesDirectory>${project.build.directory}/project/</classesDirectory>
<webAppConfig>
<contextPath>/</contextPath>
<resourceBases>
<resourceBase>${project.build.directory}/project/</resourceBase>
<resourceBase>${project.build.directory}/project/</resourceBase>
</resourceBases>
</webAppConfig>
</configuration>
</plugin>
Can someone tell me why changes are not "scanned"?
Related
Help me, please. I don't know why missing only javascript static code analyze riports.
So, I have a maven project with multiple modules and the javascript codes in the frontend project.
SonarJS plugin installed
i'm running: mvn clean install sonar:sonar
i have configure sonar from pom.xml instead of sonar-project.properties
sonar version: 6.7 community edition
In the sonar overview it has java static code analyze riport both of modules, but nothin about javascript codes.
Here is my pom.xml settings in the parent project.
<?xml version="1.0" encoding="UTF-8"?>
<project ... >
...
<version>0.0.1-SNAPSHOT</version>
<modules>
<module>backend</module>
<module>frontend</module>
</modules>
<properties>
...
<!-- sonar -->
<sonar.version>3.4.0.905</sonar.version>
<sonar.host.url>http://my.sonar.domain.url</sonar.host.url>
<sonar.login>asdsd43f8g7fs498u9s8df7s97zf9er97zf7</sonar.login>
<sonar.javascript.file.suffixes>.js,.jsx,.vue</sonar.javascript.file.suffixes>
<sonar.sources>src/main/</sonar.sources>
<sonar.test>src/test/</sonar.test>
<sonar.jacoco.itReportPath>${project.testresult.directory}/coverage/jacoco/jacoco-it.exec</sonar.jacoco.itReportPath>
<sonar.jacoco.reportPath>${project.testresult.directory}/coverage/jacoco/jacoco.exec</sonar.jacoco.reportPath>
<sonar.java.codeCoveragePlugin>jacoco</sonar.java.codeCoveragePlugin>
<!-- For Java -->
<sonar.junit.reportsPath>reports/java/surefire-reports</sonar.junit.reportsPath>
<!-- For JavaScript -->
<sonar.javascript.lcov.reportPath>reports/js/lcov.dat</sonar.javascript.lcov.reportPath>
...
</properties>
<dependencies> ... </dependencies>
<build>
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>${sonar.version}</version>
<executions>
<execution>
<id>sonar-run</id>
<phase>verify</phase>
<goals>
<goal>sonar</goal>
</goals>
</execution>
</executions>
</plugin>
....
</plugins>
</pluginManagement>
</build>
</project>
UPDATE:
I have run sonar analyze with -X debug. The logs below:
[DEBUG] 15:08:27.144 'src/main/resources/static/js/template/template.js' excluded by org.sonar.plugins.javascript.JavaScriptExclusionsFileFilter
[DEBUG] 15:08:27.145 'src/main/resources/static/js/navigation/navigationEvents.js' excluded by org.sonar.plugins.javascript.JavaScriptExclusionsFileFilter
[DEBUG] 15:08:27.145 'src/main/resources/static/js/navigation/navigation.js' excluded by org.sonar.plugins.javascript.JavaScriptExclusionsFileFilter
[DEBUG] 15:08:27.145 'src/main/resources/static/js/navigation/moduleLoader.js' excluded by org.sonar.plugins.javascript.JavaScriptExclusionsFileFilter
But doesn't have any exculde settings.
You wrote in the comment that:
sonar.javascript.exclusions=**/node_modules/**,**/bower_components/**,**/js/**
If you didn't specify it in any pom.xml file, then that value is taken from the server. You can see the configuration by opening: https://sonar.host/admin/settings?category=javascript or Administration → Configuration → JavaSctript. Next you have to find the JavaScript Exclusions section:
Probably you will also see **/js/**. From my point of view you should delete that entry because it has no sense. If you cannot then you have to overwrite the default value by adding:
<sonar.javascript.exclusions>**/node_modules/**,**/bower_components/**</sonar.javascript.exclusions>
or
<sonar.javascript.exclusions></sonar.javascript.exclusions>
In pom of maven module containing JS code, set sonar.sources (and tests if you want) of your JS code
I'd say that first you want to try to execute coverage with sonar.properties file just to figure out - which keys you are still missing, preferably for js exclusively. Also, correct setting may depend on actual Sonar version that you are using.
One thing I see is that you have sonar.lcov.javascript.reportPath twice. Which one is the correct one (to start with use the hardcoded path, to make sure, you are getting the reports)
Secondly,in my project file I also had to specify the plugin to use (something like sonar.js.coveragePlugin = lcov ). Pehaps that you also want to add, since you are using lcov.
Finally, I also have the following flag set:
sonar.dynamicAnalysis=reuseReports
That was needed to reuse the reports that were generated during the build.
On a side note, my configuration was created a 3 years back, for sonar version that was latest back then. There might have been some changes with the new releases of Sonar.
I am trying to minify all my css and js files. Then I want to have them in the final war file. I dont want to change the file names ie i want only content should be minified of each file and should go to the war file.
This is my pom.xml
<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.7.2</version>
<executions>
<execution>
<id>minify</id>
<phase>package</phase>
<goals>
<goal>minify</goal>
</goals>
<configuration>
<charset>utf-8</charset>
<jsEngine>CLOSURE</jsEngine>
<closureCompilationLevel>WHITESPACE_ONLY</closureCompilationLevel>
<nosuffix>true</nosuffix>
<skipMerge>true</skipMerge>
<verbose>true</verbose>
<cssSourceDir>/ui/css</cssSourceDir>
<cssTargetDir>/ui/css</cssTargetDir>
<cssSourceIncludes>
<cssSourceInclude>*.css</cssSourceInclude>
</cssSourceIncludes>
<jsSourceDir>/ui/js</jsSourceDir>
<jsTargetDir>/ui/js</jsTargetDir>
<jsSourceIncludes>
<jsSourceInclude>*.js</jsSourceInclude>
</jsSourceIncludes>
</configuration>
</execution>
</executions>
</plugin>
Here the packaging of war file is happening first and then the minification happening.
This is output in command line after running pom file
[INFO] --- maven-war-plugin:2.2:war (default-war) # ProductActivationServer ---
[INFO] Packaging webapp
[INFO] Assembling webapp [ProductActivationServer] in [C:\ProductActivationServerUI\pas\ProductActivationServer\target\pas]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\ProductActivationServerUI\pas\ProductActivationServer\src\main\webapp]
[INFO] Webapp assembled in [13993 msecs]
[INFO] Building war: C:\ProductActivationServerUI\pas\ProductActivationServer\target\pas.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO]
[INFO] --- minify-maven-plugin:1.7.2:minify (minify) # ProductActivationServer ---
[INFO] Starting CSS task:
[INFO] Skipping the merge step...
[INFO] Creating the minified file [C:\ProductActivationServerUI\pas\ProductActivationServer\target\pas\ui\css\BreadCrumb.css].
So in final war original content there but not minified.
Please help. I am using mvn , struts web app.
I am trying to minify all my css and js files. Then I want to have them in the final war file. I dont want to change the file names ie i want only content should be minified of each file and should go to the war file.
When both the options nosuffix and skipMerge are set to true, the plugin execution phase needs to be set to package, otherwise the output files will be overridden by the source files during the packaging.
You also need to exclude source files from WAR package.
I'd like to disable the Javascript Facet (and remove the Javascript builder) from a Maven-driven Eclipse project.
Is there any way I can configure the maven-eclipse-plugin to do so?
First of all, clean the configuration with mvn eclipse:clean, it will remove all configuration from the .project file.
Then make a new one with mvn eclipse:eclipse, just with the configuration and dependencies on your pom.xml.
EDIT:
And configure the project natures that you need:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<projectnatures>
<projectnature>org.eclipse.jdt.core.javanature</projectnature>
<projectnature>org.eclipse.wst.common.modulecore.ModuleCoreNature</projectnature>
</projectnatures>
<additionalProjectnatures>
[... the ones you need or empty...]
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
</configuration>
</plugin>
I am trying to create a war file that will be deployed on a web/application server.
The source files of the app are purely HTML, CSS, and JavaScript. There is a separate war file for our REST API and for the rest of our backend code.
Most of the guides out there talk about using java to compile, and pointing to WEB-INF folders etc.
However, as I mentioned, in the HTML/CSS/JS war, I don't use any Java, don't use WEB-INF, and there are no servlets or other things you would normally see in a "Java" war file.
How do I compile or create this type of war file?
The contents look like this:
WebContent/HTML
WebContent/CSS
WebContent/JS
All libraries for JavaScript contained within JS folder.
Would this work: Simply run:
src.dist="./WebContent"
app.name="example"
app.version=1
work.home="./temp"
jar jarfile="${src.dist}/${app.name}-${app.version}.war"
basedir="${work.home}"
Obviously I would have set up the rest of the script correctly.
This is extremely simple:
Create a folder
Add a src/main/webapp folder
Add all of your HTML, CSS and JS files to the src/main/webapp folder
Add an empty web.xml file to the src/main/webapp/WEB-INF directory.
add a maven pom.xml
add the maven-war-plugin to your pom.xml, with the following configuration:
<!-- create the war -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
run mvn clean install!
If you are creating a war file, then you are deploying on a Java based web application server, something like Tomcat or Wildfly.
If you are using eclipse, you can do so by New > Dynamic Web Project (maybe name it foo-bar), click next, next and finish. Then open that foo-bar project and create your css and js folders under WebContent like so.
\WebContent\css
\WebContent\js
\WebContent\index.html
\WebContent\foo-bar.html
You can right click the foo-bar project > Export > Web WAR file.
When you deploy it on say Tomcat, you can test to access your static content like so
http://localhost:8080/foo-bar/css/foo-bar.css
http://localhost:8080/foo-bar/js/foo-bar.js
http://localhost:8080/foo-bar/foo-bar.html
Hope this helps.
Can I setup Maven YUI Compressor for compression files after aggregation, because I want to exclude "sources" directory, which contain files for aggregation and then compress aggregated files.
For example I have some .js-files inside of /js/sources/mylib/ and all this files merged into one file /js/mylib.js while yui-compressor aggregation stage. In pom.xml I configure yui-compressor to exclude whole /js/sources/ and compress files only within /js library, but yui-compressor execute "compress" goal before aggregation, so I have uncompressed merged files. And I need to fix this somehow
Can we turn it around and say: Aggregate after compression? If so, I had the same issue and with the following it worked out for me.
The trick seemed to be to put the output file in the target dir instead of in the source. That way you can include files that got minified in the aggregation.
Files that were already minified I then approach through the basedir var.
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<excludes>
<exclude>**/*-min.js</exclude>
<exclude>**/*.min.js</exclude>
<exclude>**/*.css</exclude>
</excludes>
<removeIncluded>false</removeIncluded>
<jswarn>false</jswarn>
<aggregations>
<aggregation>
<insertNewLine>true</insertNewLine>
<removeIncluded>false</removeIncluded>
<includes>
<!-- these exist only in target dir. the original was json2.js & bootstrap.tabs.js -->
<include>**/bootstrap-tabs-min.js</include>
<include>**/json2-min.js</include>
<!-- use originals for the ones already minified -->
<include>${basedir}/src/main/webapp/js/backbone-min.js</include>
</includes>
<output>${project.build.directory}/${project.build.finalName}/js/test.js</output>
</aggregation>
</aggregations>
</configuration>