Can't find assertThat - java

Here is my code
import org.junit.Test;
import static org.junit.Assert.assertThat;
import static sun.nio.cs.Surrogate.is;
public class PlayerTest {
public void should_return_3_when_status_is_3(){
Player player = new Player();
assertThat(player.getStatus(),is(3));
}
}
And here is the trace
Can't find symbol
符号: method assertThat(int,boolean)
位置: class PlayerTest
my iml file is
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="TEST">
<library>
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.10.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
I think I used it before,but it not works now.
Have no clue about what to do.However assertTrue is working.
Ubuntu 11.04 is being used.

The mistake is in
import static sun.nio.cs.Surrogate.is;
is() should return a matcher, but whatever this is, it returns boolean. Try org.hamcrest.Matchers.is or org.hamcrest.CoreMatchers.is instead.

Related

Android Studio java-library module classpath NoClassDefFoundError

My project is started to be large, so I decided to split it into separated modules - gui and domain. My domain module mustn't know that it is a part of Android project, so I created java-library module and put some classes there. It works like a charm but there is a problem when I add some other dependencies inside my java-library module like RxJava. I've created a Main class to simply test my code. Builds passes, but when it tries to invoke RxJava classes it crashes with exception:
Exception in thread "main" java.lang.NoClassDefFoundError: io/reactivex/Observable
at com.example.domain.Main.main(Main.java:13)
Caused by: java.lang.ClassNotFoundException: io.reactivex.Observable
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
My Main class:
package com.example.domain;
import io.reactivex.Observable;
public class Main {
public static void main(String[] args) {
Observable.just(1)
.subscribe(integer -> System.out.println(integer));
}
}
My build.gradle file:
apply plugin: 'java-library'
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
api 'io.reactivex.rxjava2:rxjava:2.1.2'
}
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
1) If I use com.android.library instead it works
2) If I add RxJava library as a .jar file it changes nothing
EDIT:
I looked into Domain.iml file and I found something strange:
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":Domain" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":Domain" />
</configuration>
</facet>
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="true" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/build/classes/java/main" />
<output-test url="file://$MODULE_DIR$/build/classes/java/test" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" scope="PROVIDED" name="rxjava-2.1.2" level="project" />
<orderEntry type="library" exported="" scope="PROVIDED" name="reactive-streams-1.0.0" level="project" />
</component>
</module>
The weird part is scope attribute in orderEntry node
<orderEntry type="library" exported="" scope="PROVIDED" name="rxjava-2.1.2" level="project" />
<orderEntry type="library" exported="" scope="PROVIDED" name="reactive-streams-1.0.0" level="project" />
If I remove it manually:
<orderEntry type="library" exported="" name="rxjava-2.1.2" level="project" />
<orderEntry type="library" exported="" name="reactive-streams-1.0.0" level="project" />
It works like a charm.
Unfortunately if I sync my build.gradle file it overrides my modification.
How to make it works permanently and why this acts like this?
The weird part is scope attribute in orderEntry node
<orderEntry type="library" exported="" scope="PROVIDED" name="rxjava-2.1.2" level="project" />
<orderEntry type="library" exported="" scope="PROVIDED" name="reactive-streams-1.0.0" level="project" />
If I remove it manually:
<orderEntry type="library" exported="" name="rxjava-2.1.2" level="project" />
<orderEntry type="library" exported="" name="reactive-streams-1.0.0" level="project" />
It works like a charm.
Unfortunately if I sync my build.gradle file it overrides my
modification.
Have you tried to change the scope via Android Studios Project Structure?
File -> Project Structure then select the Dependencies Tab and add the Dependency for the required module. In your case that would be java-library I believe.
As far as i know you can't change the scope of the dependency once added. So if you have already added it, try to remove and add it again. Be sure to assign the implementation scope though and see if it works.
I hope this was helpful

IzPack Shortcut Nightmare

I'm at my wit's end with this.
I have a VERY simple installation descriptor for izpack for a two-package Java app on Windows. Everything works as intended EXCEPT for the shortcut creation. The shortcut panel doesn't seem right, for a start. The label "ShortcutPanel.regular.startup" is displayed instead of "run at startup" or anything of the sort in the startup execution checkbox.
After running the installer, the shortcuts simply aren't created. Here's what my install.xml looks like, it's pretty straightforward:
<izpack:installation version="5.0"
xmlns:izpack="http://izpack.org/schema/installation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://izpack.org/schema/installation http://izpack.org/schema/5.0/izpack-installation-5.0.xsd">
<info>
<appname>application_name</appname>
<appversion>2.0.0</appversion>
<appsubpath>myapp</appsubpath>
<javaversion>1.8</javaversion>
</info>
<locale>
<langpack iso3="bra" />
</locale>
<resources>
<res src="shortcutSpec.xml" id="shortcutSpec.xml"/>
</resources>
<variables>
<variable name="TargetPanel.dir.windows" value="C:/Sistemas"/>
</variables>
<guiprefs width="800" height="600" resizable="no">
<laf name="substance">
<os family="windows" />
<os family="unix" />
<param name="variant" value="mist-silver" />
</laf>
<modifier key="useHeadingPanel" value="yes" />
</guiprefs>
<panels>
<panel classname="HelloPanel" />
<panel classname="DefaultTargetPanel" />
<panel classname="ShortcutPanel" />
<panel classname="InstallPanel" />
<panel classname="FinishPanel" />
</panels>
<natives>
<native type="izpack" name="ShellLink.dll">
<os family="windows"/>
</native>
<native type="izpack" name="ShellLink_x64.dll">
<os family="windows"/>
</native>
</natives>
<packs>
<pack name="Pack1" required="yes">
<description>one of the packs it's a jar</description>
<file src="lib/pack1.jar" targetdir="$INSTALL_PATH/pack1subdir"
override="true">
</file>
<file src="imagens/logo.ico" targetdir="$INSTALL_PATH/pack1subdir/imagens/"
override="true" />
<executable targetfile="lib/pack1.jar" type="jar"
stage="never"></executable>
</pack>
<pack name="Pack2" required="yes">
<description>the other pack</description>
<file src="lib/pack2.jar" targetdir="$INSTALL_PATH/pack2subdir"
override="true">
</file>
<file src="imagens/update.ico" targetdir="$INSTALL_PATH/pack2subdir/imagens/"
override="true" />
<executable targetfile="lib/pack2.jar" type="jar"
stage="never"></executable>
</pack>
</packs>
Then there's the shortcutSpec.xml. My pom moves it to my staging directory:
<izpack:shortcuts version="5.0"
xmlns:izpack="http://izpack.org/schema/shortcuts" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://izpack.org/schema/shortcuts http://izpack.org/schema/5.0/izpack-shortcuts-5.0.xsd">
<lateShortcutInstall />
<shortcut name="pack1" programGroup="false"
desktop="true" applications="false" startMenu="no" startup="true"
target="java -jar $INSTALL_PATH/pack1subdir/pack1.jar"
workingDirectory="$INSTALL_PATH/pack1subdir/">
<createForPack name="pack1" />
</shortcut>
<shortcut name="pack2" programGroup="false"
desktop="true" applications="false" startMenu="no" startup="true"
target="java -jar $INSTALL_PATH/pack2subdir/pack1.jar"
workingDirectory="$INSTALL_PATH/pack2subdir/">
<createForPack name="pack2" />
</shortcut>
The installer simply doesn't create any shortcuts anywhere. It finishes with no error messages no logs no stack traces no nothing.
Help.
I fixed that by going into the izPack/lib/izpack-core-5.0.9.jar and opening the /com/izforge/izpack/bin/langpacks/installer/ folder in it. Then editing the bra.xml file and adding the following line:
<str id="ShortcutPanel.regular.startup" txt="Iniciar com o Windows"/>
Then save and update the file in the jar and rebuild your instalation.

Multinesting Gradle Projects in IntelliJ Idea

I am using IntelliJ Idea 14.1.4 and Gradle, and I am trying to create sub projects and nested sub projects:
Project
|--Research
|--Development
|--Algorithms
The reason for this is that research algorithms are separate from the development implementation. They are written in different languages (Python vs. Java) and used by different programmers, however I still want to maintain one Gradle project, so eventually researchers would be able to use stable existing algorithms implementations when developing new ones.
My problem is that Idea doesn't recognize properly the Gradle structure of the second level Gradle sub project: Project is recognized well, Research and Development are recognized well, but the Algorithms sub project is not recognized:
The code inspection of the gradle.build file in Algorithms project is highlighted as a warning with a message that test cannot be applies to Groovy.lang.closure Note that below is the complete build.gradle:
test{
useTestNG()
testLogging.showStandardStreams = true
}
Also, when I try in Idea Run->Edit Configurations->Defaults->Gradle and trying to choose Gradle project, I see that in the pop-up menu Development and Research do appear as sub-projects of Project, but Algorithms appears as a stand alone project.
Making the project however does create all the binaries and manually running a test case also works well.
When I run Gradle for command line, it appears to be working well and recognizing all nested projects: All the code is being compiled and tests are being ran. So the question here is if there is an Idea issue here which is not working correctly with Gradle, or am I doing something wrong?
Code for build.gradle inside Project:
allprojects {
group 'com.project'
version 'v0.1'
repositories {
mavenCentral()
}
}
Code for settings.gradle inside Project
rootProject.name = 'Project'
include 'Development'
include 'Development:Algorithms'
include 'Research'
Code for build.gradle of Development sub-project:
subprojects {
apply plugin: 'java'
repositories {
jcenter()
}
dependencies{
testCompile 'org.testng:testng:6.9.4'
}
}
Other code samples that I might be writing wrong (most of them are auto generated by Idea:
Project.iml:
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="Project" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="com.project" external.system.module.version="v0.1" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build" />
<output-test url="file://$MODULE_DIR$/build" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Development.iml
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":Development" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.project" external.system.module.version="v0.1" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build" />
<output-test url="file://$MODULE_DIR$/build" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Algorithms.iml
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":Development:Algorithms" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="com.project" external.system.module.version="v0.1" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/classes/main" />
<output-test url="file://$MODULE_DIR$/build/classes/test" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="TEST">
<library>
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/plugins/testng/lib/testng.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
I would like to point the following:
All projects and sub-projects have the same group: com.project
In Algorithms.iml the original (auto generated) value of external.linked.project.id was :Algorithms. I have tried setting it to :Development:Algorithms to see if it will change anything. After each change I have ran rebuild.
In Algorithms.iml the original (auto generated) value of external.root.project.path was $MODULE_DIR$/... I have tried setting it to $MODULE_DIR$/../.. to see if it will change anything. After each change I have ran rebuild.
****************************Edit********************************
Further investigation shows an issue with the workspace.xml file:
There is a GradleLocalSettingsElement there that was automatically created, but appears to be wrong: There are two different entries: one for Development and Devlopment:Algorithms and onw for the rest, so I might have did something wrong when I created the project.
My question is if there is a reference for the structure of this file and specifically for the elements inserted by the Gradle plugin?
<map>
<entry>
<key>
<ExternalProjectPojo>
<option name="name" value="Development" />
<option name="path" value="$PROJECT_DIR$/Development" />
</ExternalProjectPojo>
</key>
<value>
<list>
<ExternalProjectPojo>
<option name="name" value="Development" />
<option name="path" value="$PROJECT_DIR$/Development" />
</ExternalProjectPojo>
<ExternalProjectPojo>
<option name="name" value=":Development:Algorithms" />
<option name="path" value="$PROJECT_DIR$/Development/Algorithms" />
</ExternalProjectPojo>
</list>
</value>
</entry>
<entry>
<key>
<ExternalProjectPojo>
<option name="name" value="Project" />
<option name="path" value="$PROJECT_DIR$" />
</ExternalProjectPojo>
</key>
<value>
<list>
<ExternalProjectPojo>
<option name="name" value="Project" />
<option name="path" value="$PROJECT_DIR$" />
</ExternalProjectPojo>
<ExternalProjectPojo>
<option name="name" value=":Development" />
<option name="path" value="$PROJECT_DIR$/Development" />
</ExternalProjectPojo>
<ExternalProjectPojo>
<option name="name" value=":Research" />
<option name="path" value="$PROJECT_DIR$/Research" />
</ExternalProjectPojo>
</list>
</value>
</entry>
</map>

Spring 4 HTTP status 404

I'm just start working with Spring 4. I want to setup Spring 4 MVC project with java configuration. I use IntelliJ Idea 13.1.6. First I create new Spring 4 MVC project from Spring MVC 3.2 template. Then I add my Java spring configuration files but when I run app its shows "Hello world" from hello template controller instead of my Home controller. Here is my project structure:
And here is my project files:
HelloController:
package com.spitter.mvc;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
#Controller
#RequestMapping("/")
public class HelloController {
#RequestMapping(method = RequestMethod.GET)
public String printWelcome(ModelMap model) {
model.addAttribute("message", "Hello world!");
return "hello";
}
}
RootConfig:
package spittr.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
#Configuration
#ComponentScan(basePackages={"spitter"},
excludeFilters={
#Filter(type=FilterType.ANNOTATION, value=EnableWebMvc.class)
})
public class RootConfig {
}
SpittrWebAppInitializer:
package spittr.config;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class SpittrWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
#Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
#Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] { RootConfig.class };
}
#Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[] { WebConfig.class };
}
}
HomeController:
package spittr.web;
import static org.springframework.web.bind.annotation.RequestMethod.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
#Controller
public class HomeController {
#RequestMapping(value="/", method=GET)
public String home() {
return "home";
}
}
mvc-dispatcher-servlet.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.spitter.mvc"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
web-app.xml:
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Spitter.iml:
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="web" name="Web">
<configuration>
<descriptors>
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml" />
</descriptors>
<webroots>
<root url="file://$MODULE_DIR$/src/main/webapp" relative="/" />
</webroots>
<sourceRoots>
<root url="file://$MODULE_DIR$/src/main/resources" />
<root url="file://$MODULE_DIR$/src/main/java" />
</sourceRoots>
</configuration>
</facet>
<facet type="Spring" name="Spring">
<configuration />
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test-mvc:1.0.0.M2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Tomcat 8.0.151" level="application_server_libraries" />
<orderEntry type="library" name="Maven: org.springframework:spring-core:3.2.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-web:3.2.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-context:3.2.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-aop:3.2.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: aopalliance:aopalliance:1.0" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-beans:3.2.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-expression:3.2.0.RELEASE" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.servlet.jsp:jsp-api:2.1" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:3.2.0.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:3.2.0.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.8.2" level="project" />
<orderEntry type="library" name="Maven: javax.servlet:jstl:1.2" level="project" />
</component>
</module>
Why this code dont run home controller but hello controller insdead and how can I fix it?
I suspect that there is something wrong with Spitter.iml file and spring see only web.xml configuration instead of java class configuration.
The main problem i see is the configuration and some small details.
In your example, you are using two ways to configure the project (Java and XML).
I preffer to use Java-based configuration, it can be combined but without causing conflicts.
Your example run HelloController because it is indicated in mvc-dispatcher-servlet.xml with the base-package.
<context:component-scan base-package="com.spitter.mvc"/>
And moreover, SpittrWebAppInitializer replace to web.xml. You must delete XML files and modify RootConfig to specify the correct package.
#ComponentScan(basePackages={"spittr"}
And WebConfig so be similar to this.
#Configuration
#EnableWebMvc
#ComponentScan("spittr.web")
public class WebConfig extends WebMvcConfigurerAdapter {
// Configure a JSP view resolver
#Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setViewClass(JstlView.class);
resolver.setPrefix("/WEB-INF/pages/");
resolver.setSuffix(".jsp");
return resolver;
}
#Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// TODO Auto-generated method stub
super.addResourceHandlers(registry);
}
}
And you can only have unique paths in your controllers, for example if you add to WebConfig the package com.spitter.mvc to #ComponentScan you will have an error.

File metro-default.xml not found on Weblogic 12.1.3

We're currently running on WebLogic 12.1.2. And in this environment our application runs fine.
What we want now is to homologate our applications to WebLogic 12.1.3 environments. But we are facing a problem with the Web Services we use. In the new version the server throws a exception saying that the "Default configuration file [ metro-default.xml ] was not found".
I'm trying to find something on this file but there is nothing.
PS: We do not use Metro, we use the WebLogic default JAX-WS stack. And the application is deployed as a WAR file.
Here is the stack of the exception
java.lang.IllegalStateException: MASM0001: Default configuration file [ metro-default.xml ] was not found
at com.sun.xml.ws.assembler.MetroConfigLoader.init(MetroConfigLoader.java:142)
at com.sun.xml.ws.assembler.MetroConfigLoader.<init>(MetroConfigLoader.java:119)
at com.sun.xml.ws.assembler.TubelineAssemblyController.getTubeCreators(TubelineAssemblyController.java:122)
at com.sun.xml.ws.assembler.MetroTubelineAssembler.createServer(MetroTubelineAssembler.java:173)
at com.sun.xml.ws.server.WSEndpointImpl.<init>(WSEndpointImpl.java:193)
at com.sun.xml.ws.server.EndpointFactory.create(EndpointFactory.java:337)
at com.sun.xml.ws.server.EndpointFactory.create(EndpointFactory.java:332)
at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:164)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:577)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:560)
at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parseAdapters(DeploymentDescriptorParser.java:303)
at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parse(DeploymentDescriptorParser.java:179)
at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.parseAdaptersAndCreateDelegate(WSServletContextListener.java:131)
at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized(WSServletContextListener.java:152)
at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:678)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
at weblogic.servlet.internal.EventsManager.executeContextListener(EventsManager.java:243)
at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:200)
at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:185)
at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1838)
at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:2876)
at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1661)
at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:823)
at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:360)
at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:356)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:138)
at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:216)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:211)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:73)
at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:24)
I solved it so that I added jaxws-rt-2.2.8.jar as a dependency to my project and wrote following to the weblogic-application.xml:
<wls:prefer-application-packages>
<package-name>com.sun.xml.ws.api.wsdl.parser.*</package-name>
</wls:prefer-application-packages>
<wls:prefer-application-resources>
<wls:resource-name>META-INF/services/javax.xml.ws.*</wls:resource-name>
<wls:resource-name>META-INF/services/com.sun.xml.ws.*</wls:resource-name>
<wls:resource-name>META-INF/services/com.sun.tools.ws.*</wls:resource-name>
</wls:prefer-application-resources>
All credit to Thomas Isaksen
I placed this metro-default.xml in my maven src/main/resources/META-INF which results in the file being placed WEB-INF/classes/META-INF
The default here caused many ClassNotFoundExceptions...
(I am using Weblogic 12.2.1.0.0)
<?xml version="1.0" encoding="UTF-8"?>
<metro xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns='http://java.sun.com/xml/ns/metro/config'
version="1.0">
<tubelines default="#default-metro-tubeline">
<tubeline name="default-metro-tubeline">
<client-side>
<tube-factory className="com.sun.xml.ws.assembler.jaxws.TerminalTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.HandlerTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.ValidationTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.MustUnderstandTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.MonitoringTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.AddressingTubeFactory" />
<tube-factory className="com.sun.xml.ws.rx.rm.runtime.RmTubeFactory" />
<tube-factory className="com.sun.xml.ws.dump.MessageDumpingTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.TransportTubeFactory" />
</client-side>
<endpoint-side>
<tube-factory className="com.sun.xml.ws.assembler.jaxws.TransportTubeFactory" />
<tube-factory className="com.sun.xml.ws.dump.MessageDumpingTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.AddressingTubeFactory" />
<tube-factory className="com.sun.xml.ws.rx.rm.runtime.RmTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.MonitoringTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.MustUnderstandTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.HandlerTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.ValidationTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.TerminalTubeFactory" />
</endpoint-side>
</tubeline>
</tubelines>
</metro>
We placed the metro-default.xml in WEB-INF/classes/META-INF to resolve the issue. Contents of the file can be taken from here :
https://metro.java.net/guide/ch02.html#dynamic_tube-based_message_logging
As Tube based messaging is introduced , jaxws-ri-2.2.8 jars are required to make any JAX-WS web services work.
create a xml file named metro-default.xml and add the below xml content into it ,then place this metro-default.xml file inside the WEB-INF folder of your project then restart the server it will work.
<?xml version="1.0" encoding="UTF-8"?>
<metro xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns='http://java.sun.com/xml/ns/metro/config'
version="1.0">
<tubelines default="#default-metro-tubeline">
<tubeline name="default-metro-tubeline">
<client-side>
<tube-factory className="com.sun.xml.ws.assembler.jaxws.TerminalTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.HandlerTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.ValidationTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.MustUnderstandTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.MonitoringTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.AddressingTubeFactory" />
<tube-factory className="com.sun.xml.ws.rx.rm.runtime.RmTubeFactory" />
<tube-factory className="com.sun.xml.ws.dump.MessageDumpingTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.TransportTubeFactory" />
</client-side>
<endpoint-side>
<tube-factory className="com.sun.xml.ws.assembler.jaxws.TransportTubeFactory" />
<tube-factory className="com.sun.xml.ws.dump.MessageDumpingTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.AddressingTubeFactory" />
<tube-factory className="com.sun.xml.ws.rx.rm.runtime.RmTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.MonitoringTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.MustUnderstandTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.HandlerTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.ValidationTubeFactory" />
<tube-factory className="com.sun.xml.ws.assembler.jaxws.TerminalTubeFactory" />
</endpoint-side>
</tubeline>
</tubelines>

Categories