Is there an Eclipse plugin or feature that allows previewing of JSP files? Ideally such a feature would be aware of Spring tags. It's a major pain to edit the JSP in Eclipse, then build and deploy to see the results.
I haven't seen any good plugin which will satisfy your requirement.
As an alternative you can put the jetty server's jar to your class path (I am using jetty-6.1.5.jar and jetty-util-6.1.5.jar) and write a class like the following.
package net.eduportal.jetty;
import javax.servlet.ServletContext;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.security.UserRealm;
import org.mortbay.jetty.webapp.WebAppContext;
public class JettyRunner {
public static final int PORT = 8080;
public static final String BASE_URL = "http://localhost:" + PORT;
private static final JettyRunner _instance = new JettyRunner();
public static JettyRunner getInstance() {
return _instance;
}
// ///////////////////////////////////////////////////////////////
// Singleton
// /////////////
private Server server = null;
private WebAppContext wac = null;
private JettyRunner() {
}
public interface WebApplicationInitializer {
public void init(WebAppContext wac);
}
public ServletContext getServletContext() {
return wac.getServletContext();
}
public void start() throws Exception {
if (server == null) {
server = new Server(PORT);
server.setStopAtShutdown(true);
wac = new WebAppContext();
wac.setContextPath("/test");
wac.setResourceBase("war");
wac.setClassLoader(this.getClass().getClassLoader());
server.addHandler(wac);
server.start();
}
}
public void stop() throws Exception {
if (server != null) {
server.stop();
server = null;
}
}
public static void main(String argv[]) throws Exception {
JettyRunner.getInstance().start();
}
}
The above code assumes there is a folder called "war" in the class path which contains the same WEB-INF/* folders. When you run the code from eclipse the server will start and you can view the jsps by accessing the location localhost:8080/test/*
See http://jetty.mortbay.org/jetty5/tut/Server.html
You shouldn't have to rebuild at all to see the results.
The latest Enterprise version of eclipse actually does hot code replacement of JSPs. I add the web project to Tomcat (or Glassfish or JBoss...) and any change I make in a JSP is reflected after I refresh my browser window. Obviously, when I change a Java file, I need to restart Tomcat, but that only takes 2 seconds at most.
MyEclipse provides this plugin:
http://www.myeclipseide.com/module-htmlpages-display-pid-11.html
As to whether it will be Spring tag aware is another matter though...
JBoss Tools (http://jboss.org/tools) has a visual page editor that supports JSP, HTML and even JSF.
If a tag is not supported you can right click it and add a template for it OR you can extend the supported tags by implementing the extension points.
Examples of users extending the set of supported tags are http://relation.to/Bloggers/HowToCreateAVisualDocBookEditorIn10Minutes and http://planetjbpm.wordpress.com/2009/02/25/xforms-editor-with-jboss-vpe-and-some-jbpm/
There's the Oracle Workshop for WebLogic 10g R3 which gives you the closest thing to WYSIWYG JSP editing. Despite the fact that it comes from Oracle/BEA, it works with many app servers, not just WebLogic. It is the best tool I know for JSPs and it's free. I don't about Spring tags, but it can be customized to give design time representation of tags. I'm not sure if they support Eclipse 3.4 though.
There's also JBoss Developer Studio which has good JSP visual tools.
Related
I want to change the favicon of the website in Vaadin that is combined with Springboot. I have also opted to go the pure Java route within Vaadin (no html page).
I followed this guide, which explains that the icon I wish to use should be added in the src/main/webapp/icons folder where it will be automatically picked up, resized, etc.
I tried that to no avail, after which I found this thread and subsequently this one. The latter link especially explains that Spring-boot has its own directories and that the webapp folder should be avoided. I tried using the spring directories, but again to no avail.
My resources folder currently looks as such:
My MainView as such:
#Route
#PageTitle("My new title")
public class MainView extends VerticalLayout {
And my SpringBootApplication class as such:
#SpringBootApplication
public class MyVaadinApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(MyVaadinApplication.class, args);
}
}
The icon still remains the default spring leaf:
Where am I going wrong in trying to set the favicon?
Add icon.png to resources/META-INF/resources/icons/icon.png
Then:
If you are use progressive web app (#PWA annotation) it should already work
If you are use simple vaadin application you should to implements PageConfiguration and add link to your favicon.
#Route("favicon")
public class FaviconTest extends Div implements PageConfigurator {
#Override
public void configurePage(InitialPageSettings settings) {
HashMap<String, String> attributes = new HashMap<>();
attributes.put("rel", "shortcut icon");
attributes.put("type", "image/png");
settings.addLink("icons/icon.png", attributes);
}
}
Hi I am working on a Maven project having dependency on a external jar which has a class ConfigLoader having following loader() method.
public class ConfigLoader {
public void initialize() {
loader();
}
private static void loader() {
URL configURL = ConfigLoader.getClass().getResource("runtimeConfiguration.xml");
//some other method calls to which configURL is an argument.
}
//other methods of ConfigLoader class
}
and the directory structure is like this -
src
|...main
|.......java
|.......resources
|................dev
|................prod
both dev and prod have a file named runtimeConfiguration.xml
and the code which uses this class is
public class Application {
private Application application;
public static void main(String []args){
application = new Application();
application.invokeConfigLoader();
//additional code
}
private void invokeConfigLoader() {
configLoader.initialize();
}
}
The error I get is
could not find: runtimeConfiguration.xml
and the exception is thrown at the getResource() line in the class from jar.
I have tried adding the dev folder to classpath but still the same error. I want to run this code from linux terminal, and the command I am giving from trunk directory (where all my exernal jars and resource folder sits after maven build) is -
java -cp /resources/dev/*:configuration-loader.jar
I am using intelliJ 2017.2 and also tried to add the resources/dev folder as module dependency, but I keep on getting the same error. The resources folder is added as a library via project structure settings. I tried to search a lot but have not found any question with this issue. Kindly help me out as I am new to this environment based development.
Thanks!
ConfigLoader.getClass().getResource("runtimeConfiguration.xml"); will try to get runtimeConfiguration.xml from the same package a the ConfigLoader is defined and not from the root of classpath. Try appending / to runtimeConfiguration.xml.
This should work ConfigLoader.getClass().getResource("/runtimeConfiguration.xml"); or ConfigLoader.getClass().getResource("/dev/runtimeConfiguration.xml"); depending how you are adding resources to your classpath.
See javadoc for more.
I am trying to find if it is possible to use togglz in non web application - like we have plain java project or java batch programs.
I tried adding the togglz library in the stand alone application and tried running it.
this is my code snippet -
import com.feature.MyFeature;
public class Test {
public static void main(String[] args) {
Test t = new Test();
boolean valid=t.validate("CREATE_TEAM");
System.out.println(valid);
}
public boolean validate(String feature){
if (MyFeature.valueOf(feature).isActive()) {
return true;
}
return false;
}
}
It says -
Exception in thread "main" java.lang.IllegalStateException: Could not find the FeatureManager. For web applications please verify that the TogglzFilter starts up correctly. In other deployment scenarios you will typically have to implement a FeatureManagerProvider as described in the 'Advanced Configuration' chapter of the documentation.
at com.amdocs.switchlite.core.context.FeatureContext.getFeatureManager(FeatureContext.java:53)
at com.feature.MyFeature.isActive(MyFeature.java:20)
at Test.validate(Test.java:22)
at Test.main(Test.java:12)
You will have to configure Togglz correctly to make it work. In a standalone application I recommend the following setup.
First create a FeatureManager using the FeatureManagerBuilder. Something like this:
FeatureManager featureManager = FeatureManagerBuilder.begin()
.featureEnum(Features.class)
.stateRepository(new InMemoryStateRepository())
.userProvider(new NoOpUserProvider())
.build();
The tell StaticFeatureManagerProvider about your manager:
StaticFeatureManagerProvider.setFeatureManager(featureManager);
Now StaticFeatureManagerProvider is able to tell Togglz about your FeatureManager and everything should work fine!
Features.FOOBAR.isActive();
// > false
I have my own custom-written unmanaged extension for Neo4j database.
I want to run integration tests againt fully-functional database, with unmanaged extension available there.
Neo4j provides tool called neo4j-harness that makes it easier to write integration tests for unmanged extensions. More iformation is available here.
Blog post
1) Determine Neo4j version that is needed (used).
Maven:
<properties>
<version.neo4j>2.2.5</version.neo4j>
</properties>
2) Add dependency for neo4j-harness.
Maven:
<dependency>
<groupId>org.neo4j.test</groupId>
<artifactId>neo4j-harness</artifactId>
<version>${version.neo4j}</version>
<!-- If you want to use Neo4j server in sources, instead of tests, then remove this line -->
<scope>test</scope>
</dependency>
3) Be sure that you unmanaged extension sources is available in tests.
Maven:
If you write tests into same module with extension, then everything is OK.
If you write tests in seperate module (i.e. integration-tests), then make sure that extension is available there.
<dependency>
<groupId>my.company</groupId>
<artifactId>unmanaged-extension</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
4) Create Neo4jTestServer class that is responsible for database start-up and shutdown.
/**
* Spin-up Neo4j server with loaded unmanaged extension.
*/
public final class Neo4jTestServer {
public static final String EXTENSION_MOUNT_POINT = "/ext";
public static final String EXTENSION_RESOURCES = "my.company.extension.resources";
// Alternative way to get package
// public static final String EXTENSION_RESOURCES = SomeResource.class.getPackage().getName();
private static Neo4jTestServer INSTANCE = null;
public static synchronized Neo4jTestServer getInstance() {
if (INSTANCE == null) {
INSTANCE = new Neo4jTestServer();
}
return INSTANCE;
}
private final ServerControls serverControls;
private Neo4jTestServer() {
serverControls = TestServerBuilders.newInProcessBuilder()
.withExtension(EXTENSION_MOUNT_POINT, EXTENSION_RESOURCES)
// Resource can be specified directly
// .withExtension(EXTENSION_MOUNT_POINT, SomeResource.class)
.newServer();
}
public ServerControls getServerControls() {
return serverControls;
}
public void shutdown() {
serverControls.close();
}
}
Usage:
Neo4jTestServer server = Neo4jTestServer.getInstance();
// Get Neo4j server URI, with port
server.getServerControls().getHttpUri();
// Shutdown server
server.shutdown();
Notes:
SomeResource is JAX-RS resource that provides custom functionality
If you have more than 1 resource, and want to use class to specify unmanaged extension, instead of string - there is no need to specify all thoose classes. Neo4j will scan specified class package for other resources and load them automatically.
All resources should be in same package
Tip: You can create ResourcesRootPackageMarker class in same package, where all resources reside and use this class to specify package. It makes code more resilient to future code refactorings.
5) Optional. Specify JVM shutdown hook to shutdown database.
final Neo4jTestServer server = Neo4jTestServer.getInstance();
Runtime.getRuntime().addShutdownHook(new Thread() {
#Override
public void run() {
server.shutdown();
}
});
6) To verify that everything is working and your unmanaged extension is available - execute tests, start database and examine output generated by Neo4j server.
You should see something like this:
INFO: Scanning for root resource and provider classes in the packages:
my.company.extension.resources
Sep 14, 2015 5:25:15 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
class my.company.extension.resources.SomeResource
class my.company.extension.resources.AnotherResource
EDIT: Graphaware test framework, information provided by MicTech
Alternatively, there is GraphAware Test framework provided by graphaware, that gives possibility to test any Neo4j-related code.
This module provides means of easily testing code that talks to the Neo4j database in one way or another. The target audience of this module are Java developers who write Neo4j-related code, as well as authors of GraphAware Modules and APIs.
Here you can find some posts about how framework can be used (autored by Graphaware developers).
Basically what you need to do is:
1) Create extension:
#Path("/helloworld")
public class HelloWorldUnmanagedExtension {
private final HelloWorldNodeCreator nodeCreator;
public HelloWorldUnmanagedExtension(#Context GraphDatabaseService database) {
nodeCreator = new HelloWorldNodeCreator(database);
}
#POST
#Path("/create")
public Response createHelloWorldNode() {
Node node = nodeCreator.createHelloWorldNode();
return Response.ok(String.valueOf(node.getId())).build();
}
}
2) Extend your test with WrappingServerIntegrationTest and necessary configuration.
public class HelloWorldUnmanagedExtensionApiTest extends WrappingServerIntegrationTest {
#Override
protected Map<String, String> thirdPartyJaxRsPackageMappings() {
return Collections.singletonMap("com.graphaware.example.unmanaged", "/ext");
}
#Test
public void shouldCreateAndReturnNode() {
String result = TestUtils.post(baseNeoUrl() + "/ext/helloworld/create", 200);
assertEquals("0", result);
GraphUnit.assertSameGraph(getDatabase(), "CREATE (:HelloWorld {hello:'world'})");
}
}
Here can be found more detailed instructions on how to test unmanaged extension with Graphaware test framework.
Everything should be up-and-running now and ready for testing. Good luck!
I thought I would use the new ResourceBundleControlProvider framework in Java 8 to fix something which Oracle themselves will never fix - the default encoding used when reading resource bundles.
So I made a control:
package com.acme.resources;
import java.io.IOException;
import java.util.Locale;
import java.util.ResourceBundle;
public class AcmeResourceBundleControl extends ResourceBundle.Control
{
#Override
public ResourceBundle newBundle(String baseName, Locale locale, String format,
ClassLoader loader, boolean reload)
throws IllegalAccessException, InstantiationException, IOException
{
throw new UnsupportedOperationException("TODO");
}
}
Then I made a provider:
package com.acme.resources;
import java.util.ResourceBundle;
import java.util.spi.ResourceBundleControlProvider;
public class AcmeResourceBundleControlProvider implements ResourceBundleControlProvider
{
private static final ResourceBundle.Control CONTROL = new AcmeResourceBundleControl();
#Override
public ResourceBundle.Control getControl(String baseName)
{
if (baseName.startsWith("com.acme."))
{
return CONTROL;
}
else
{
return null;
}
}
}
Then in META-INF/services/java.util.spi.ResourceBundleControlProvider:
com.acme.resources.AcmeResourceBundleControlProvider
Then I just tried to run our application from IDEA and I find that it never loads my provider (otherwise the exception would be raised.)
I have checked the names and they all seem to match up. I have checked the compiler output directory IDEA is using and it does contain the service file. I wrote a simple test program which just tries to look up the service:
public static void main(String[] args)
{
for (ResourceBundleControlProvider provider :
ServiceLoader.load(ResourceBundleControlProvider.class))
{
System.out.println(provider.getClass());
}
}
This does print out one entry which is the name of my implementation class. So the issue is not in the service file.
If I breakpoint inside ResourceBundle, I seem to be able to access the custom provider class. Initial forays into the debugger show that ServiceLoader isn't finding any implementations, but I can't figure out why. I'm sure there is some dodgy class loader magic going on which results in not loading my class. :(
Some scary documentation on the Javadoc makes it sound like it might have to be installed as a global extension. If that really is the case, it's a bit of a shame, because it seemed like a useful way to override the default (and in my opinion broken) behaviour. But I also read the tutorial on the matter and it didn't seem to be describing anything like that (unless the good behaviour was pulled out of Java 8 at the very last minute and the docs are out of date!)
The tutorial does state that the JAR containing the ResourceBundleControlProvider must be in the JVM's system extension directory. Section 6 of the tutorial describes the requirement:
java -Djava.ext.dirs=lib -cp build RBCPTest
When you install a Java extension, you typically put the JAR file of the extension in the lib/ext directory of your JRE. However, this command specifies the directory that contains Java extensions with the system property java.ext.dirs.
The JavaDoc for ServiceLoader.loadInstalled() also states that providers on the application's class path are ignored.
Your problem is that the java.util.ResourceBundle that comes with the JVM does a ServiceLoader.loadInstalled(ResourceBundleControlProvider.class) to obtain a list of providers in the static initializer, and uses the thus obtained list ever after.