Build failed by schemaExport, HelloWorld program with Hibernate - java

I am new in Hibernate and try to write my first "helloworld" program. I am using the step in the book "Java Persistence with Hibernate". as I run the build.xml with ant I become the following error. The error came as a schema have to be generate to on the database using hbm2ddl
BUILD FAILED
C:\mypath\build.xml:60: java.lang.NoSuchMethodError: >org/slf4j/impl/StaticLoggerBinder.getSingleton()Lorg/slf4/im/StaticLoggerBinder;
"schemaexport target von build.xml(so sieht die stelle wo der fehler sein sollte aus)"
Translation: "schemaexport target of build.xml(the have to be here, but i cannot found it!)"
<target name="schemaexport" depends="compile, copymetafiles"
description="Exports a generated schema to DB and file">
<hibernatetool destdir="${basedir}">
<classpath path="${build.dir}"/>
<configuration
configurationfile="${build.dir}/hibernate.cfg.xml"/>
<hbm2ddl
drop="true"
create="true"
export="true"
outputfilename="helloworld-ddl.sql"
delimiter=";"
format="true"/>
</hibernatetool>
</target>
I have the following *.jar file in my workdir/lib directory:
antlr.jar
asm.jar
asm-attrs.jars
c3p0.jar
cglib.jar
commons-collections.jar
jcl-over-slf4j.jar
dom4j.jar
hibernate3.jar
hsqldb.jar
jta.jar
thank for reply! I very appreciate.
I am using the latest version of slf4j(slf4j-api-1.6.1). This version come with the hibernate I downloaded, hibernate-distribution-3.6.5.Final, and was located in the folder lib/required of this hibernate version. I also have the following library(jar file):
all ends with .jar
dom4j-1.6.1
hibernate3
hibernate-jpa-2.0-api-1.0.0.Final
hibernate-tools
hsqldb
javassist-3.12.0.GA
jcl-over-slf4j-1.5.4(I also try commons-logging-1.1.1 but nothing change)
jta-1.1
log4j-1.2.16
slf4j-api-1.6.1
Any other idea?
thanks.

This is most likely a version problem: you're using a wrong version of the slf4j library. One of the libraries you're using tries to lookup a certain method, but that method doesn't exist in the version of the library you are using.
Check which version exactly you need by looking in the documentation of the version of Hibernate or other libraries you are using (or try the latest version from slf4j.org).

Related

What causes FileNotFoundException: ...pdq.jar with db2jcc4?

When adding db2jcc4.jar to the system class path, Tomcat 8.0 raises a FileNotFoundException on a jar file that has no apparent reference to my project, pdq.jar.
I couldn't find it anywhere on my system or where it might come from, except through a search which turned up the answer below.
In this case, I have my CATALINA_HOME pointed to C:\tomcat8.0\apache-tomcat-8.0.41 and my project has the following maven dependency defined:
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc4</artifactId>
<version>10.1</version>
<scope>system</scope>
<systemPath>${env.CATALINA_HOME}/lib/db2jcc4-10.1.jar</systemPath>
</dependency>
This might happen in the newer versions of Db2 jcc driver:
Beginning with version 4.16 of the IBM Data Server Driver for JDBC and SQLJ, which is shipped with Db2 10.5 on Linux, UNIX, or Windows operating systems, the MANIFEST.MF file for db2jcc4.jar contains a reference to pdq.jar.
IBM Support offers 2 options:
Resolving the problem
To prevent the java.io.FileNotFoundException, you can take one of the following actions:
Edit the MANIFEST.MF file, and remove this line: Class-Path: pdq.jar
Edit the context.xml file for Apache Tomcat, and add an entry like the following one to set the value of scanClassPath to false.
Personally, I prefer the second approach, which can be done as following:
<Context>
...
<JarScanner scanClassPath="false" />
...
</Context>
According to this KB article on IBM, the problem comes from the MANIFEST, which lists pdq.jar, a third party optimization tool.
I had both db2jcc4.jar and db2jcc4.10.1.jar in my lib folder.
While the article suggests editing the MANIFEST file in db2jcc4.jar, version 10.1 does not include this entry at all.
Removing db2jcc4.jar solved my problem, so a solution in this case could also be to upgrade db2jcc4 from an older version to version 10.1, or if that is not possible, edit the manifest file as instructed.
You Just need to update jar db2jcc4.jar to be db2jcc4-10.1.jar
You can find maven dependency / Jar on that link
Kayvan Tehrani's answer explains what's going on here and that this error can be ignored.
Another alternative to clean up the logs is to create a dummy pdq.jar and place it into tomcat's lib folder.
jar -cf pdq.jar ""
(The ": no such file or directory" message from this command is expected.)

Getting 'Missing Required Attribute' JiBX error after migrating to WebLogic 12

Good morning,
I've been working on a project where I'm supposed to:
upgrade the application from JRockit 1.6 to Java 7
upgrade the application to run in a WebLogic 10.3.5 environment to run in a WebLogic 12 environment
I'm sure this doesn't help but I'm new to the Java/Spring/WebLogic world.
I was able to upgrade from JRockit 1.6 to Java 7 but when it comes to the WebLogic part, I've been having issues starting the application.
Every time I do, I get the following error
org.jibx.runtime.JiBXException: Missing required attribute "a" (line 1, col 71)
at org.jibx.runtime.impl.UnmarshallingContext.attributeText(UnmarshallingContext.java:975)
at com.mydomain.JiBX_rule_def_bindingMungeAdapter.JiBX_rule_def_binding_unmarshalAttr_1_0()
at com.mydomain.JiBX_rule_def_bindingMutableRuleDefinition_access.unmarshal()
at org.jibx.runtime.impl.UnmarshallingContext.unmarshalElement(UnmarshallingContext.java:2757)
at org.jibx.runtime.impl.UnmarshallingContext.unmarshalDocument(UnmarshallingContext.java:2900)
and have been trying to debug it for a while now. What's really weird is that when I take out the code from a Spring/WebLogic environment and execute it, it works fine (ie, unmarshalls the data).
When it was in the WebLogic 10.3.5 environment w/ JRockit 1.6 and JiBX 1.2.1 jars, I had zero issues.
Here's what I've tried
upgraded JiBX jars from 1.2.1 to 1.2.5
upgraded xpp3 jars to 1.1.3.4.O
upgraded Spring jars from 2.5.5 to 3.2.11
tried including a weblogic.xml file (didn't have one before) and try to used the
<preferred-web-inf>true</preferred-web-inf>
but no luck
tried including a weblogic-application.xml file and an APP-INF folder (didn't have one before) and tried to used the JiBX as my preffered class for unmarshalling
Here is some more information about the environment I'm working in
Non Maven Environment (had to upgrade .jars manually)
Used Java 1.7.0.45 and .71
WebLogic 1.2.1.2
Spring 3.2.11
JiBX 1.2.5
using MyEclipse Version: 2014 Build id: 12.0.0-20131202
no xsd file just a .xml binding file
<binding>
<mapping name="rule"
class="com.mydomain.MutableRuleDefinition">
<value name="a" field="a" style="attribute" />
<value name="b" field="b" style="attribute" />
<collection field="ruleElements">
<structure name="ruleElement"
type="com.mydomain.MutableRuleElement">
<value name="c" field="c" style="attribute" />
<value name="d" field="d" style="attribute" />
<collection field="values" item-type="java.lang.String"
usage="optional">
<value name="value" />
</collection>
</structure>
</collection>
</mapping>
</binding>
Here is the unmarshalling code:
private MutableRuleDefinition unmarshalXMLRuleDef(String _xmlRuleDef) {
MutableRuleDefinition mruleDef = null;
try {
IBindingFactory bfact = BindingDirectory
.getFactory(MutableRuleDefinition.class);
IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
mruleDef = (MutableRuleDefinition) uctx.unmarshalDocument(
new ByteArrayInputStream(_xmlRuleDef.getBytes()), null);
} catch (JiBXException e) {
logger.error("Could not un-marshalling the XML rule definition:["
+ _xmlRuleDef + "]", e);
}
Apparently this was an issue back in JiBX 1.2.1 but was fixed in 1.2.2 :
https://www.mail-archive.com/jibx-users#lists.sourceforge.net/msg04200.html
Any help appreciated. Please let me know if you need more info...
Update #1
I have tried
<value name="a" field="a" style="attribute" usage=optional />
on all the attribute flags and the unmarshalling will work, however, these fields aren't optional so I can't use that as a fix.
Update #2
fwiw, here is an example that would come into be unmarshalled
<rule a="dataForA" b="dataForB">
<ruleElement c="dataForC1" d="dataForD1" />
<ruleElement c="dataForC2" d="dataForD2" />
<ruleElement c="dataForC3" d="dataForD3" />
<ruleElement c="dataForC4" d="dataForD3" />
</rule>
R Hanna,
I would suggest looking at the JiBX dependencies and making sure all of the Jars are the exact same version as the ones used by JiBX. We use some eclipse libraries that often conflict with web server jars.
Also, remember that JiBX is open source. You may want to step through the code and see what is causing JiBX to fail.
One more thing. I can't see your schema definition, but it is strange that the error seems to say that you are missing an attriburte. Are you sure the 'source' attribute is not required.
Good Luck!
Don Corley
JiBX contributor
R Hanna,
I got this resolved for me after using 1.2.5 version of jibx however i made sure all the related jars also updated to 1.2.5 and made sure there are no stale class files present in my war which were created by the previous jars that did the trick for me hope its helps you .

ant propertyfile task update property removes all comments from the property file

I am running ant version 1.6.5 on CentOS 5.5. I used ant propertyfile task (an optional ant task) to update some properties in a property file before loading the property file. The property file task seems to be removing all the existing comments from the file just leaving it with the property key-value pairs.
Here is my code snippet from the build.xml file:
<target name="version">
<propertyfile file="${root.dir}/build/cbo_version.properties" >
<entry key="major_number" value="${major_number}"/>
<entry key="minor_number" value="${minor_number}"/>
<entry key="maintenance_number" value="${maintenance_number}"/>
<entry key="build_number" value="${build_number}"/>
</propertyfile>
</target>
Here is a snippet from my property file:
#
# This file was designed to contain basic information about a build/release such
# as its version, code label, etc. for the purpose of traceability.
#
major_number=1
minor_number=0
maintenance_number=0
build_number=18
Once I build my application, all the lines in the property file prefixed with "#" are deleted. I have tried the same code on mac os x 10.8.4 and with ant 1.8.2 and the code runs perfectly fine. I would like to have the comments left completely untouched by the propertyfile task. Please help
[Edited] Ant docu says about PropertyFile task:
Since Ant 1.8.0 comments and layout of the original properties file are preserved.
http://ant.apache.org/manual/Tasks/propertyfile.html

Ant target failing: Antlib or Ivy issue? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Ivy fails to resolve a dependancy, unable to find cause
I'm trying to run the following build task (initIvy):
<?xml version="1.0" encoding="UTF-8"?>
<project name="myproject-build" default="package" basedir=".." xmlns:ivy="antlib:org.apache.ivy.ant">
<property file="build/build.properties"/>
<property environment="env"/>
<!-- Ant library path, including all of its plugins. -->
<path id="ant.lib.path">
<fileset dir="${env.ANT_HOME}/lib" includes="*.jar"/>
</path>
<!-- CONFIGURE IVY -->
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" classpathref="ant.lib.path"/>
<!-- Use Ivy tasks to resolve dependencies into the local Ivy cache. -->
<target name="initIvy">
<!-- Initialize Ivy and connect to host repository. -->
<echo message="Initializing Apache Ivy and connecting to the host repository."/>
<ivy:settings url="${ivy.std.repo.settings.url}" realm="${ivy.std.repo.realm}" username="${ivy.std.repo.username}" passwd="${ivy.std.repo.password}"/>
<!-- Clear/flush the Ivy cache. -->
<echo message="Cleaning the local Ivy cache for the current build."/>
<ivy:cleancache/>
</target>
<!-- Rest of buildfile omitted for brevity. -->
</project>
When I run ant -buildfile build.xml initIvy I get the following output:
Buildfile: /<path-to-my-project>/build/build.xml
[taskdef] Could not load definitions from resource org/apache/ivy/ant/antlib.xml. It could not be found.
initIvy:
[echo] Initializing Apache Ivy and connecting to the host repository.
BUILD FAILED
/<path-to-my-project>/build/build.xml:81: Problem: failed to create task or type antlib:org.apache.ivy.ant:settings
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet
This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
-/<path-to-my-ANT_HOME>/lib
-/home/myUser/.ant/lib
-a directory added on the command line with the -lib argument
When I go to ${ANT_HOME}/lib, I don't see any JARs labeled "antlib*.jar".
So I'm guessing I downloaded a version of Ant that did not include Antlib, and now that I'm using Ivy (which uses Antlib), the build is choking?
If this is an Antlib issue, then I believe I want one of the distros available here. If so, can someone confirm which one I should use (that only contains Antlib and not anything else), and confirm the process for installing it; i.e., is it just as simple as putting the correct JAR in ${ANT_HOME}/lib? Etc.
If this is an Ivy issue, then can someone point me in the right direction as to what could be going on?
And if this is neither Antlib nor Ivy, ditto for the question directly above. Thanks in advance!
I think you might be missing Apache IVY library. Download it from here - apache ivy Copy the jar in your ant lib directory.
For example (change version numbers as appropriate):
Download and install Ant (e.g., C:\Apps\Tools\apache-ant-1.9.7).
Download and extract Ivy (e.g., C:\Users\UserName\Downloads\apache-ivy-2.4.0)
Copy C:\Users\UserName\Downloads\apache-ivy-2.4.0\ivy-2.4.0.jar into C:\Apps\Tools\apache-ant-1.9.7\lib.
Ant is configured to use Ivy.

using IVY dependencies manager programmatically

i need help using IVY as dependencies manager
my application need to load plug-ins at RUN-TIME
means while the core application is running ,user can request for a new plug-in
and install them ,
i wish to manage all installed plug-ins using the core application DB.
i want to get a pom from my plug-ins server (or some other descriptor),
and ask IVY to tell me what are the dependencies OR let IVY
install the plug-in and dependencies ,
based on the current state of my application.
( what do i have right now ,
1.jar's used by core application
2.jar's used by current installed plug-ins)
i wish for each plug-in to have independent directory
under some folder where my application is located (not a shared one)
the thing is i don't know where to start
i notice that there is no programming API for that
i located one link over the network of someone who try something similar
but look likes the code is not completed , or some variable are missing
and i dont know how to complete the rest cause lake of programming documentation
http://www.mail-archive.com/ivy-user#ant.apache.org/msg03228.html
(where the variable "art" came for.....)
can you help me please ...
Thank you all
UPDATE
ok this what i am trying now .
i am getting some a error plus i dont know how to define my archiva server
IvySettings settings = new IvySettings();
settings.setDefaultIvyUserDir(new File("D:/programming/eclipse_projects/ivyTest/repo/"));
settings.setDefaultCache(new File("D:/programming/eclipse_projects/ivyTest/repo/cache/"));
settings.setDefaultCacheArtifactPattern("[module]/[revision]/[module]-[revision](-[classifier]");
Ivy ivy = Ivy.newInstance(settings);
ivy.getLoggerEngine().pushLogger(new DefaultMessageLogger(Message.MSG_VERBOSE));
ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(new IvySettings(), new File("src/movies.pom").toURL(), true);
RetrieveOptions retriveOptions = new RetrieveOptions();
retriveOptions.setUseOrigin(true);
retriveOptions.setConfs(md.getConfigurationsNames());
ivy.retrieve(md.getModuleRevisionId(), "lib/[conf]/[artifact].[ext]", etriveOptions);
this is the error i get
:: loading settings :: url = jar:file:/D:/programming/eclipse_projects/ivyTest/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
:: retrieving :: org.jtpc#movies
checkUpToDate=true
confs: [default, master, compile, provided, runtime, test, system, sources, javadoc, optional]
java.lang.RuntimeException: problem during retrieve of org.jtpc#movies: java.lang.IllegalStateException: Report file 'D:\programming\eclipse_projects\ivyTest\repo\cache\org.jtpc-movies-default.xml' does not exist.
at org.apache.ivy.core.retrieve.RetrieveEngine.retrieve(RetrieveEngine.java:206)
at org.apache.ivy.Ivy.retrieve(Ivy.java:540)
at Test.main(Test.java:52)
Caused by: java.lang.IllegalStateException: Report file 'D:\programming\eclipse_projects\ivyTest\repo\cache\org.jtpc-movies-default.xml' does not exist.
at org.apache.ivy.plugins.report.XmlReportParser.parse(XmlReportParser.java:294)
at org.apache.ivy.core.retrieve.RetrieveEngine.determineArtifactsToCopy(RetrieveEngine.java:288)
at org.apache.ivy.core.retrieve.RetrieveEngine.retrieve(RetrieveEngine.java:104)
... 2 more
Ivy can be used as a standalone java program:
java -jar ivy.jar -retrieve "lib/[conf]/[artifact].[ext]"
The retrieve pattern can be then used to determine where files are installed, based on the ivy configuration settings
$ find lib -type f
lib/core/commons-lang.jar
lib/plugin1/commons-logging.jar
lib/plugin1/commons-codec.jar
lib/plugin2/commons-logging.jar
lib/plugin2/commons-cli.jar
lib/plugin3/commons-logging.jar
Configurations are used as a collective label or grouping of dependencies. They are similar to Maven scopes but much more flexible:
<ivy-module version="2.0">
<info organisation="com.myspotontheweb" module="demo"/>
<configurations>
<conf name="core" description="Core application dependencies"/>
<conf name="plugin1" description="Plugin 1 dependencies"/>
<conf name="plugin2" description="Plugin 2 dependencies"/>
<conf name="plugin3" description="Plugin 3 dependencies"/>
</configurations>
<dependencies>
<dependency org="commons-lang" name="commons-lang" rev="2.5" conf="core->default"/>
<dependency org="commons-codec" name="commons-codec" rev="1.4" conf="plugin1->default"/>
<dependency org="commons-cli" name="commons-cli" rev="1.2" conf="plugin2->default"/>
<dependency org="commons-logging" name="commons-logging" rev="1.1.1" conf="plugin1,plugin2,plugin3->default"/>
</dependencies>
</ivy-module>
If you only want to download and install one set of jars, into a specified directory you can use the confs parameter:
java -jar ivy.jar -retrieve "plugin1/[artifact].[ext]" -confs plugin1
Finally, if you still want to use a programming API, you could invoke the run method called by the main class
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/Main.java?view=markup
Update 1
Groovy has built in support for invoking ivy tasks
import groovy.xml.NamespaceBuilder
def ant = new AntBuilder()
def ivy = NamespaceBuilder.newInstance(ant, 'antlib:org.apache.ivy.ant')
ivy.settings(file:"ivysettings.xml")
ivy.retrieve(pattern:"lib/[conf]/[artifact].[ext]")
ivy.report(toDir:'reports', graph:false)
Update 2
To set the location of your local Maven repository you need to use an ivysettings.xml file.
<ivysettings>
<settings defaultResolver='nexus' />
<resolvers>
<ibiblio name='nexus' root='http://myhost.mydomanin.com:8081/nexus' m2compatible='true' />
</resolvers>
</ivysettings>
Update 3
Just found an article that details how to invoke Ivy from Java

Categories