Adding Apache common dependency to Play Framework 2.0 - java

i want to import org.apache.commons.io but i'm getting this error:
[info] Compiling 1 Java source to /home/ghost/Bureau/app/play-2.0.1/waf/target/scala-2.9.1/classes...
[error] /home/ghost/Bureau/app/play-2.0.1/waf/app/controllers/Application.java:9: error: package org.apache.commons.io does not exist
[error] import org.apache.commons.io.*;
[error] ^
[error] /home/ghost/Bureau/app/play-2.0.1/waf/app/controllers/Application.java:41: error: cannot find symbol
[error] FileUtils.copyFile(file, destinationFile);
[error] ^
[error] symbol: variable FileUtils
[error] location: class Application
[error] 2 errors
[error] {file:/home/ghost/Bureau/app/play-2.0.1/waf/}waf/compile:compile: javac returned nonzero exit code
[error] application -
Play can't find package org.apache.commons.io .
How can i add apache io as a dependency ?

To add the dependencies
Edit project Build.scala file : /project/Build.scala and add dependency for commons-io
val appDependencies = Seq(
// Add your project dependencies here,
"commons-io" % "commons-io" % "2.4"
)
using play console check dependency resolved or not use command: play dependencies
Tip: If you're not familiar with SBT syntax mvnrepository.com allows you to copy proper one in SBT tab: commons-io sample

Related

Compilation error of test scripts from Jenkins

Jenkins maven project shows [ERROR] COMPILATION ERROR after step
--- maven-compiler-plugin:3.8.1:testCompile (default-testCompile).
All selenium-elements are non-recognized. Also, there are rather strange slashes "/" instead of "\" in files paths.
If compilation starts through maven:surefire in IntelijIdea, such problems don't appear.
Here are links to Jenkins configure and pom.xml photos
[Jenkins conf1]https://prnt.sc/ox1wzb
[Jenkins conf2]https://prnt.sc/ox1yye
[pom1]https://prnt.sc/ox1xzg
[pom2]https://prnt.sc/ox2y21
What could be the mistake?
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Program Files (x86)/Jenkins/workspace/roz/src/test/java/script_1_2_3/WebDriverSettings.java:[5,27] package org.openqa.selenium does not exist
[ERROR] /C:/Program Files (x86)/Jenkins/workspace/roz/src/test/java/script_1_2_3/WebDriverSettings.java:[6,27] package org.openqa.selenium does not exist
[ERROR] /C:/Program Files (x86)/Jenkins/workspace/roz/src/test/java/script_1_2_3/WebDriverSettings.java:[7,34] package org.openqa.selenium.chrome does not exist
[ERROR] /C:/Program Files (x86)/Jenkins/workspace/roz/src/test/java/script_1_2_3/WebDriverSettings.java:[8,35] package org.openqa.selenium.support does not exist
[ERROR] /C:/Program Files (x86)/Jenkins/workspace/roz/src/test/java/script_1_2_3/WebDriverSettings.java:[9,38] package org.openqa.selenium.support.ui does not exist
[ERROR] /C:/Program Files (x86)/Jenkins/workspace/roz/src/test/java/script_1_2_3/WebDriverSettings.java:[13,19] cannot find symbol
symbol: class WebDriver
location: class script_1_2_3.WebDriverSettings
[ERROR] /C:/Program Files (x86)/Jenkins/workspace/roz/src/test/java/script_1_2_3/WebDriverSettings.java:[14,19] cannot find symbol
symbol: class WebDriverWait
location: class script_1_2_3.WebDriverSettings
[ERROR] /C:/Program Files (x86)/Jenkins/workspace/roz/src/test/java/script_1_2_3/PageObjects.java:[3,27] package org.openqa.selenium does not exist
[ERROR] /C:/Program Files (x86)/Jenkins/workspace/roz/src/test/java/script_1_2_3/PageObjects.java:[4,27] package org.openqa.selenium does not exist
[ERROR] /C:/Program Files (x86)/Jenkins/workspace/roz/src/test/java/script_1_2_3/PageObjects.java:[5,35] package org.openqa.selenium.support does not exist
[ERROR] /C:/Program Files (x86)/Jenkins/workspace/roz/src/test/java/script_1_2_3/PageObjects.java:[6,38] package org.openqa.selenium.support.ui does not exist
[ERROR] /C:/Program Files (x86)/Jenkins/workspace/roz/src/test/java/script_1_2_3/ListsOperating.java:[3,27] package org.openqa.selenium does not exist
[ERROR] /C:/Program Files (x86)/Jenkins/workspace/roz/src/test/java/script_1_2_3/PageObjects.java:[12,71] cannot find symbol
symbol: class WebElement
location: class script_1_2_3.PageObjects
[ERROR] /C:/Program Files (x86)/Jenkins/workspace/roz/src/test/java/script_1_2_3/PageObjects.java:[13,59] cannot find symbol
symbol: class WebElement
location: class script_1_2_3.PageObjects
[ERROR] /C:/Program Files (x86)/Jenkins/workspace/roz/src/test/java/script_1_2_3/PageObjects.java:[14,59] cannot find symbol
symbol: class WebElement
location: class script_1_2_3.PageObjects
[ERROR] /C:/Program Files (x86)/Jenkins/workspace/roz/src/test/java/script_1_2_3/PageObjects.java:[15,59] cannot find symbol
symbol: class WebElement
location: class script_1_2_3.PageObjects
[ERROR] /C:/Program Files (x86)/Jenkins/workspace/roz/src/test/java/script_1_2_3/PageObjects.java:[16,59] cannot find symbol
symbol: class WebElement
location: class script_1_2_3.PageObjects
[ERROR] /C:/Program Files (x86)/Jenkins/workspace/roz/src/test/java/script_1_2_3/PageObjects.java:[17,59] cannot find symbol
symbol: class WebElement
location: class script_1_2_3.PageObjects
[ERROR] /C:/Program Files (x86)/Jenkins/workspace/roz/src/test/java/script_1_2_3/PageObjects.java:[18,64] cannot find symbol
symbol: class WebElement
location: class script_1_2_3.PageObjects
The reason is what the Java compiler cannot find classes that you refer. None of libraries that you defined in pom.xml contains org.openqa.selenium. Add Selenium library.
Also, before compiling on Jenkins, why have you not compiled it locally? It would be much easier to first make it compiling and running locally, and only then put it to Jenkins.
You need to consider three below things to solve this issue:
Jenkins:
Once You have Jenkins install, make sure you install Maven Plugins from “Manage Jenkins  Manage Plugins”
Then add the Simple New Item, As Maven Project.
Keep everything as it is, Add POM details under Build section.
You can set the Goals and Options as: clean install or test as well.
Java:
Check the JAVA_HOME file version and add the JDK version accordingly everywhere.
Maven:
Make sure you are using the right version of JDK or JRE for the compilation. (Common error of compilation come here)
In eclipse, go to “Window  Preference  Java  Installed JRE  Apply the JRE from Execution Environments”
Add Maven Compilation Plugins into POM.XML. o Make sure you have correct version of JDK
Below is the sample format.

I am trying to run a maven compile on my project, I am getting this error message

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project codec-energy-phase3: Compilation failure: Compilation failure:
[ERROR] error reading C:\Users\ArEgOn\.m2\repository\com\hpe\iot\codec\0.0.1-SNAPSHOT\codec-0.0.1-SNAPSHOT.jar; invalid distance too far back
[ERROR] error reading C:\Users\ArEgOn\.m2\repository\log4j\log4j\1.2.17\log4j-1.2.17.jar; invalid LOC header (bad signature)
[ERROR] /E:/work/iot-codec/codec-energy-phase3/src/main/java/com/tcl/iot/codec/energy/phase3/encoder/base/BaseEncoder.java:[12,25] cannot access com.hpe.iot.codec.CodecException
[ERROR] bad class file: C:\Users\ArEgOn\.m2\repository\com\hpe\iot\codec\0.0.1-SNAPSHOT\codec-0.0.1-SNAPSHOT.jar(com/hpe/iot/codec/CodecException.class)
[ERROR] unable to access file: corrupted zip file
[ERROR] Please remove or make sure it appears in the correct subdirectory of the classpath.
[ERROR] /E:/work/iot-codec/codec-energy-phase3/src/main/java/com/tcl/iot/codec/energy/phase3/encoder/base/BaseEncoder.java:[25,56] cannot find symbol
[ERROR] symbol: class CodecException
[ERROR] location: class com.tcl.iot.codec.energy.phase3.encoder.base.BaseEncoder<T>
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project codec-energy-phase3: Compilation failure
I am getting the above error log when I am trying to compile my project using maven.
Can anyone please help me to figure out possible causes and solutions.

Cannot compile parquet-tools

I cloned the repository of parquet-mr from this link. The I wanted to build parquet-tools as explained here:
cd parquet-mr/parquet-tools/
mvn clean package -Plocal
(I updated pom.xml to point correct version of com.twitter:parquet-hadoop:jar)
This is the compilation error that I get:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /usr/local/parquet-mr-master/parquet-tools/src/main/java/org/apache/parquet/tools/command/MergeCommand.java:[76,13]
cannot find symbol symbol: method
appendFile(org.apache.hadoop.conf.Configuration,org.apache.hadoop.fs.Path)
location: variable writer of type
org.apache.parquet.hadoop.ParquetFileWriter
[ERROR]
/usr/local/parquet-mr-master/parquet-tools/src/main/java/org/apache/parquet/tools/command/MergeCommand.java:[82,29]
cannot find symbol symbol: method
mergeMetadataFiles(java.util.List,org.apache.hadoop.conf.Configuration)
location: class org.apache.parquet.hadoop.ParquetFileWriter
Try checking out a concrete tag in git first.
git checkout apache-parquet-1.9.0
cd parquet-mr/parquet-tools/
mvn clean package -Plocal
By doing the git checkout, all the pom.xml files will say <version>1.9.0</version> instead of <version>1.9.0-SNAPSHOT</version>.

dependencyClasspath error on Play! 2.2 as play.db.ebean cannot be found

I am running Play! 2.2 and want my models to extend play.db.ebean. I have one model called Event which extends play.db.ebean.Model. I get the following compilation errors when I try to generate Eclipse files (from the play command line) because the application cannot find the play.db.ebean package:
[info] About to create Eclipse project files for your project(s).
[info] Compiling 6 Scala sources and 7 Java sources to C:\Users\nickc\gatherme\target\scala-2.10\classes... error: cannot find symbol
[error] public abstract class Event_ extends play.db.ebean.Model_ {
[error] symbol: class Model_
[error] location: package play.db.ebean
[error] 1 error
[error] Could not create Eclipse project files:
[error] Error evaluating task 'dependencyClasspath': error
I have the following in my build.sbt file:
import play.Project._
name := "forms"
version := "1.0"
val appDependencies ++= Seq(
javaEbean,
jdbc
)
playJavaSettings
This is as suggested here and in the Zentasks sample project. I am guessing that my build.sbt file must be wrong? Or not getting picked up?
Any suggestions would be greatly appreciated!
Thank you,
Nick

playframework - package javax.persistence does not exist

I have Issue with using database
I was going with this tutorial
http://vimeo.com/58969923# (one from playframework.com page)
in the model:
play-2.2.1/jcirs/app/models/MedicalIncident.java
public class MedicalIncident extends Model{}
I am trying to use Entity. For that I have to import:
javax.persistence.* and play.db.ebean.*
but none of them can be found.
The error is
package javax.persistence does not exist
What should I do?
Use any other database engine? Or should download some dependency.
I would like to go with playframework best way.
Please help.
My configuration
application.conf:
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
ebean.default="models.*"
stack trace:
[jcirs] $ run 8081
--- (Running the application from SBT, auto-reloading is enabled) ---
[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:8081
(Server started, use Ctrl+D to stop and go back to the console...)
[info] Compiling 5 Scala sources and 5 Java sources to /home/daniel/play-2.2.1/jcirs/target/scala-2.10/classes...
[error] /home/daniel/play-2.2.1/jcirs/app/models/MedicalIncident.java:4: error: package javax.persistence does not exist
[error] import javax.persistence.*;
[error] ^
[error] /home/daniel/play-2.2.1/jcirs/app/models/MedicalIncident.java:6: error: package play.db.ebean does not exist
[error] import play.db.ebean.*;
[error] ^
[error] /home/daniel/play-2.2.1/jcirs/app/models/MedicalIncident.java:14: error: cannot find symbol
[error] public class MedicalIncident extends Model {
[error] ^
[error] symbol: class Model
[error] /home/daniel/play-2.2.1/jcirs/app/models/MedicalIncident.java:13: error: cannot find symbol
[error] #Entity
[error] ^
[error] symbol: class Entity
[error] /home/daniel/play-2.2.1/jcirs/app/models/MedicalIncident.java:15: error: cannot find symbol
[error] #id
[error] ^
[error] symbol: class id
[error] location: class MedicalIncident
[error] /home/daniel/play-2.2.1/jcirs/app/controllers/MedicalIncident.java:21: error: cannot find symbol
[error] MedicalIncident medical_incident = Form.form(MedicalIncident.class).bindFormRequest().get();
[error] ^
[error] symbol: variable Form
[error] location: class MedicalIncident
[error] 6 errors
[error] (compile:compile) javac returned nonzero exit code
[error] application -
! #6gfjpj0cf - Internal server error, for (GET) [/] ->
play.PlayExceptions$CompilationException: Compilation error[error: package javax.persistence does not exist]
at play.PlayReloader$$anon$1$$anonfun$reload$2$$anonfun$apply$14$$anonfun$apply$16.apply(PlayReloader.scala:304) ~[na:na]
at play.PlayReloader$$anon$1$$anonfun$reload$2$$anonfun$apply$14$$anonfun$apply$16.apply(PlayReloader.scala:304) ~[na:na]
at scala.Option.map(Option.scala:145) ~[scala-library.jar:na]
at play.PlayReloader$$anon$1$$anonfun$reload$2$$anonfun$apply$14.apply(PlayReloader.scala:304) ~[na:na]
at play.PlayReloader$$anon$1$$anonfun$reload$2$$anonfun$apply$14.apply(PlayReloader.scala:298) ~[na:na]
at scala.Option.map(Option.scala:145) ~[scala-library.jar:na]
[warn] play - No application found at invoker init
Have you updated your project dependencies in Build.scala?
Not sure if anything has changed in Play 2.2.1 but for Play 2.1.3 dependencies in Build.scala would look like this:
val appDependencies = Seq(
javaCore,
javaJdbc,
javaEbean
)
EDIT:
Once you update your dependencies in Build.scala don't forget to update dependencies in your IDEA or Eclipse by running corresponding play command, e.g.
play idea
Playframework is generating the IDEA specific files when you run "play idea" (if you're using Eclipse, run "play eclipse"). If you imported the project in the same way the tutorial explained, you should have the necessary JARs already available in the project.
If it's still not working, verify if IDEA correctly assigned a JDK to your project.
Try to understand what this framework is doing under the hood, don't just try to make it work and ignore the important stuff.
I had the same problem and I was using Eclipse. I included #Entity, e.g. and in my project console I typed eclipse with-source=true. After a "Refresh" in my Eclipse project and a "Clean", it brings me all JARs and then I clicked on the issue and the IDE offered the possibility to include javax.persistence.*, play.db.ebean.Model, etc.
I was having the same problem, while using a heavily modified version of Eclipse Neon. The clue to solving it for me, was that the only place I was seeing the errors was during a Maven build. The Eclipse IDE was able to compile and run the program just fine.I was able to solve it by adding a couple of dependencies to the project's pom.xml file. See below for the xml code for the dependencies.I was able to get the groupId's and artifactId's versions by drilling down the directories out on Maven Central. I just walked the tree until I found the metadata.xml files for the persistence.core and the persistence.jpa artifacts.
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.core</artifactId>
<version>2.6.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.6.4</version>
<scope>compile</scope>
</dependency>

Categories