I'm using Play 2.4 (Java version) but I'm also interested in solutions for >2.4. This is my problem. I want to structure the content of my template folder under app/views. So I'd like to create some sub packages under app/views but get compilation errors. Here is, what I've tried so far:
Create new subpackage via eclipse
app/views/mediaViewers
Put a template standardViewer.scala.html in it
app/views/mediaViewers/standardViewer.scala.html
Try to access the template from controller class via
views.mediaViewers.html.standardViewer.render()
Rebuild play project
activator clean; activator clean-files; activator run
When calling the appropriate route I get:
[error] .../Viewers.java:18: package views.mediaViewers.html does not exist
[error] views.mediaViewers.html.standardViewer
[error] ..../Viewers.java:21: package views.mediaViewers.html does not exist
[error] views.mediaViewers.html.standardViewer
[error] .../app/controllers/Viewers.java:24: package views.mediaViewers.html does not exist
...
[error] (compile:compileIncremental) javac returned nonzero exit code
[error] application -
! #765kicfe1 - Internal server error, for (GET) [/] ->
play.sbt.PlayExceptions$CompilationException: Compilation error[package views.mediaViewers.html does not exist]
...
In order to call a view template from the controller you should alwayes prefix the name of the view with "views.html", so the call to standardViewer.scala.html would be :
views.html.mediaViewers.standardViewer
you can verify this if you took a look at the generated files under target/scala-/twirl as indicated in this picture :
project structure
The package path in the controller is wrong! Use this pattern:
`views.html.your-package-goes-here.your-template-goes-here.render()`
Or more concrete:
Try to access the template from controller class via
views.mediaViewers.html.standardViewer.render()
Has to be:
views.html.mediaViewers.standardViewer.render()
Related
I'm trying to get the flash data that has been passed from the controller in the view. In the Play documentation (https://www.playframework.com/documentation/2.8.x/JavaSessionFlash) it says the flash can be get like this:
#flash.get("success").orElse("Welcome!")
However, I'm getting this error when I try to compile the project
[error] .../edit.scala.html:4:3: not found: value flash
[error] #flash.get("test").orElse("No flash!")
[error] ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
I've also tried using #request.flash and it gave the same error.
How can I get the flash or request in the view for Play Framework 2.8. Am I missing some import or something like that?
Since you're using Java you need to pass the request param to the template. At the top of the template file:
#( ... your normal params ...)(implicit request: Http.Request)
Now to get the flash use the request:
#request.flash().getOptional("test")
I'm getting a dependency issue with a jar I'm attempting to use.
I receive the following error
remote: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project sparq: Compilation failure: Compilation failure:
remote: [ERROR] /var/lib/openshift/55846322500446673d000007/app-root/runtime/repo/src/main/java/ServerQuery.java:[3,0] error: package com.github.koraktor.steamcondenser does not exist
remote: [ERROR] /var/lib/openshift/55846322500446673d000007/app-root/runtime/repo/src/main/java/ServerQuery.java:[8,8] error: cannot find symbol
remote: [ERROR] class ServerQuery
remote: [ERROR] /var/lib/openshift/55846322500446673d000007/app-root/runtime/repo/src/main/java/ServerQuery.java:[8,34] error: cannot find symbol
Here is the offending java file.
package helpers;
import com.github.koraktor.steamcondenser.*;
public class ServerQuery {
public static String getPlayers() {
SourceServer server = new SourceServer("66.150.155.152",27015);
server.initialize();
return server.toString();
}
}
I've added the following dependency to my pom.xml
<dependency>
<groupId>com.github.koraktor</groupId>
<artifactId>steam-condenser</artifactId>
<version>1.3.9</version>
</dependency>
I've also added the following action_hook pre_build script
mvn install:install-file -Dfile=./app-root/repo/steam-condenser.jar -DgroupId=com.github.koraktor -DartifactId=steam-condenser -Dversion=1.3.9 -Dpackaging=jar
Here's the GitHub for the project
https://github.com/koraktor/steam-condenser-java
And the website for it
http://koraktor.de/steam-condenser/usage/
Any ideas? Completely lost. Help much appreciated.
Since you are including the jar file in your project already, trying to manage the dependency with Maven seems like overkill. You should be able to put the jar file in your project's lib directory like this article describes. Then you won't need to configure that dependency in Maven at all.
I would use Maven for any dependencies that you want to download at the time your application is being built. Any jar files that you are checking into your project shouldn't need to be configured in Maven.
Just by looking at the question and the excerpts provided, I believe you are struggling with the basics of Maven. If I understand the situation correctly you have a library (which is not written by you):
once added to your project as a Maven dependency. This seems reasonable if you want to use it.
once the source code of the library incorrectly added to your own Java project.
remote: [ERROR] /var/lib/openshift/55846322500446673d000007/app-root/runtime/repo/src/main/java/ServerQuery.java:[3,0] error: package com.github.koraktor.steamcondenser does not exist
Based on the errormessage above it seems you have copied one of the sourcefiles from the library into your project. This is now causing problems. The main one is that without your source-folder (src/main/java) correctly representing the package structure declared in the source file (com.github...) it cannot be compiled. Hence the errormessage:
package com.github.koraktor.steamcondenser does not exist.
First of all you need to remove this copy-pasted file entirely an just use the dependency-management feature of Maven to get the library on classpath. After that just follow the examples given by the author of the library using the link you have already found (http://koraktor.de/steam-condenser/usage/).
I have a little problem in Eclipse with a package . The error output is Package (name of package ) does not exist .
I have a package called de.baimos.blueid.lockserver.demo.exec . But Eclipse is looking for a package called de.baimos.blueid.lockserver.api.exec . This package is can be found in my Project nowhere .
My current situation is this: I have two projects that work as a project. Now you can in Eclipse under Properties - Add a project to a different > Project -> Java Build Path . But if I want to run Maven install I get the error above. At first I thought it would be in the pom.xml file . But I noticed that it is not possible to merge two pom.xml files. My project was to make the inheritance , however, by themselves , whom I put them together leads . Did anyone of you ever such a problem , or can someone help me ?
Thanks in advance for your help .
That is the error:
[ERROR] /home/test/workspace/HeartbeatService/src/main/java/de/baimos/blueid/lockserver/demo/exec/DemoCommandExecutionEventListener.java:[3,44] error: package de.baimos.blueid.lockserver.api.event does not exist
[ERROR] /home/test/workspace/HeartbeatService/src/main/java/de/baimos/blueid/lockserver/demo/exec/DemoCommandExecutionEventListener.java:[4,44] error: package de.baimos.blueid.lockserver.api.event does not exist
[ERROR] /home/test/workspace/HeartbeatService/src/main/java/de/baimos/blueid/lockserver/demo/exec/DemoCommandExecutionEventListener.java:[5,44] error: package de.baimos.blueid.lockserver.api.event does not exist
[ERROR] /home/test/workspace/HeartbeatService/src/main/java/de/baimos/blueid/lockserver/demo/exec/DemoCommandExecutionEventListener.java:[6,44] error: package de.baimos.blueid.lockserver.api.event does not exist
[ERROR] /home/test/workspace/HeartbeatService/src/main/java/de/baimos/blueid/lockserver/demo/exec/DemoCommandExecutionEventListener.java:[8,59] error: cannot find symbol
Maven can't see what you specify in Eclipse's Java Build Path; it's a command line tool that runs outside / without Eclipse.
Instead, you have to do mvn install in the first project.
Then you can add a dependency to this project in the second project's POM.
Maven will then make sure that Eclipse add the first project to the classpath as well without manually changing the build path in the UI.
I have a little application which is working fine when testing is on localhost.
But when I want to deploy it to google app engine server, I have thoses errors :
Compiling module org.magnetik.semola.Org_magnetik
Validating newly compiled units
Ignored 1 unit with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
Finding entry point classes
[ERROR] Errors in 'file:/C:/Users/magnetik/git/semola-rdf/org.magnetik/src/org/magnetik/semola/client/RDFServlet.java'
[ERROR] Line 13: No source code is available for type javax.servlet.http.HttpServlet; did you forget to inherit a required module?
[ERROR] Line 16: No source code is available for type javax.servlet.http.HttpServletRequest; did you forget to inherit a required module?
[ERROR] Line 16: No source code is available for type javax.servlet.http.HttpServletResponse; did you forget to inherit a required module?
[ERROR] Line 25: No source code is available for type com.hp.hpl.jena.rdf.model.Model; did you forget to inherit a required module?
[ERROR] Line 25: No source code is available for type com.hp.hpl.jena.rdf.model.ModelFactory; did you forget to inherit a required module?
[ERROR] Line 37: No source code is available for type java.io.ByteArrayInputStream; did you forget to inherit a required module?
[ERROR] Unable to find type 'org.magnetik.semola.client.RDFServlet'
[ERROR] Hint: Previous compiler errors may have made this type unavailable
[ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
Usefull files (I think) are here : http://pastebin.com/zuELG18u
Does your project use GWT for the client side? Your deployment is failing when it is trying to do a special GWT compliation step.
I believe your problem is that your RDFServlet class is part of a GWT module, which is not what you are intending.
The default Eclipse project for GAE comes preconfigured to work with GWT. The package is structure in the example is like this:
client/ <--- GWT code (for client side, compiled to JavaScript)
shared/ <--- Code necessary on both the client and server
server/ <--- Server side code
When GWT compiles client/ down to JavaScript, it needs the full source of all its dependencies, and there are many classes that should not be referenced. However, it seems that you have a servlet (RDFServlet) in the "client" package.
You probably want to either disable GWT in your project, or move RDFServlet into a package that is not part of a GWT module. (For example, if you are using the Eclipse sample project, Servlets would be put somewhere under the 'server' package.
I have an external JAR signpost-core-1.2.1.1.jar (from http://code.google.com/p/oauth-signpost/), that I want to include into my Java GWT project.
So I add this external JAR file to my build path in Eclipse and put theese imports to my Class:
import oauth.signpost.basic.DefaultOAuthConsumer;
import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
While compiling I got theese error messages:
[ERROR] Line 130: No source code is available for type oauth.signpost.basic.DefaultOAuthConsumer; did you forget to inherit a required module?
[ERROR] Line 133: No source code is available for type oauth.signpost.exception.OAuthMessageSignerException; did you forget to inherit a required module?
[ERROR] Line 135: No source code is available for type oauth.signpost.exception.OAuthExpectationFailedException; did you forget to inherit a required module?
[ERROR] Line 137: No source code is available for type oauth.signpost.exception.OAuthCommunicationException; did you forget to inherit a required module?
So I put the following line in my Admin.gwt.xml file:
<inherits name='oauth.signpost.Signpost' />
And now I'm getting this message:
Loading inherited module 'oauth.signpost.Signpost'
[ERROR] Unable to find 'oauth/signpost/Signpost.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
Unfortunately the Signpost does not seam provide a gwt.xml file, since it consists only of a jar file.
So how can I write it?
And where do I have to place it?
Or do I just need to set some additional paths?
I don't know Signpost library but I suppose that you want to use it in your client side. Unfortunately oauth-signpost is only provided for traditional web services. Anyway if you want to use it, its possible only on server side where you have full support of jre 6. On client side you can use only provided gwt modules that use only emulated gwt-jre environment.