Adding Classes to Clojure - java

In my clojure project I have a dependency on the javax.jms.MessageListener library. I have this class file in my project in the following directory
My-project
|java-
| |src -
| | |myJavaFile.java
| | |jars -
| | |library1.jar
| | |library2.jar
| | |libarary3.jar
| |javax -
| | |jms -
| | |MessageListener.class
|project.clj
|src -
| |my-program1.clj
| |my-program2.clj
| |my-program3.clj
Then in my project.clj file I have my java-source-paths set to
:java-source-paths ["java/src" "java/src/jars/" "java/javax/jms"]
but when I go to run my project via lein repl, I get compilation errors saying
java.lang.NoClassDefFoundError: javax/jms/MessageListener
Caused by: java.lang.ClassNotFoundException: javax.jms.MessageListener
From what I've read the messagelistener.class and my library jars should be included in my classpath when the project is running but that doesn't seem to be the case.

It is my understanding that the directory structure of java projects has to match the name of the namespaces. For instance package_name.classname has to be in the folder package_name on the classpath https://docs.oracle.com/javase/tutorial/java/package/managingfiles.html
But of course using either Leiningen or Boot you just need to add [javax.jms/jms-api "1.1-rev-1"] to the :dependencies.

Related

How to undo a migration using Flyway?

I am working on a Spring project and I have FlyWay as a dependency to manage my migrations, I made a mistake on the SQL command. When I ran the project I got an error showing a problem with the script, a silly mistake that was easy to fix, I misspelled a column name. However, the undo command from the flyway is not working.
I was trying to undo a migration using FlyWay and I follow the tutorial from FlyWay documentation: link-flyway
However, I got this output:
C:\Users\leonardo.freitas\Documents\workspace\api>C:\Users\leonardo.freitas\Documents\workspace\flyway-9.8.1\flyway undo
A new version of Flyway is available
Upgrade to Flyway 9.8.2: https://rd.gt/2X0gakb
ERROR: The command 'undo' was not recognized. Make sure you have added 'flyway-proprietary' as a dependency.
Caused by: No command extension found to handle command: undo
That's my migration history:
C:\Users\leonardo.freitas\Documents\workspace\api>C:\Users\leonardo.freitas\Documents\workspace\flyway-9.8.1\flyway info
A new version of Flyway is available
Upgrade to Flyway 9.8.2: https://rd.gt/2X0gakb
Flyway Community Edition 9.8.1 by Redgate
See what's new here: https://flywaydb.org/documentation/learnmore/releaseNotes#9.8.1
ERROR: Skipping filesystem location: sql (not found)
Database: jdbc:mysql://localhost:3306/volimed (MySQL 8.0)
Schema version: 5
+-----------+---------+----------------------------------------+------+---------------------+-----------------+----------+
| Category | Version | Description | Type | Installed On | State | Undoable |
C:\Users\leonardo.freitas\Documents\workspace\api>C:\Users\leonardo.freitas\Documents\workspace\flyway-9.8.1\flyway info
A new version of Flyway is available
Upgrade to Flyway 9.8.2: https://rd.gt/2X0gakb
Flyway Community Edition 9.8.1 by Redgate
See what's new here: https://flywaydb.org/documentation/learnmore/releaseNotes#9.8.1
ERROR: Skipping filesystem location: sql (not found)
Database: jdbc:mysql://localhost:3306/volimed (MySQL 8.0)
Schema version: 5
+-----------+---------+----------------------------------------+------+---------------------+-----------------+----------+
| Category | Version | Description | Type | Installed On | State | Undoable |
+-----------+---------+----------------------------------------+------+---------------------+-----------------+----------+
| Versioned | 1 | create-table-medicos | SQL | 2022-11-19 03:12:19 | Future | No |
| Versioned | 2 | alter-table-medicos-add-telefone | SQL | 2022-11-19 13:32:45 | Future | No |
| Versioned | 3 | create-table-pacientes | SQL | 2022-11-19 13:46:17 | Future | No |
| Versioned | 4 | alter-table-medicos-add-column-active | SQL | 2022-11-19 15:28:46 | Future | No |
| Versioned | 5 | alter-table-paciente-add-column-active | SQL | 2022-11-19 15:45:28 | Failed (Future) | No |
+-----------+---------+----------------------------------------+------+---------------------+-----------------+----------+
And I want to redu the last migration.
Undo command is supported in both the Teams and Enterprise edition . Flyway Enterprise is the only version with auto generation of Undo scripts though. Bill, could you point me towards where the information is conflicting?
I find out a way to resolve this problem, I went to the FlyWay table and deleted the last row, when I ran the project the FlyWay applied the migration again.

How to force log4j to be used but not slf4j

EDIT: To clarify the question, I added many explanations.
In my project dependencies, I have both slf4j and log4j. This can't be changed for some technical reason.
>gradlew dependencies
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could
not be reused, use --status for details
> Task :dependencies
.
.
| | | +--- org.springframework.boot:spring-boot-starter-logging:2.5.7
| | | | +--- ch.qos.logback:logback-classic:1.2.7
| | | | | +--- ch.qos.logback:logback-core:1.2.7
| | | | | \--- org.slf4j:slf4j-api:1.7.32
| | | | +--- org.apache.logging.log4j:log4j-to-slf4j:2.14.1
| | | | | +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.32
| | | | | \--- org.apache.logging.log4j:log4j-api:2.14.1 -> 2.17.0
| | | | \--- org.slf4j:jul-to-slf4j:1.7.32
| | | | \--- org.slf4j:slf4j-api:1.7.32
.
.
+--- org.apache.logging.log4j:log4j-core:2.17.0
| \--- org.apache.logging.log4j:log4j-api:2.17.0
+--- org.apache.logging.log4j:log4j-api:2.17.0
BUILD SUCCESSFUL in 16s
1 actionable task: 1 executed
I want to set the log level in the code, and AFAIK that can only be done with log4j. As a result, I simply look for a way to make this code line (LogManager is part of log4j) returns log4j implementation and not slf4j implementation:
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
.
.
private final Logger logger = LogManager.getLogger(getClass());
Sadly, the logger's class returns is org.apache.logging.slf4j.SLF4JLogger:
System.out.println("logger class is: [" + logger.getClass() + "]");
output:
logger class is: [class org.apache.logging.slf4j.SLF4JLogger]
Even though it sounds easy, I haven't been able to do it or find an example online. What can be done?
Log4j 2.x Core and the Log4j to SLF4J Adapter are two implementations of the Log4j 2.x API. If they are both present on the classpath log4j-to-slf4j is used. That is what happens in your case: messages logged using the Log4j 2.x API are sent to SLF4J, which sends them to Logback.
That is the standard logging configuration brought by the spring-boot-starter-logging. If you want to use Log4j 2 as backend instead you need to exclude that artifact and add spring-boot-starter-log4j2.
Anyway, since you are using Spring Boot, you have two ways to set the level of a logger:
Using Spring Boot's LoggingSystem abstraction (works for all available logging systems):
final LoggingSystem loggingSystem = LoggingSystem.get(getClass().getClassLoader());
loggingSystem.setLogLevel("loggerName", LogLevel.DEBUG);
Using the underlying logging system. In your case it is Logback, so you should use:
final Logger logger = LoggerFactory.getLogger("loggerName");
if (logger instanceof ch.qos.logback.classic.Logger) {
((ch.qos.logback.classic.Logger) logger).setLevel(Level.DEBUG);
}
Remark: due to recent vulnerabilities in both Log4j and Logback, you should bump your version of Spring Boot to 2.5.8 (or 2.6.2).
Whats the full class path of LogManager? It has to be imported, there you should see the full class.
My guess is that you need to change the Import to import some log4j LogManager, not the slf4j one.

Fitnesse: Slim server fails to start; using Eclipse

I'm trying to get a very basic Fitnesse test to run; using Fitnesse / Slim; Java in Eclipse.
Test runs, or at least starts, but doesn't finish; get this error:
Unable to start test system 'slim': fitnesse.slim.SlimError: Error SLiM server died before a connection could be established. JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [debugInit.c:750]
Fitnesse test is:
!define TEST_SYSTEM {slim}
!path: C:\Users\<my folder>\EclipseWorkspace\CalculatorProject
| import | packageCalculator |
| TestCalculator |
| operand | result? |
| 4 | 8 |
| 2 | 4 |
| 7 | 14 |
| 2 | 4 |
This is a similar issue: Fitnesse: SLiM server died before a connection could be established; suggests this might be a regression bug; but I tried earlier versions of fitnesse, which made no difference
And it's not this one either: https://github.com/unclebob/fitnesse/issues/726; there is no space in the classpath
Help!!!

Maven parent hierarchy + dependencyManagement not transitive?

I thought dependencyManagement from parents were transitive aren't they?
Never see that explicitely in the doc, but it seemed obvious to me...
Here's what i have:
+-----------------------+
| Parent 1 |
|-----------------------|
| dependencyManagement: |
| lib1: 1.0.0 |
+-----------------------+
^
|
|
+-----------+-----------+
| Parent 2 |
|-----------------------|
| dependencyManagement: |
| lib2: 1.0.0 |
+-----------------------+
^
|
+-----------+-----------+
| Project A |
|-----------------------|
| dependencies: |
| lib1 |
| lib2 |
+-----------------------+
When i try to mvn install Project A, i get:
[ERROR] 'dependencies.dependency.version' for lib1-digester:jar is missing. # line XX, column YY
I also tried to add an entry of Parent 1 in the dependencyManagement of Parent 2 with the import scope, with no success..
How can my Project A have versions managed by all it's parent hierarchy?
It seems you are correct after reading the Maven Docs.
In general, all dependencies of those projects are used in your project, as are any that the project inherits from its parents, or from its dependencies, and so on.
Try to update to the latest version of Maven 3. IIRC, there were a couple of bugs in the inheritance of dependencyManagement elements.
A made a small example with other empty projects, and everything went fine...
Finally, there was something strange, here's what happened.
I was actually more like that:
+-----------------------+
| Parent 1 |
|-----------------------|
| dependencyManagement: |<----------------------+
| lib1: 1.0.0 | |
+-----------------------+ |
^ |
| +-------------+------------+
| | Project B |
+-----------+-----------+ |--------------------------|
| Parent 2 | | dependencies: |
|-----------------------| | somethingWrong: 1.0.0 |
| dependencyManagement: | +--------------------------+
| lib2: 1.0.0 |
+-----------------------+
^
|
+-----------+-----------+
| Project A |
|-----------------------|
| dependencies: |
| lib1 |
| lib2 |
+-----------------------+
There was an error in Project B's pom.xml
It shouldn't have any impact on my problem, but correcting that unrelated pom solved my problem...
Sorry for the wasted time

Organizing Git submodules to share platform-generic src and tests between platform-specific Eclipse projects in separate repos

I have a cross-mobile-platform project that I am trying have platform-specific Android and BlackBerry Eclipse projects in separate repos use a Git submodule that contains J2ME platform-generic src and test code.
Here is the intended layout:
team-lib-j2me
| - src (platform generic source code)
| | - ...
| - test
| - src (platform generic source code)
| - ...
team-lib-android
| - team-lib-j2me (git submodule)
| - lib (Eclipse Android project)
| | - AndroidManifest.xml
| | - src (platform specific)
| | - ...
| - test (Eclipse Android Project)
| - AndroidManifest.xml
| - src (platform specific)
| - ...
team-lib-blackberry
| - team-lib-j2me (git submodule)
| - lib (Eclipse BB Project)
| | - BlackBerry_App_Descriptor.xml
| | - src (platform specific)
| | - ...
| - test (Eclipse BB Project)
| - BlackBerry_App_Descriptor.xml
| - src (platform specific)
| - ...
I cannot seem to find a clean and simple way to:
Get either of the Eclipse "lib" projects to source link to the relative path "../team-lib-j2me/src"
Get either of the Eclipse "test" projects to source link to the relative path "../team-lib-j2me/test/src"
Any suggestions on how to do this?
Thanks!
Got it: Is there a way to setup Linked Resources relative to the .project file?
I just created a new path variable "TEAM_LIB_J2ME"="${PROJECT_LOC}..\team-lib-j2me", and then created "Link Source"s to:
"team-lib-j2me-src" = TEAM_LIB_J2ME\src
"team-lib-j2me-test-src" = TEAM_LIB_J2ME\test\src

Categories