I have configured SFTP Adapter configurations in Spring Aplication file and i have one JAR which is including in that war file & i have rsa file on resource location of that Jar file but when i try to deploy it on Weblogic 10.3.6.0 it does not find rsa file and gives the following error:
POM.XML:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.abc.tsi</groupId>
<artifactId>tsi-ibs2bank</artifactId>
<packaging>pom</packaging>
<version>1.1-SNAPSHOT</version>
<name>Project</name>
<modules>
<module>tsi-a-core</module>
<module>tsi-b-services</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav-jackrabbit</artifactId>
<version>1.0-beta-7</version>
</extension>
</extensions>
</build>
<properties>
<cxf.version>3.0.1</cxf.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Stacktrace:
synchronizing remote to local directory
at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.synchronizeToLocalDirectory(AbstractInboundFileSynchronizer.java:209)
at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizingMessageSource.receive(AbstractInboundFileSynchronizingMessageSource.java:167)
at org.springframework.integration.endpoint.SourcePollingChannelAdapter.receiveMessage(SourcePollingChannelAdapter.java:144)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.doPoll(AbstractPollingEndpoint.java:192)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.access$000(AbstractPollingEndpoint.java:55)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:149)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:146)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller$1.run(AbstractPollingEndpoint.java:298)
at org.springframework.integration.util.ErrorHandlingTaskExecutor$1.run(ErrorHandlingTaskExecutor.java:52)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:51)
at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:59)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller.run(AbstractPollingEndpoint.java:314)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:82)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:440)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:139)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.springframework.messaging.MessagingException: Failed to obtain pooled item
at org.springframework.integration.util.SimplePool.getItem(SimplePool.java:177)
at org.springframework.integration.file.remote.session.CachingSessionFactory.getSession(CachingSessionFactory.java:118)
at org.springframework.integration.file.remote.RemoteFileTemplate.execute(RemoteFileTemplate.java:310)
at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.synchronizeToLocalDirectory(AbstractInboundFileSynchronizer.java:167)
at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizingMessageSource.receive(AbstractInboundFileSynchronizingMessageSource.java:168)
... 20 more
Caused by: java.lang.IllegalStateException: failed to create SFTP Session
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:354)
at org.springframework.integration.file.remote.session.CachingSessionFactory$1.createForPool(CachingSessionFactory.java:76)
at org.springframework.integration.file.remote.session.CachingSessionFactory$1.createForPool(CachingSessionFactory.java:73)
at org.springframework.integration.util.SimplePool.doGetItem(SimplePool.java:187)
at org.springframework.integration.util.SimplePool.getItem(SimplePool.java:167)
... 24 more
Caused by: java.io.FileNotFoundException: ServletContext resource [/classpath*:WEB-INF/id_rsa] cannot be resolved to absolute file path - web application archive not expanded?
at org.springframework.web.util.WebUtils.getRealPath(WebUtils.java:237)
at org.springframework.web.context.support.ServletContextResource.getFile(ServletContextResource.java:176)
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.initJschSession(DefaultSftpSessionFactory.java:370)
Application.xml
<bean id="defaultSftpSessionFactory"
class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
<property name="host" value="${sftp.host}" />
<property name="user" value="${sftp.username}" />
<!--<property name="password" value="${sftp.password}"/> -->
<property name="port" value="${sftp.serverPort}" />
<property name="privateKey" value="${sftp.private.keyfile}" />
<property name="privateKeyPassphrase" value="${sftp.passphrase}" />
</bean>
<bean id="sftpSessionFactory"
class="org.springframework.integration.file.remote.session.CachingSessionFactory">
<constructor-arg ref="defaultSftpSessionFactory" />
</bean>
Related
I have been using intellij for 2 years now and love it. however after updating to 2016.3.4 it stopped highlighting path locations in the run window.
I used to be able to just click on the highlighted path and it would jump to the file and line.
example of output from maven-checkstyle-plugin which should be "clickable" :
[ERROR] C:\Users\userName\Documents\project.main\src\main\java\MyClass.java:36: Only one statement per line allowed. [OneStatementPerLine]
This is extremely frustrating and any idea of how to get intellij to do this again would be fantastic.
Minimal, Complete, and Verifiable example
To Replicate this Create a project in IntelliJ IDEA called "bug"
IntelliJ IDEA 2016.3.4
Build #IU-163.12024.16, built on January 31, 2017
Create a folder
bug->CodeStyle
and a file in this folder
"checkstyle.xml"
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="charset" value="UTF-8"/>
<property name="severity" value="error"/>
<property name="fileExtensions" value="java,"/>
<module name="FileTabCharacter"/>
<module name="TreeWalker">
<module name="RegexpSinglelineJava">
<property name="format" value="System\.(out|err).*?$"/>
<property name="ignoreComments" value="true"/>
</module>
</module>
</module>
the pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>bugExample</groupId>
<artifactId>bug</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<configLocation>CodeStyle/checkstyle.xml</configLocation>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>6.18</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
and a Class Example.java
public class Example {
public Example() {
System.out.println("This is not allowed");
}
}
And now in the maven project Tool Click life-cycle, and then Validate.
The outputs in the "run terminal" :
[INFO] Starting audit...
[ERROR] C:\Users\Username\bug\src\main\java\Example.java:7: Line matches the illegal pattern 'System\.(out|err).*?$'. [RegexpSinglelineJava]
Audit done.
So the problem is that Example.java is Not "Clickable", it has been in the past.
Thanks for the example, I've reported a bug for IntelliJ IDEA Maven integration, feel free to vote:
IDEA-169034 File paths are not clickable in the Maven tool output
I am trying to make a maven project using Datanucleus as a database abstraction. However, when i try to mvn datanucleus:schema-create, i get the following error:
[ERROR] --------------------
[ERROR] Standard error from the DataNucleus tool + org.datanucleus.store.schema.SchemaTool :
[ERROR] --------------------
[ERROR] Error: Could not find or load main class org.datanucleus.store.schema.SchemaTool
The relevant parts from the pom.xml file are:
<dependencies>
<dependency>
<groupId>javax.jdo</groupId>
<artifactId>jdo-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>4.0.4</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jdo</artifactId>
<version>4.0.4</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-rdbms</artifactId>
<version>4.0.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- <version>3.2</version> -->
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-maven-plugin</artifactId>
<version>4.0.0-release</version>
<configuration>
<api>JDO</api>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
And the persistence.xml file is in /src/main/resources/META-INF/persistence.xml, containing the following:
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<!-- JDO tutorial "unit" -->
<persistence-unit name="Tutorial">
<class>a.b.c.MyClass</class>
<exclude-unlisted-classes />
<properties>
<property name="javax.jdo.option.PersistenceUnitName" value="Tutorial" />
<property name="javax.jdo.option.ConnectionURL" value="jdbc:mysql://localhost/mydb" />
<property name="javax.jdo.option.ConnectionDriverName"
value="com.mysql.jdbc.Driver" />
<property name="javax.jdo.option.ConnectionUserName" value="myuser" />
<property name="javax.jdo.option.ConnectionPassword" value="mypass" />
<property name="datanucleus.schema.autoCreateAll" value="true" />
<property name="datanucleus.schema.validateTables" value="true" />
<property name="datanucleus.schema.validateConstraints"
value="true" />
<property name="javax.jdo.PersistenceManagerFactoryClass"
value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory" />
</properties>
</persistence-unit>
To my untrained eye it looks like everything is in place, yet it doesn't work.
Perhaps your <scope>runtime</scope> is causing the problem, because that jar contains this class. Whether it is or not you can easily enable Maven debug --debug on the command line and look at what is in the CLASSPATH for that operation.
Edit: Question Rewritten:
I created a new minimal example to illustrate my problem. First here is the source code of a simple class App.java:
package testlog4j.testlog4j;
import java.io.*;
import java.net.*;
import org.apache.log4j.*;
import org.apache.log4j.xml.*;
public class App
{
static Logger logger = Logger.getLogger(App.class);
URL url = getClass().getClassLoader().getResource("log4j.xml");
public static void main( String[] args )
{
App app = new App();
DOMConfigurator.configure(app.url);
System.out.println( "Hello World!" );
System.out.println("Resource(.): " + App.class.getResource("."));
System.out.println("Resource(): " + App.class.getResource(""));
System.out.println("URL :" + app.url.toString());
logger.info("INFO");
}
}
Second, Here is the pom.xml file of the project
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>testlog4j</groupId>
<artifactId>testlog4j</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>testlog4j</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>testlog4j.testlog4j.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.dstovall</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<configuration>
<mainClass>testlog4j.testlog4j.App</mainClass>
<attachToBuild>true</attachToBuild>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>
<pluginRepositories>
<pluginRepository>
<id>onejar-maven-plugin.googlecode.com</id>
<url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url>
</pluginRepository>
</pluginRepositories>
</project>
Third, I have my log4j.xml under src/main/resources folder:
<?xml version="1.0" encoding="iso-8859-1"?>
<!--<!DOCTYPE log4j:configuration PUBLIC-->
<!--"-//APACHE//DTD LOG4J 1.2//EN" "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">-->
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration debug="true">
<appender name="default.console" class="org.apache.log4j.ConsoleAppender">
<param name="target" value="System.out" />
<param name="threshold" value="debug" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p [%c{1}] - %m%n" />
</layout>
</appender>
<appender name="main.file" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="log/main.log" />
<param name="MaxFileSize" value="2MB" />
<param name="append" value="true" />
<param name="threshold" value="debug" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p [%c{1}] - %m%n" />
</layout>
</appender>
<logger name="testlog4j.testlog4j.App" additivity="false">
<level value="debug" />
<appender-ref ref="main.file" />
<appender-ref ref="default.console" />
</logger>
<root>
<priority value="debug" />
<appender-ref ref="default.console" />
<appender-ref ref="main.file" />
</root>
OK, building the application and running in Netbeans works perfectly as expected logging out into both the console and a file under the log directory.
However, running from command line (both the normal jar and oneJar) doesn't work as you can see below:
java -jar testlog4j-1.0.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at testlog4j.testlog4j.App.<clinit>(App.java:17)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 1 more
java -jar testlog4j.1.0.one-jar.jar
log4j:ERROR Could not parse url [jar:file:/testlog4j-1.0.one-jar.jar!/main/testlog4j-1.0.jar!/log4j.xml].
java.io.FileNotFoundException: /testlog4j-1.0.one-jar.jar (No such file or directory)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:215)
at java.util.zip.ZipFile.<init>(ZipFile.java:145)
at java.util.jar.JarFile.<init>(JarFile.java:154)
at java.util.jar.JarFile.<init>(JarFile.java:91)
at sun.net.www.protocol.jar.URLJarFile.<init>(URLJarFile.java:93)
at sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:69)
at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:84)
at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:122)
at sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:150)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:613)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:189)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:812)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:347)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:177)
at org.apache.log4j.xml.DOMConfigurator$2.parse(DOMConfigurator.java:612)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:711)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:618)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:470)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:122)
at org.apache.log4j.Logger.getLogger(Logger.java:117)
at testlog4j.testlog4j.App.<clinit>(App.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.simontuffs.onejar.Boot.run(Boot.java:340)
at com.simontuffs.onejar.Boot.main(Boot.java:166)
log4j:ERROR Could not parse url [jar:file:/testlog4j-1.0.one-jar.jar!/main/testlog4j-1.0.jar!/log4j.xml].
java.io.FileNotFoundException: /testlog4j-1.0.one-jar.jar (No such file or directory)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:215)
at java.util.zip.ZipFile.<init>(ZipFile.java:145)
at java.util.jar.JarFile.<init>(JarFile.java:154)
at java.util.jar.JarFile.<init>(JarFile.java:91)
at sun.net.www.protocol.jar.URLJarFile.<init>(URLJarFile.java:93)
at sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:69)
at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:84)
at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:122)
at sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:150)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:613)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:189)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:812)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:347)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:177)
at org.apache.log4j.xml.DOMConfigurator$2.parse(DOMConfigurator.java:612)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:711)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:618)
at org.apache.log4j.xml.DOMConfigurator.configure(DOMConfigurator.java:743)
at testlog4j.testlog4j.App.main(App.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.simontuffs.onejar.Boot.run(Boot.java:340)
at com.simontuffs.onejar.Boot.main(Boot.java:166)
Hello World!
Resource(.): null
Resource(): jar:file:/testlog4j-1.0.one-jar.jar!/main/testlog4j-1.0.jar!/testlog4j/testlog4j/
URL :jar:file:/testlog4j-1.0.one-jar.jar!/main/testlog4j-1.0.jar!/log4j.xml
log4j:WARN No appenders could be found for logger (testlog4j.testlog4j.App).
log4j:WARN Please initialize the log4j system properly.
Your help is highly appreciated.
The first problem with NoClassDefFoundError was setting correct classpaths, I solved this by adding the maven-dependencies-plugin and included the class prefix attribute in the maven-jar-plugin.
For one-jar plugin; When building the one-jar file, DOMConfigurator.configure() method of log4j was not able to parse the log4j.xml file anymore (as can be seen in the question above). I was able to replace this by log4j.properties file and using the PropertyConfigurator.configure() method. Then the problem would be solved. However, OneJar is causing another problem for me. Since it builds the first executable jar into another jar; I will need to change my code to find the path of the parent executable jar to write log and properties files. For this reason, I changed into the maven-assembly-plugin using its non deprecated single goal. In this case I can also keep the nice log4j.xml file.
Below is the new pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>testlog4j</groupId>
<artifactId>testlog4j</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>testlog4j</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>testlog4j.testlog4j.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>testlog4j.testlog4j.App</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>
<repositories>
</repositories>
</project>
Moreover, I uploaded the testing project into github:
https://github.com/mtleis/simpleLog4jMaven
I Hope someone will find this useful.
[As answer since too long for comment]
Maybe helpful for java.lang.NoClassDefFoundError:
3 ways to solve java.lang.NoClassDefFoundError in Java J2EE
java.lang.NoClassDefFoundError: How to resolve – Part 1.
I'm not too familiar with NetBeans but I can imagine that it works therein because NetBeans accesses your classes from target/classes and log4j from your local Maven repository, not from the created jars.
Have you unzipped the jar files and checked what's in it? Are all files therein as expected and at the right place? /main/testlog4j-1.0.jar!/log4j.xml seems not to be where it is expected.
im trying to build an example code with maven liferay:build-service from an service.xml
There is simple entity company.
After code generating i have uncompilable code. I have tried another versions of maven plugins, but it didnt help.
Thanx
My pom.xml
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.plugins</groupId>
<artifactId>intlib-env</artifactId>
<packaging>war</packaging>
<name>intlib-env Portlet</name>
<version>1.0.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>com.liferay.maven.plugins</groupId>
<artifactId>liferay-maven-plugin</artifactId>
<version>6.1.2</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>build-css</goal>
</goals>
</execution>
</executions>
<configuration>
<autoDeployDir>D:\portal\liferay\deploy</autoDeployDir>
<appServerDeployDir>D:\portal\liferay\tomcat7\webapps</appServerDeployDir>
<appServerLibGlobalDir>D:\portal\liferay\tomcat7\lib\ext</appServerLibGlobalDir>
<appServerPortalDir>D:\portal\liferay\tomcat7\webapps\ROOT</appServerPortalDir>
<liferayVersion>6.1.2</liferayVersion>
<pluginType>portlet</pluginType>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<version>6.1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>util-bridges</artifactId>
<version>6.1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>util-taglib</artifactId>
<version>6.1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>util-java</artifactId>
<version>6.1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>Liferay-v6.x-Runtime-Stub</id>
<properties>
<liferay.version>6.1.2</liferay.version>
<liferay.maven.plugin.version>6.1.30.1</liferay.maven.plugin.version>
<liferay.auto.deploy.dir>D:\portal\liferay\deploy</liferay.auto.deploy.dir>
<liferay.app.server.deploy.dir>D:\portal\liferay\tomcat7\webapps</liferay.app.server.deploy.dir>
<liferay.app.server.lib.global.dir>D:\portal\liferay\tomcat7\lib\ext</liferay.app.server.lib.global.dir>
<liferay.app.server.portal.dir>D:\portal\liferay\tomcat7\webapps\ROOT</liferay.app.server.portal.dir>
</properties>
</profile>
</profiles>
</project>
and here the service.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_0_0.dtd">
<service-builder package-path="cz.sysnet.intlib.eia">
<author>EB</author>
<namespace>EIA</namespace>
<entity name="Company" local-service="true" remote-service="false">
<column name="Id" type="long" primary="true" />
<column name="ICO" type="String" />
<column name="name" type="String" />
<column name="companyId" type="long" />
<column name="groupId" type="long" />
<order by="asc">
<order-column name="name" />
</order>
<finder name="G_N" return-type="Collection">
<finder-column name="groupId" />
<finder-column name="name" />
</finder>
<finder name="GroupId" return-type="Collection">
<finder-column name="groupId" />
</finder>
<finder name="CompanyId" return-type="Collection">
<finder-column name="companyId" />
</finder>
</entity>
</service-builder>
Here are few of the errors after successfully generation of the code.
Description Resource Path Location Type
The method update(Company, boolean) in the type BasePersistence<Company> is not applicable for the arguments (Company) CompanyLocalServiceBaseImpl.java /intlib-env2/src/main/java/cz/sysnet/intlib/eia/service/base line 80 Java Problem
The method update(Company, boolean) in the type BasePersistence<Company> is not applicable for the arguments (Company) CompanyLocalServiceBaseImpl.java /intlib-env2/src/main/java/cz/sysnet/intlib/eia/service/base line 276 Java Problem
The method update(Company, boolean) in the type BasePersistence<Company> is not applicable for the arguments (Company) CompanyUtil.java /intlib-env2/src/main/java/cz/sysnet/intlib/eia/service/persistence line 89 Java Problem
The method update(Company, boolean) in the type BasePersistence<Company> is not applicable for the arguments (Company, ServiceContext) CompanyUtil.java /intlib-env2/src/main/java/cz/sysnet/intlib/eia/service/persistence line 97 Java Problem
The method setModelClass(Class<Company>) is undefined for the type CompanyPersistenceImpl CompanyPersistenceImpl.java /intlib-env2/src/main/java/cz/sysnet/intlib/eia/service/persistence line 169 Java Problem
The method setExpandoBridgeAttributes(ExpandoBridge) of type CompanyModel must override or implement a supertype method CompanyModel.java /intlib-env2/src/main/java/cz/sysnet/intlib/eia/model line 146 Java Problem
The method setExpandoBridgeAttributes(BaseModel<?>) of type CompanyModel must override or implement a supertype method CompanyModel.java /intlib-env2/src/main/java/cz/sysnet/intlib/eia/model line 143 Java Problem
The method countWithDynamicQuery(DynamicQuery) in the type BasePersistence<Company> is not applicable for the arguments (DynamicQuery, Projection) CompanyLocalServiceBaseImpl.java /intlib-env2/src/main/java/cz/sysnet/intlib/eia/service/base line 210 Java Problem
Thanx.
Company is a type that Liferay also has. Most likely ServiceBuilder generates import for Liferay's Company class, clashing with your own. Unless you want to start over, you'd have some tasks to do to get rid of all of your company declarations from the generated content of service builder - hibernate files, spring configuration and others. Search for cz.sysnet.intlib.eia.Company in your project and remove those declarations (and the Company* classes in your project), rename your entity (e.g. to Kompany, choose any other value that you like) and rebuild the services.
ServiceBuilder has a few limitations like these, after all, it's a code generator and rarely used to introduce another entity with an already existing name. You might want to add this limitation to LPS-27710 and watch that issue. It probably doesn't have the highest priority unless there's a lot of activity on there
Thanx for the response,
i had to move from the newest version apache maven 3.2.2 to the 3.1.1 and cleaned the maven files in the project.
Now its working again.
I have just switch over to Intellij IDEA and I am trying to test my JPA entities using a RESOURCE_LOCAL persistence unit. My environment is currently using EclipseLink, MySQL and Maven.
At the moment my test class is performing the following call:
EntityManagerFactory factory = Persistence.createEntityManagerFactory("app-test");
The persistence unit is being detected (if I change the name in the persistence.xml file, I get an error saying the unit cannot be found). However, if I run the test I am getting the following errors in the console:
Exception in thread "main" Local Exception Stack:
Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader#1005354a
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [app-test] failed.
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:115)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at suite.Suite.main(Suite.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [app-test] failed.
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createPredeployFailedPersistenceException(EntityManagerSetupImpl.java:1541)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1532)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.callPredeploy(JPAInitializer.java:98)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:105)
... 8 more
Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [app-test] failed.
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:221)
... 12 more
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.hasEntity(MetadataProject.java:1272)
at org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataAnnotatedElement.isOneToMany(MetadataAnnotatedElement.java:610)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.buildAccessor(ClassAccessor.java:594)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.addAccessorFields(ClassAccessor.java:423)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.addAccessors(ClassAccessor.java:395)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.preProcess(ClassAccessor.java:1178)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.MappedSuperclassAccessor.preProcess(MappedSuperclassAccessor.java:724)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.preProcess(EntityAccessor.java:555)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processStage1(MetadataProject.java:1649)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processORMMetadata(MetadataProcessor.java:531)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:550)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1469)
... 10 more
This is my persistence.xml
<?xml version="1.0" encoding="UTF-8" ?>
<persistence version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="app-test" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/app" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.logging.level" value="FINEST" />
<property name="eclipselink.logging.level.sql" value="FINEST" />
<property name="eclipselink.logging.parameters" value="true" />
</properties>
</persistence-unit>
</persistence>
My pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.app.entities</groupId>
<artifactId>app-entities</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>app-entities</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.24</version>
</dependency>
</dependencies>
</project>
My folder structure (all my entities are in the src/main/java folder):
I removed the project and recreated it from scratch and it is working now.